这是我写的显示的代码,按键切换显示内容,如果我想实现按键变成内容滚动,应该怎么写!
单片机源程序如下:
- #include <reg51.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- /*12864端口定义*/
- #define LCD_data P0 //数据口
- sbit LCD_RS = P2^6; //寄存器选择输入
- sbit LCD_RW = P2^5; //液晶读/写控制
- sbit LCD_EN = P2^7; //液晶使能控制
- sbit LCD_PSB = P3^2; //串/并方式控制
- sbit wela = P2^6;
- sbit dula = P2^7;
- sbit key =P2^3;
- uchar code dis1[] = {"打电话说哈实际上"};
- uchar code dis2[] = {"今天星期五"};
- uchar code dis3[] = {"哈哈哈哈哈"};
- uchar code dis4[] = {"吃米线"};
- uchar code dis5[] = {"单片机哈 "};
- uchar code dis6[] = {"单片机哈哈"};
- uchar code dis7[] = {"单片机哈哈哈"};
- uchar code dis8[] = {"单片机哈哈哈哈"};
- #define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
- uchar IRDIS[2];
- uchar IRCOM[4];
- void dataconv();
- void delay0(uchar x); //x*0.14MS
- void lcd_pos(uchar X,uchar Y); //确定显示位置
- /*******************************************************************/
- /* */
- /* 延时函数 */
- /* */
- /*******************************************************************/
- void delay(uint time)
- {
- uint x,y;
- for(x=time;x;x--)
- for(y=110;y;y--);
- }
- /*******************************************************************/
- /* */
- /*检查LCD忙状态 */
- /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */
- /* */
- /*******************************************************************/
- bit lcd_busy()
- {
- bit result;
- LCD_RS = 0;
- LCD_RW = 1;
- LCD_EN = 1;
- delayNOP();
- result = (bit)(P0&0x80);
- LCD_EN = 0;
- return(result);
- }
- void lcd_wcmd(uchar cmd)
- {
- lcd_busy();
- LCD_RS = 0;
- LCD_RW = 0;
- LCD_EN = 1;
- delay(2);
- P0 = cmd;
- delay(2);
- LCD_EN = 0;
- }
- /*******************************************************************/
- /* */
- /*写显示数据到LCD */
- /*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */
- /* */
- /*******************************************************************/
- void lcd_wdat(uchar dat)
- {
- while(lcd_busy());
- LCD_RS = 1;
- LCD_RW = 0;
- LCD_EN =1;
- delay(2);
- P0 = dat;
- delay(2);
- LCD_EN = 0;
- }
- void lcd_init()
- {
- LCD_PSB = 1; //并口方式
- lcd_wcmd(0x34); //扩充指令操作
- delay(5);
- lcd_wcmd(0x30); //基本指令操作
- delay(5);
- lcd_wcmd(0x0C); //显示开,关光标
- delay(5);
- lcd_wcmd(0x01); //清除LCD的显示内容
- delay(5);
- }
- /*********************************************************/
- /* */
- /* 延时x*0.14ms子程序 */
- /* */
- /*********************************************************/
- void delay0(uchar x) //x*0.14MS
- {
- uchar i;
- while(x--)
- {
- for (i = 0; i<13; i++) {}
- }
- } //* 设定显示位置 ******************************************************/
- /*void lcd_pos(uchar X,uchar Y)
- {
- uchar pos;
- if (X==0)
- {X=0x80;}
- else if (X==1)
- {X=0x90;}
- else if (X==2)
- {X=0x88;}
- else if (X==3)
- {X=0x98;}
- pos = X+Y ;
- lcd_wcmd(pos); //显示地址
- }
- */
- void print(uchar line,uchar *dis5)
- {
- uchar code p[4]={0x80,0x90,0x88,0x98};
- uchar i;
- lcd_wcmd(p[line]);
- for(i=0;dis5[i] != '\0';i++)
- lcd_wdat(dis5[i]); //显示字符
- }
- main()
- {
- uchar i;
- delay(10); //延时
- wela=0;
- dula=0;
- lcd_init(); //初始化LCD
- while(1)
- {
- if(key==0)
- {
- print(0,dis5);
- print(1,dis6);
- print(2,dis7);
- print(3,dis8);
- }
- else
- {
- print(0,dis1);
- print(1,dis2);
- print(2,dis3);
- print(3,dis4);
- }
- }
- }
复制代码 |