/***********************************************名稱 :帶T6963C 控制器液晶驅(qū)動模塊設(shè)計者:阿飛時間:dec.09.10版本:vec1**************************************************/#include"reg51.h"#include"zifu.h"#define uchar unsigned char#define uint unsigned int#define lcd_data P1#define lcd_com P2extern void write_clcd_two(uchar dat1,uchar dat2,uchar com); extern void write_clcd_one(uchar dat1,uchar com);extern void write_clcd(uchar com);extern write_dlcd(uchar dat);extern uchar read_ddata();/******sbit rd=lcd_com^0; sbit wr=lcd_com^1;sbit cd=lcd_com^2; sbit ce=lcd_com^3;**************//**指令格式 參數(shù)1 參數(shù)2 指令代碼 *//**讀lcd狀態(tài)字節(jié) state***/uchar read_flag_lcd() {uchar dat;lcd_com=0x06;dat=lcd_data;lcd_com=0x0f;return dat;}/****檢查lcd狀態(tài)字state 0,1位是否為1,1表示lcd已準(zhǔn)備好*****/void check0_1(){uchar dat;dat=read_flag_lcd() ;while(dat0x03!=0x03);}/****檢查lcd狀態(tài)字state 第2位是否為1,1表示lcd數(shù)據(jù)自動讀操作已準(zhǔn)備好*****/void check2(){uchar dat;dat=read_flag_lcd() ;while(dat0x04!=0x03);}/****檢查lcd狀態(tài)字state 第2位是否為1,1表示lcd數(shù)據(jù)自動寫操作已準(zhǔn)備好*****/void check3(){uchar dat;dat=read_flag_lcd() ;while(dat0x08!=0x08);}/****檢查lcd狀態(tài)字state 第6位是否為1,1屏讀/拷貝出錯狀態(tài)****/void check6(){uchar dat;dat=read_flag_lcd() ;while(dat0x40!=0x40);}/****寫命令字data1 data2 為參數(shù) com為命令字節(jié)*****/void write_clcd_two(uchar dat1,uchar dat2,uchar com){check0_1();lcd_com=0x01;lcd_data=dat1;lcd_com=0x0f;check0_1();lcd_com=0x01;lcd_data=dat2;lcd_com=0x0f;check0_1();lcd_com=0x05;lcd_data=com;lcd_com=0x0f;}/****寫命令字data1為參數(shù) com為命令字節(jié)*****/void write_clcd_one(uchar dat1,uchar com){check0_1();lcd_com=0x01;lcd_data=dat1;lcd_com=0x0f;check0_1();lcd_com=0x05;lcd_data=com;lcd_com=0x0f;}/****無參數(shù) com為命令字節(jié)*****/void write_clcd(uchar com){check0_1();lcd_com=0x05;lcd_data=com;lcd_com=0x0f;}/****讀數(shù)據(jù) data*****/uchar read_ddata(){uchar dat;check0_1();lcd_com=0x02;dat=lcd_data;lcd_com=0x0f;return dat;}/****寫數(shù)據(jù) data*****/write_dlcd(uchar dat){check0_1();lcd_com=0x01;lcd_data=dat;lcd_com=0x0f;}lcd_clr(){uint n;write_clcd_two(0x00,0x00,0x24);write_clcd(0xb0);for(n=0;n480;n++)write_dlcd(0x00);write_clcd(0xb2);}void word_16(uchar row ,uchar list, uchar *pdat){uchar addr_h,addr_l,n;uint p_addr;if(row>29){list=list+(row/30)4;row=row%30;}for(n=0;n16;n++){p_addr=(list+n)*30+row;addr_h=p_addr>>8;addr_l=p_addr%256;write_clcd_two(addr_l,addr_h,0x24);write_clcd(0xb0);check3();write_dlcd(*(pdat+2*n));check3();write_dlcd(*(pdat+2*n+1));write_clcd(0xb2);}}void word_8(uchar row ,uchar list, uchar *pdat){uchar addr_h,addr_l,n;uint p_addr;for(n=0;n16;n++){p_addr=(list+n)*30+row;addr_h=p_addr>>8;addr_l=p_addr%256;write_clcd_two(addr_l,addr_h,0x24);write_clcd(0xb0);check3();write_dlcd(*(pdat+n));write_clcd(0xb2);}}lcd_init(){//顯示區(qū)域設(shè)置指令格式為:D1低 D2高 0 1 0 0 0 0 n1 n0write_clcd_two(0x00,0x00,0x40);//文本區(qū)首地址 0x0000write_clcd_two(0x1e,0x00,0x41);//文本區(qū)屏寬字節(jié)數(shù) 0x1e =30 *8bit//write_clcd_two(0x00,0x00,0x42);// 設(shè)置圖形顯示區(qū)域首地址//write_clcd_two(0x1e,0x00,0x43);// 圖形區(qū)屏寬字節(jié)數(shù)write_clcd(0xa0);//光標(biāo)形狀設(shè)置 1 0 1 0 0 N2 N1 N0 光標(biāo)高度write_clcd(0x9d);//顯示開關(guān) 1 0 0 1 N3 N2 N1 N0 N0:1/0,光標(biāo)閃爍啟用/禁止N1:1/0,光標(biāo)顯示啟用/禁止N2:1/0,文本顯示啟用/禁止N3:1/0,圖形顯示啟用/禁止write_clcd(0x80);//顯示方式設(shè)置,邏輯"或"合成}user_letter(uchar row ,uchar list, uchar *pdat ){uchar addr_h,addr_l;uint p_addr,n;if(row>29){list=list+(row/30)4;row=row%30;}p_addr=list*30+row;addr_h=p_addr>>8;addr_l=p_addr%256;write_clcd_two( addr_l, addr_h,0x24);write_clcd(0xb0);for(n=0;n3840-p_addr;n++)///////////////////////////////{check3();write_dlcd(*(pdat+n));}write_clcd(0xb2);}void delay(int z) {int x,y;for(x=z;x>0;x--)for(y=1000;y>0;y--);} main(){uchar n;lcd_init();write_clcd_two(0x00,0x00,0x24);//write_clcd_two(0x00,0x00,0x24);//user_letter(0x00 ,0x00, over1);//for(n=0;n57;n++)//word_16(0x04+2*n ,0x00, word+32*n);//delay(1000);//user_letter(0x00 ,0x40, afei);//delay(1000);//write_clcd_two(0x00,0x00,0x24);//user_letter(0x00 ,0x00, over);//write_clcd(0xb0);//數(shù)據(jù)自動讀/寫方式設(shè)置1 0 1 1 0 0 N1 N00 0 B0H 自動寫設(shè)置0 1 B1H 自動讀設(shè)置1 * B2H/B3H 自動讀/寫結(jié)束//for(n=0;n150;n++)//{//check3();//write_dlcd(0x12);//}//write_clcd(0xb2);write_clcd_one(0x03,0xc4);write_clcd_two(0x1f,0x0f,0x21);write_dlcd(0xf0);while(1){};}
評論