「とりあえず」4月29日時点で作成済の制御プログラムです。
まぁ、たいしたことはやっていません。下記とは別に下記を呼び出す側のプログラムもあります。
PSoc用のコンパイラを使用しています。
LCDからの読み込みに対応しないで、CPU側にテキストとグラフィックのバッファを持たせておき、そことの演算結果をLCDに流すようにしています。
#define Display_Clear 0x01
#define Return_Home 0x02
#define Entry_Mode_Set 0x04
#define Address_Inc_Mode 0x02
#define Display_Control 0x08
#define Display_On 0x04
#define Cursor_On 0x02
#define Char_Blink_On 0x01
#define Cursor_Display_Control 0x10
#define Function_Set 0x30 // 8bit I/F mode Basic Function
#define Extended_Instruction 0x04
#define Set_CGRAM_Address 0x40
#define Set_DDRAM_Address 0x80
#define Extended_Function_Set 0x34
#define Graphic_Display_On 0x02
#define Graphic_Display_Off 0x00
#define Stand_By 0x01
#define Scroll_or_RAM_Addres_Select 0x02
#define Set_Scroll_Address 0x40
#define Reverse 0x04
#define Set_Graphic_Display_RAM_ADdress 0x80
char GL0[256],GL1[256],GL2[256],GL3[256];
char DD[64];
unsigned char _posX = 0; // current char X pos for Charctor
unsigned char _posY = 0; // current char Y pos
unsigned char _gposX = 0; // current char X pos for Graphic
unsigned char _gposY = 0; // current char Y pos
unsigned char _gareaY = 0; // current char Y area
void CmdWrt(unsigned char X);
void DataWrt(unsigned char X);
void GLCD_Init(void);
void GLCD_Clear(void);
void GLCD_Cursor_Move_XY(unsigned char X,unsigned char Y);
void GLCD_PrString(unsigned char* sRamString);
void GLCD_PrCString(const unsigned char* sRomString);
void GLCD_PrIntWithAlign(int nData,int nLen);
void GLCD_Calc_XY_Address(unsigned char X,unsigned char Y);
void Sample_Display(void);
#ifndef wait
void wait(LONG l){while(l--);}
#endif
void CmdWrt(unsigned char X)
{
RS_Off();
RW_Off();
E_On();
PRT2DR = X;
wait(2);
E_Off();
}
void DataWrt(unsigned char X)
{
RS_On();
RW_Off();
E_On();
PRT2DR = X;
wait(2);
E_Off();
}
void GLCD_Clear(void)
{
int i,j;
CmdWrt(Display_Clear);
wait(100);
GLCD_Cursor_Move_XY(0,0);
GLCD_PrCString(" ");
GLCD_Cursor_Move_XY(0,1);
GLCD_PrCString(" ");
GLCD_Cursor_Move_XY(0,2);
GLCD_PrCString(" ");
GLCD_Cursor_Move_XY(0,3);
GLCD_PrCString(" ");
for(i=0;i<32;i++){
CmdWrt(Function_Set + Extended_Instruction);
wait(10);
CmdWrt(Extended_Function_Set + Graphic_Display_On);
wait(10);
CmdWrt(Set_Graphic_Display_RAM_ADdress + i);
CmdWrt(Set_Graphic_Display_RAM_ADdress + 0);
wait(10);
CmdWrt(Function_Set);
for(j=0;j<32;j++){
DataWrt(0x00);
};
};
for(i=0;i<256;i++){
GL0[i] = 0;
GL1[i] = 0;
GL2[i] = 0;
GL3[i] = 0;
};
}
void GLCD_Init(void)
{
unsigned char i,j;
wait(1000);
RS_Start();
RW_Start();
E_Start();
PSB_Start();
PSB_On();
wait(100000);
for(i=0;i<64;i++){DD[i]=0x20;};
CmdWrt(Function_Set);
wait(100);
CmdWrt(Function_Set);
wait(100);
CmdWrt(Display_Control + Display_On);
wait(100);
CmdWrt(Entry_Mode_Set + Address_Inc_Mode);
wait(100);
GLCD_Clear();
}
void GLCD_Cursor_Move_XY(unsigned char X,unsigned char Y)
{
_posX = X;
_posY = Y;
switch (_posY){
case 0x00 : CmdWrt(Set_DDRAM_Address + 0x00 + (_posX >> 1));break;
case 0x01 : CmdWrt(Set_DDRAM_Address + 0x10 + (_posX >> 1));break;
case 0x02 : CmdWrt(Set_DDRAM_Address + 0x08 + (_posX >> 1));break;
case 0x03 : CmdWrt(Set_DDRAM_Address + 0x18 + (_posX >> 1));break;
};
wait(100);
}
void GLCD_Write_DataBytes(unsigned char* S,int pLen)
{
int i;
if ((_posX & 0x01) == 1){
DataWrt(DD[(_posY<<4)+_posX]);
_posX++;
};
for(i=0;i
if (_posX<16){
DataWrt(S[i]);
DD[(_posY<<4)+_posX] = S[i];
_posX++;
};
};
if ((_posX & 0x01) == 0){
DataWrt(DD[(_posY<<4)+_posX + 1]);
_posX++;
};
}
void GLCD_Write_DataCBytes(unsigned const char* S,int pLen)
{
int i;
if ((_posX & 0x01) == 1){
DataWrt(DD[(_posY<<4)+_posX]);
_posX++;
};
for(i=0;i
if (_posX<16){
DataWrt(S[i]);
DD[(_posY<<4)+_posX] = S[i];
_posX++;
};
};
if ((_posX & 0x01) == 0){
DataWrt(DD[(_posY<<4)+_posX + 1]);
_posX++;
};
}
void GLCD_PrString(unsigned char* sRamString)
{
GLCD_Write_DataBytes(sRamString,strlen(sRamString));
}
void GLCD_PrCString(const unsigned char* sRomString)
{
GLCD_Write_DataCBytes((const unsigned char*)sRomString,cstrlen(sRomString));
}
void GLCD_PrIntWithAlign(int nData,int nLen)
{
int nDataLen;
char pBuff[6];
itoa(pBuff,nData,10);
nDataLen = strlen(pBuff);
for(; nDataLen < nLen; nDataLen++)
GLCD_PrCString(" ");
GLCD_PrString(pBuff);
}
void GLCD_Calc_XY_Address(unsigned char X,unsigned char Y)
{
_gposX = X >> 4;
_gposY = Y & 0x1f;
CmdWrt(Function_Set + Extended_Instruction);
wait(5);
CmdWrt(Extended_Function_Set + Graphic_Display_On);
wait(5);
if (Y < 32){
CmdWrt(Set_Graphic_Display_RAM_ADdress + _gposY);
CmdWrt(Set_Graphic_Display_RAM_ADdress + _gposX);
wait(5);
}else if (Y < 64){
CmdWrt(Set_Graphic_Display_RAM_ADdress + _gposY);
CmdWrt(Set_Graphic_Display_RAM_ADdress + _gposX + 8);
wait(5);
};
CmdWrt(Function_Set);
wait(5);
}
void GLCD_DotON_XY(unsigned char X,unsigned char Y)
{
unsigned char B1,B2;
int ADR;
GLCD_Calc_XY_Address(X,Y);
ADR = ((Y & 0x0f)<<4) + (_gposX<<1);
if (Y < 16){
B1 = GL0[ADR];
B2 = GL0[ADR+1];
}else if (Y < 32){
B1 = GL1[ADR];
B2 = GL1[ADR+1];
}else if (Y < 48){
B1 = GL2[ADR];
B2 = GL2[ADR+1];
}else {
B1 = GL3[ADR];
B2 = GL3[ADR+1];
};
switch (X & 0x0f){
case 15: B2 = B2 | 0x01;break;
case 14: B2 = B2 | 0x02;break;
case 13: B2 = B2 | 0x04;break;
case 12: B2 = B2 | 0x08;break;
case 11: B2 = B2 | 0x10;break;
case 10: B2 = B2 | 0x20;break;
case 9: B2 = B2 | 0x40;break;
case 8: B2 = B2 | 0x80;break;
case 7: B1 = B1 | 0x01;break;
case 6: B1 = B1 | 0x02;break;
case 5: B1 = B1 | 0x04;break;
case 4: B1 = B1 | 0x08;break;
case 3: B1 = B1 | 0x10;break;
case 2: B1 = B1 | 0x20;break;
case 1: B1 = B1 | 0x40;break;
case 0: B1 = B1 | 0x80;break;
};
if (Y < 16){
GL0[ADR] = B1;
GL0[ADR+1] = B2;
}else if (Y < 32){
GL1[ADR] = B1;
GL1[ADR+1] = B2;
}else if (Y < 48){
GL2[ADR] = B1;
GL2[ADR+1] = B2;
}else {
GL3[ADR] = B1;
GL3[ADR+1] = B2;
};
DataWrt(B1);
DataWrt(B2);
}
void GLCD_TEST(void)
{
unsigned char i,j;
/* GLCD_Cursor_Move_XY(0,0);
GLCD_PrCString("AABBCCDDEEFFGGHHIIJJKKLL");
GLCD_Cursor_Move_XY(1,1);
GLCD_PrCString("0123456789");
GLCD_Cursor_Move_XY(1,0);
GLCD_PrCString("m");
GLCD_Cursor_Move_XY(5,0);
GLCD_PrCString("nn");
GLCD_Cursor_Move_XY(9,0);
GLCD_PrCString("ooo");*/
/* for(i=0;i<64;i++){
GLCD_Calc_XY_Address(i+64,i);
// CmdWrt(Function_Set);
// wait(100);
DataWrt(0xff);
DataWrt(i);
};
GLCD_Calc_XY_Address(0,16);
CmdWrt(Function_Set);
DataWrt(0xaa);
DataWrt(0xaa);
GLCD_Calc_XY_Address(0,32);
CmdWrt(Function_Set);
wait(100);
DataWrt(0xCC);
DataWrt(0xCC);
GLCD_Calc_XY_Address(0,48);
CmdWrt(Function_Set);
wait(100);
DataWrt(0x33);
DataWrt(0x33);
*/
for(i=0;i<64;i++){
GLCD_DotON_XY(i,i);
GLCD_DotON_XY(i+4,i);
GLCD_DotON_XY(i+64,i);
GLCD_DotON_XY(i+62,i);
GLCD_DotON_XY(64-i,i);
};
}
void Sample_Display(void)
{
unsigned char i,j;
//1行目に16文字
CmdWrt(Set_DDRAM_Address + 0);
wait(10);
for(i=0x30;i<0x40;i++){
DataWrt(i);
};
//2行目に16文字
CmdWrt(Set_DDRAM_Address + 0x10);
wait(10);
for(i=0x40;i<0x50;i++){
DataWrt(i);
};
//上側2行をクリア
for(i=0;i<32;i++){
CmdWrt(Function_Set + Extended_Instruction);
wait(200);
CmdWrt(Extended_Function_Set + Graphic_Display_On);
wait(200);
CmdWrt(Set_Graphic_Display_RAM_ADdress + i);
wait(100);
CmdWrt(Set_Graphic_Display_RAM_ADdress + 0);
wait(200);
CmdWrt(Function_Set);
for(j=0;j<16;j++){
DataWrt(0x00);
};
};
//下側2行に0x00..0x0fを繰り返す
for(i=0;i<32;i++){
CmdWrt(Function_Set + Extended_Instruction);
wait(200);
CmdWrt(Extended_Function_Set + Graphic_Display_On);
wait(200);
CmdWrt(Set_Graphic_Display_RAM_ADdress + i);
wait(100);
CmdWrt(Set_Graphic_Display_RAM_ADdress + 0x08);
wait(200);
CmdWrt(Function_Set);
for(j=0;j<16;j++){
DataWrt(i);
};
};
}