这几天在调试控制芯片为T6963C的128*64的液晶,不过没什么进展。液晶亮都没亮。
驱动程序如下,请各位不啬赐教。 #include <mega16.h> #include <delay.h>
#define WR PORTA.0 #define RD PORTA.1 #define CE PORTA.2 #define C_D PORTA.3
void init_io() { DDRA=0XFF;//porta is output CE=0; DDRC=0XFF;//portc is output PORTC=0XFF; }
void Re_Sta(unsigned char mark) { bit exit=0; unsigned char state; C_D=1; RD=1; WR=1; while(1) { RD=0; state=PINC; RD=1; switch(mark) { case 1:if(state&0x03)exit=1;break;/*check commad execution capability or check data read/write capability*/ case 2:if(state&0x04)exit=1;break;/*check auto mode data read capability*/ case 3:if(state&0x08)exit=1;break;/*check auto mode data write capability*/ case 4:if(state&0x40)exit=1;break;/*error flag;used for screen peek and screen copy commads*/ default:break; } if(exit==1) break; } }
void send_data(unsigned char dat) { C_D=0; PORTC=dat; WR=0; WR=1; }
void send_com(unsigned char com) { PORTC=com; WR=0; WR=1; }
void send_d_c(unsigned char sta_sty, unsigned char dat_num,unsigned char dat1,unsigned char dat2,unsigned char com) { if(dat_num) { Re_Sta(1); send_data(dat1); if(dat_num==2) Re_Sta(1); send_data(dat2); } switch(sta_sty) { case 1:Re_Sta(1);send_com(com);break; case 2:Re_Sta(2);send_com(com);break; case 3:Re_Sta(3);send_com(com);break; case 4:Re_Sta(4);send_com(com);break; default:break; } }
void init_lcd(void) { send_d_c(1,2,0x00,0x00,0x21);//set the position of curser send_d_c(1,2,0x00,0x00,0x40);//set text home address send_d_c(1,2,0X20,0X00,0X41);//set text area send_d_c(1,2,0X00,0X80,0X42);//set graphic home address send_d_c(1,2,0X20,0X00,0X43);//set graphic area send_d_c(1,0,0x00,0x00,0x80);//set the logic of display,internal character generator mode send_d_c(1,0,0x00,0x00,0x9f);//text on,graphic on,cursor on,blink on send_d_c(1,0,0x00,0x00,0xaf);//8-line cursor }
void clear_lcd(void) { unsigned char i,j; send_d_c(1,2,0X00,0X00,0X24);//set address pointer send_d_c(1,0,0x00,0x00,0xb0);//set auto write mode for(i=0;i<205;i++) { for(j=0;j<=40;j++) { Re_Sta(3); C_D=0; PORTC=0X00; WR=0; WR=1; } } send_d_c(3,0,0x00,0x00,0xb2);//set auto reset }
main() { delay_ms(200); init_io(); init_lcd(); //clear_lcd(); } |