《凌阳单片机12864驱动.doc》由会员分享,可在线阅读,更多相关《凌阳单片机12864驱动.doc(10页珍藏版)》请在三一办公上搜索。
1、#define cmd 0/sid(5)IOA0sck(6)IOA1resetIOA2CS(4)Vcc PSBGND#define dat 1extern void wr_lcd(int dat_cmd,int data);extern void init_lcd(void);extern void clear_ddram(void);extern void cn_1_disp(int high,int low,int location);/显示一个汉字参数(汉字编码高字节,汉字编码低字节,显示位置)extern void en_1_disp(int data,int location);/显
2、示一个英文字母参数(字母asc码,显示位置)extern void full_disp(int *data,int num);/整屏依次显示参数(显示数据首地址,字符数)extern void series_disp(int *data,int location,int num);/依次连续显示参数(显示数据首地址,位置,字符数)extern void select_disp(int data1,int data2,int x0,int y0,int x1,int y1);/反白显示选择:data1,data2=0xff/取消选择:data1,data2=0x00/x0,x1=8横坐标/y0,
3、y1=64竖坐标选中(x0xx1)&(y0yy1)extern void dot_disp_up(char *addr);/上半屏点阵显示参数(点阵数据首地址)extern void dot_disp_down(char *addr);/下半屏点阵显示参数(点阵数据首地址)extern void clear_dot_disp_up(void);/清除上半屏点阵extern void clear_dot_disp_down(void);/清除下半屏点阵void sck_set(void)int *P_Watchdog_Clear=0x7012;int *P_IOA_Data=0x7000;int
4、 *P_IOA_Buffer=0x7001;*P_IOA_Data=(*P_IOA_Buffer)|0x0002;*P_Watchdog_Clear=0x0001;void sck_clear(void)int *P_Watchdog_Clear=0x7012;int *P_IOA_Data=0x7000;int *P_IOA_Buffer=0x7001;*P_IOA_Data=(*P_IOA_Buffer)&0xfffd;*P_Watchdog_Clear=0x0001;void sid_set(void)int *P_Watchdog_Clear=0x7012;int *P_IOA_Dat
5、a=0x7000;int *P_IOA_Buffer=0x7001;*P_IOA_Data=(*P_IOA_Buffer)|0x0001;*P_Watchdog_Clear=0x0001;void sid_clear(void)int *P_Watchdog_Clear=0x7012;int *P_IOA_Data=0x7000;int *P_IOA_Buffer=0x7001;*P_IOA_Data=(*P_IOA_Buffer)&0xfffe;*P_Watchdog_Clear=0x0001;void delayshort(int i)int *P_Watchdog_Clear=0x701
6、2;int j;for(j=0;ji;j+)*P_Watchdog_Clear=0x0001;void delaylong(int i)int *P_Watchdog_Clear=0x7012;int j,k;for(j=0;ji;j+)for(k=0;k20;k+)*P_Watchdog_Clear=0x0001;void wr_lcd(int dat_cmd,int data)int tmp,i,j;tmp=data;sck_clear();sid_set();for(i=0;i5;i+)sck_set();sck_clear();sid_clear();sck_set();sck_cle
7、ar();if(dat_cmd)sid_set();elsesid_clear();sck_set();sck_clear();sid_clear();sck_set();sck_clear();for(j=0;j2;j+)for(i=0;i4;i+)if(tmp&0x80)sid_set();elsesid_clear();tmp=tmp1;sck_set();sck_clear();sid_clear();for(i=0;i4;i+)sck_set();sck_clear();void init_lcd(void)int *P_IOA_Data=0x7000;int *P_IOA_Buff
8、er=0x7001;int *P_IOA_Dir=0x7002;int *P_IOA_Attrib=0x7003;*P_IOA_Dir=(*P_IOA_Dir|0x0007);*P_IOA_Attrib=(*P_IOA_Attrib|0x0007);*P_IOA_Data=(*P_IOA_Data|0x0007);*P_IOA_Data=(*P_IOA_Buffer&0xfffb);delayshort(200);*P_IOA_Data=(*P_IOA_Buffer|0x0004);delayshort(200);wr_lcd(cmd,0x30);wr_lcd(cmd,0x01);delays
9、hort(100);wr_lcd(cmd,0x06);wr_lcd(cmd,0x0c);delayshort(300);void clear_ddram(void)wr_lcd(cmd,0x30);wr_lcd(cmd,0x01);delayshort(200);void cn_1_disp(int high,int low,int location)/80h87h/90h97hwr_lcd(cmd,0x30);/88h8fhwr_lcd(cmd,location);/98h9fhdelayshort(20);wr_lcd(dat,high);wr_lcd(dat,low);void en_1
10、_disp(int data,int location)wr_lcd(cmd,0x30);wr_lcd(cmd,location);delayshort(20);wr_lcd(dat,data);void full_disp(int *data,int num)int i;int error=error;wr_lcd(cmd,0x30);wr_lcd(cmd,0x80);delayshort(20);if(num=16)for(i=0;i16)&(num=32)for(i=0;i16;i+)wr_lcd(dat,*data);data+;wr_lcd(cmd,0x90);for(i=16;i3
11、2)&(num=48)for(i=0;i16;i+)wr_lcd(dat,*data);data+;wr_lcd(cmd,0x90);for(i=16;i32;i+)wr_lcd(dat,*data);data+;wr_lcd(cmd,0x88);for(i=32;i48)&(num=64)for(i=0;i16;i+)wr_lcd(dat,*data);data+;wr_lcd(cmd,0x90);for(i=16;i32;i+)wr_lcd(dat,*data);data+;wr_lcd(cmd,0x88);for(i=32;i48;i+)wr_lcd(dat,*data);data+;w
12、r_lcd(cmd,0x98);for(i=48;i64)for(i=0;i5;i+)wr_lcd(dat,errori);void series_disp(int *data,int location,int num)int i;wr_lcd(cmd,0x30);wr_lcd(cmd,location);delayshort(20);for(i=0;inum;i+)wr_lcd(dat,*data);data+;void select_disp(int data1,int data2,int x0,int y0,int x1,int y1)/x0,x18y0,y164int i,j;if(y
13、1=32)for(j=y0;jy1;j+)for(i=x0;i32)for(j=(y0-32);j(y1-32);j+)for(i=x0;ix1;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x88+i);wr_lcd(cmd,0x30);wr_lcd(dat,data1);wr_lcd(dat,data2);wr_lcd(cmd,0x36);if(y032)for(j=y0;j32;j+)for(i=x0;ix1;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x80+i);
14、wr_lcd(cmd,0x30);wr_lcd(dat,data1);wr_lcd(dat,data2);for(j=0;j(y1-32);j+)for(i=x0;ix1;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x88+i);wr_lcd(cmd,0x30);wr_lcd(dat,data1);wr_lcd(dat,data2);wr_lcd(cmd,0x36);void dot_disp_up(char *addr)int i,j;for(j=0;j32;j+)for(i=0;i8;i+)wr_lcd(cmd,0x34);wr
15、_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x80+i);wr_lcd(cmd,0x30);wr_lcd(dat,addrj*16+2*i);wr_lcd(dat,addrj*16+2*i+1);wr_lcd(cmd,0x36);void dot_disp_down(char *addr)int i,j;for(j=0;j32;j+)for(i=0;i8;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x88+i);wr_lcd(cmd,0x30);wr_lcd(dat,addrj*16+2*i);wr_lcd(dat
16、,addrj*16+2*i+1);wr_lcd(cmd,0x36);void clear_dot_disp_up(void)int i,j;for(j=0;j32;j+)for(i=0;i8;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x80+i);wr_lcd(cmd,0x30);wr_lcd(dat,0x00);wr_lcd(dat,0x00);wr_lcd(cmd,0x36);void clear_dot_disp_down(void)int i,j;for(j=0;j32;j+)for(i=0;i8;i+)wr_lcd(cmd,0x34);wr_lcd(cmd,(0x80+j);wr_lcd(cmd,(0x88+i);wr_lcd(cmd,0x30);wr_lcd(dat,0x00);wr_lcd(dat,0x00);wr_lcd(cmd,0x36);