//程序见下面 //参考了某位网友的模拟总线程序,时间好久了想不起来了。 //在此感谢那位网友 //程序要结合1335的硬件才能更明白 //接口用的是0口
#define uchar unsigned char #define uint unsigned int #define D1 0x0000 /*D1/D2/D3:分别为LCD第一二三区之首地址*/ #define D2 0x2580 #define D3 0x4b00
//lcd interface #define WR_N (1<<13) #define RD_N (1<<12) #define CS_N (1<<16) #define A0 (1<<15)
#define DB0 (1<<4) #define DB1 (1<<5) #define DB2 (1<<6) #define DB3 (1<<7) #define DB4 (1<<8) #define DB5 (1<<9) #define DB6 (1<<10) #define DB7 (1<<11)
#define LCD 1 //显示效果不错 ,还需要改进 void OutData(unsigned char Data) { volatile uchar i; IO0CLR|=A0; IO0CLR|=CS_N; for(i=0;i<LCD;i++) ; IO0SET|=(Data<<4); Data=(~Data); IO0CLR|=(Data<<4); IO0CLR|=WR_N; for(i=0;i<LCD;i++) ; IO0SET|=WR_N; for(i=0;i<LCD;i++) ; IO0SET|=CS_N; } void OutCommand(unsigned char CMD) { volatile uchar i; IO0SET|=A0; IO0CLR|=CS_N; for(i=0;i<LCD;i++) ; IO0SET|=(CMD<<4); CMD=(~CMD); IO0CLR|=(CMD<<4); IO0CLR|=WR_N; for(i=0;i<LCD;i++) ; IO0SET|=WR_N; for(i=0;i<LCD;i++) ; IO0SET|=CS_N; } void send_I2par(uchar z,uchar x,uchar y) /*送LCD两参数指令函数,第一形参为指令码*/ { OutCommand(z); OutData(x); OutData(y); } void send_I1par(uchar z,uchar x) /*送LCD单参数指令子程,第一形参为指令码*/ { OutCommand(z); OutData(x); } void send_I0par(uchar z) /*送LCD无参数指令子程,形参为指令码*/ { OutCommand(z); } void wr_one8(uint d,uchar x,uchar y,uint z) /* 向LCD写一个8x8字符函数, ch:8x8字符位于字库中的具体区域(CH8,CH16,CH24);d:欲写入LCD之显示区;x:LCD地址水平坐标;y:LCD 地址纵坐标,起点自上而下;z:字库中字符代码值*/ { uchar a,b ; const uchar * pCharLib; uint m,r,i; r=(d+x)+y*0x28; /*根据横纵坐标计算LCD实际地址,并将地址送b,a*/ a=r; /*a,LCD低8位地址*/ r >>= 8; b=r; /*B,LCD高8位地址*/ m=z*8; send_I0par(0x4f); send_I2par(0x46,a,b); send_I0par(0x42); pCharLib=CharLib; for(i=m;i<(m+8);i++) { OutData(*(pCharLib+i)); } } |