欢迎来到天天文库
浏览记录
ID:55210608
大小:17.50 KB
页数:4页
时间:2020-05-03
《串口液晶显示程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#defineSENDCOMM0XF8//0XF1000#defineREADCOMM0XFC//0XF1100#defineSENDDATA0XFA//0XF1010#defineREADDATA0XFE//0XF1110voidLCD_send_byte(unsignedchara);unsignedcharLCD_read_byte(void);voidLCD_comm(unsignedcharcomm);voidLCD_setxy(unsigned
2、charx,unsignedchary);voidLCD_WriteStr(unsignedchardis_addr_x,unsignedchardis_addr_y,char*str);sbitE_CLK=P2^2;//clockinputsbitRW_SID=P2^1;//datainput/outputsbitRS_CS=P2^0;//chipselectvoiddelay(unsignedintn){unsignedinti;for(i=0;i3、hara){unsignedchari;for(i=8;i>0;i--){if(a&(0x01<<(i-1)))RW_SID=1;elseRW_SID=0;delay(100);E_CLK=1;delay(100);E_CLK=0;delay(100);}}unsignedcharLCD_read_byte(void){unsignedchari,dat=0;for(i=8;i>0;i--){E_CLK=1;delay(100);if(RW_SID==1)dat4、=(0x01<<(i-1));E_CLK=0;delay(1005、);}returndat;}unsignedcharLCD_bf(void){unsignedcharreadh,readl;RS_CS=1;delay(100);LCD_send_byte(READCOMM);readh=LCD_read_byte();readl=LCD_read_byte();delay(100);RS_CS=0;}voidLCD_comm(unsignedcharcomm){unsignedchartemp;RS_CS=1;delay(100);LCD_send_byte(SENDCOMM);temp=6、comm&0XF0;LCD_send_byte(temp);temp=((comm&0X0F)<<4)&0XF0;LCD_send_byte(temp);delay(100);RS_CS=0;}voidLCD_data(unsignedcharlcd_data){unsignedchartemp;RS_CS=1;delay(100);LCD_send_byte(SENDDATA);temp=lcd_data&0xf0;LCD_send_byte(temp);temp=(lcd_data&0X0F)<<4;LCD_send_by7、te(temp);delay(100);RS_CS=0;}voidLCD_setxy(unsignedcharx,unsignedchary)//设置显示位置X(1~16),Y(1~4){switch(y){case1:LCD_comm(0X7F+x);break;case2:LCD_comm(0X8F+x);break;case3:LCD_comm(0X87+x);break;case4:LCD_comm(0X97+x);break;default:break;}}voidLCD_WriteStr(unsignedchard8、is_addr_x,unsignedchardis_addr_y,char*str)//在指定位置显示字符串{unsignedcharLCD_temp;LCD_setxy(dis_addr_x,dis_addr_y);LCD_temp=*str;while(LCD_temp!=0x00){LCD_data(LCD_temp);LCD_temp=*(++str);}}voidLCD_init(void){unsignedchari;while(i==0x80)RS_CS=0;delay(500);LCD_comm(0x30);/9、/一次送8位数据LCD_comm(0x0C);//整体显示,游标off,游标位置offLCD_comm(0x01);//清DDRAMLCD_comm(0x02);//DDRAM地址归位LCD_comm(0x80);//设定DDRAM7位地址000,0000到地址计数器AC}v
3、hara){unsignedchari;for(i=8;i>0;i--){if(a&(0x01<<(i-1)))RW_SID=1;elseRW_SID=0;delay(100);E_CLK=1;delay(100);E_CLK=0;delay(100);}}unsignedcharLCD_read_byte(void){unsignedchari,dat=0;for(i=8;i>0;i--){E_CLK=1;delay(100);if(RW_SID==1)dat
4、=(0x01<<(i-1));E_CLK=0;delay(100
5、);}returndat;}unsignedcharLCD_bf(void){unsignedcharreadh,readl;RS_CS=1;delay(100);LCD_send_byte(READCOMM);readh=LCD_read_byte();readl=LCD_read_byte();delay(100);RS_CS=0;}voidLCD_comm(unsignedcharcomm){unsignedchartemp;RS_CS=1;delay(100);LCD_send_byte(SENDCOMM);temp=
6、comm&0XF0;LCD_send_byte(temp);temp=((comm&0X0F)<<4)&0XF0;LCD_send_byte(temp);delay(100);RS_CS=0;}voidLCD_data(unsignedcharlcd_data){unsignedchartemp;RS_CS=1;delay(100);LCD_send_byte(SENDDATA);temp=lcd_data&0xf0;LCD_send_byte(temp);temp=(lcd_data&0X0F)<<4;LCD_send_by
7、te(temp);delay(100);RS_CS=0;}voidLCD_setxy(unsignedcharx,unsignedchary)//设置显示位置X(1~16),Y(1~4){switch(y){case1:LCD_comm(0X7F+x);break;case2:LCD_comm(0X8F+x);break;case3:LCD_comm(0X87+x);break;case4:LCD_comm(0X97+x);break;default:break;}}voidLCD_WriteStr(unsignedchard
8、is_addr_x,unsignedchardis_addr_y,char*str)//在指定位置显示字符串{unsignedcharLCD_temp;LCD_setxy(dis_addr_x,dis_addr_y);LCD_temp=*str;while(LCD_temp!=0x00){LCD_data(LCD_temp);LCD_temp=*(++str);}}voidLCD_init(void){unsignedchari;while(i==0x80)RS_CS=0;delay(500);LCD_comm(0x30);/
9、/一次送8位数据LCD_comm(0x0C);//整体显示,游标off,游标位置offLCD_comm(0x01);//清DDRAMLCD_comm(0x02);//DDRAM地址归位LCD_comm(0x80);//设定DDRAM7位地址000,0000到地址计数器AC}v
此文档下载收益归作者所有