- #include <reg52.H>
- #define uint unsigned int
- #define uchar unsigned char
- uchar string1[]={"I LOVE YOU"};
- uchar string2[]={"FOR EVER! "};
- /****delay1ms***/
- /*函数功能:延时1ms
- 参数:count
- 返回类型:无
- */
- void delay1ms(unsigned int count)
- {
- unsigned int i,j;
- for(i=0;i<count;i++)
- for(j=0;j<120;j++);
- }
- /***lcd_busy***/
- /*函数功能:判断p0.7口是否为1,为1则为忙
- 参数:无
- 返回类型:p0.7的值
- ***/
- sbit rs = P2^7;
- sbit rw = P2^6;
- sbit en = P2^5;
- uchar lcd_busy(void)
- {uchar busy;
- rs=0;
- rw=1;
- en=1;
- delay1ms(1);
- busy=P0&0x80;
- delay1ms(1);
- en=0;
- return (busy);
- }
- /**lcd_write***/
- /*函数功能:向LCD中写数据和命令
- 参数:s=0 时向lcd写命令
- s=1 时向lcd写数据
- date 为要向lcd写入的数据
- 返回类型:无
- ***/
- #define cmd 0
- #define dat 1
- void lcd_write(uchar s,uchar date)
- {while (lcd_busy());
- rs=s;
- rw=0;
- en=1;
- delay1ms(1);
- P0=date;
- delay1ms(1);
- en=0;
- }
- /*****lcd_init****/
- /*函数功能:将lcd进行初始化处理
- 参数:无
- 返回类型:无
- ****/
- void lcd_init(void)
- {lcd_write(cmd,0x38); //设置16X2显示,5X7点阵,8位数据接口
- lcd_write(cmd,0x0c); //开显示,不显示光标,无光标闪烁
- lcd_write(cmd,0x06); //AC累加,屏幕不移动
- lcd_write(cmd,0x01); //清屏
- }
- /***lcd_XY****/
- /***函数功能:实现位置定位
- 参数:X Y的值
- 返回类型:无
- ***/
- void lcd_xy(uchar x,uchar y)
- {
- if(y==0) //表示在第一行显示
- lcd_write(cmd,0x80|x);
- if(y==1) //表示在第二行显示
- lcd_write(cmd,0x80|0x40|x);
- }
- /**lcd_print***/
- /*****函数功能:显示LCD数据
- 参数:*string
- 返回类型:无
- ***/
- void lcd_print(uchar *string) //string 表示要显示的数据
- {
- while(*string!='\0')
- {lcd_write(dat,*string);
- string++;
- }
- }
- /***lcd_display()***/
- /*函数功能:显示
- 参数:无
- 返回类型:无
- */
- void lcd_display()
- {lcd_xy(3,0);
- lcd_print(string1);
- lcd_xy(4,1);
- lcd_print(string2);
- }
- /****主函数****/
- void main()
- {
- while(lcd_busy());
- lcd_init();
- while(1)
- {
- lcd_display();
- }
- }
复制代码
|