這是我寫的顯示的代碼,按鍵切換顯示內容,如果我想實現按鍵變成內容滾動,應該怎么寫!
單片機源程序如下:
- #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);
- }
- }
- }
復制代碼 |