lcd1602驱动程序
单片机源程序如下:
- #include<lcd1602.h>
- #include<reg52.h>
- #include<delay.h>
- #include<string.h>
- #include<intrins.h>
- #define uchar unsigned char
- sbit RS = P2^0;
- sbit RW = P2^1;
- sbit E = P2^2;
- void check_busy(void)
- {
- uchar dt;
- do
- {
- dt=0xff;
- E=0;
- RS=0;
- RW=1;
- E=1;
- dt=P0;
- }while(dt&0x80);
- E=0;
- }
- void LCD_Write_Cmd(unsigned char cmd) //写命令
- {
- check_busy();
- E=0;
- RS=0;
- RW=0;
- P0=cmd;
- E=1;
- _nop_();
- E=0;
- delay(1);
- }
- void LCD_Write_Dat(unsigned char dat)//写数据
- {
- check_busy();
- E=0;
- RS=1;
- RW=0;
- P0=dat;
- E=1;
- _nop_();
- E=0;
- delay(1);
- }
- //LCD初始化
- void LCD_Init(void)
- {
- LCD_Write_Cmd(LCD_Clear); // 清屏
- delayms(2);
- LCD_Write_Cmd(LCD_C_BLK);//让光标闪烁
- delayms(2);
- LCD_Write_Cmd(LCD_S_RMove);
- delayms(2);
- LCD_Write_Cmd(LCD_Double57);//双行显示
- delayms(2);
- }
- void LCD_String(unsigned char addr,unsigned char *s)
- {
- LCD_Write_Cmd(addr);
- while(*s>0)
- {
- LCD_Write_Dat(*s++);
- delay(100);
- }
- }
- void LCD_Write_VarDat(char addr,float num)
- {
- int temp;
- char Q,B,S,G;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
lcd1602.rar
(1.39 KB, 下载次数: 9)
|