資料請下載附件
單片機源程序如下:
- #include<reg51.h>
- #include<string.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- void Initialize_LCD();
- void DelayMS(uint ms);
- void ShowString(uchar,uchar,uchar *);
- sbit RS=P2^0;
- sbit RW=P2^1;
- sbit EN=P2^2;
- sbit K1=P3^0;
- sbit K2=P3^1;
- sbit K3=P3^2;
- uchar code Prompt[]="Press K1 - K3 To Start Demo Prog";
- uchar const Line_Count=10;
- uchar code Msg[][80]=
- {" <The furthest distance in the world> "
- " The furthest distance in the world ",
- " Is not between life and death ",
- " But when I stand in front of you ",
- " Yet you do not know that",
- " I love you ",
- " The furthest distance in the world ",
- " Is not when I stand in font of you ",
- " Yet you can not see my love ",
- " But when undoubtedly knowing the love from bot ",
- " Yet cannot ",
- " Be together "
- };
- uchar Disp_Buffer[32]; //顯示緩沖(2行)
- void DelayMS(uint ms) //延時
- {
- uchar i;
- while(ms--) for(i=0;i<120;i++);
- }
- uchar Busy_Check()
- {
- uchar LCD_Status;
- RS=0;
- RW=1;
- EN=1;
- DelayMS(1);
- LCD_Status=P0;
- EN=0;
- return LCD_Status;
- }
- void Write_LCD_Command(uchar cmd)
- {
- while((Busy_Check()&0x80)==0x80);
- RS=0;
- RW=0;
- EN=0;
- P0=cmd;EN=1;DelayMS(1);EN=0;
- }
- void Write_LCD_Data(uchar dat)
- {
- while((Busy_Check()&0x80)==0x80);
- RS=1;RW=0;EN=0;P0=dat;EN=1;DelayMS(1);EN=0;
- }
- void Initialize_LCD()
- {
- Write_LCD_Command(0x38);DelayMS(1);
- Write_LCD_Command(0x01);DelayMS(1);
- Write_LCD_Command(0x06);DelayMS(1);
- Write_LCD_Command(0x0c);DelayMS(1);
- }
- void ShowString(uchar x,uchar y,uchar *str)
- {
- uchar i=0;
- if(y==0) Write_LCD_Command(0x80|x);
- if(y==1) Write_LCD_Command(0xc0|x);
- for(i=0;i<16;i++)
- {
- Write_LCD_Data(str[i]);
- }
- }
- void H_Scroll_Display()
- {
- uchar i,j,k=0,L=0;
- uchar *p=Msg[0];
- uchar *q=Msg[Line_Count]+strlen(Msg[Line_Count]);
- for(i=0;i<16;i++) Disp_Buffer[i]=' ';
- while(p<q)
- {
- if((i==16||i==31)&&*p==' ') p++;
- for(i=16;i<32&&p<q;i++)
- {
- if(*p!='\0')
- {
- Disp_Buffer[i]=*p++;
- }
- else
- {
- if(++k>Line_Count) break;
- p=Msg[k];
- Disp_Buffer[i]=*p++;
- }
- }
- for(j=i;j<32;j++) Disp_Buffer[j]=' ';
- for(i=0;i<=16;i++)
- {
- while(F0) DelayMS(5);
- ShowString(0,L,Disp_Buffer+i);
- while(F0) DelayMS(5);
- DelayMS(30);
- }
- L=(L==0)?1:0;
- DelayMS(300);
- }
- if(L==1) ShowString(0,1," ");
- }
- void EX_INT0() interrupt 0
- {
- F0=!F0;
- }
- void main()
- {
- uint Count=0;
- IE=0x81;
- IT0=1;
- F0=0;
- Initialize_LCD();
- ShowString(0,0,Prompt);
- ShowString(0,1,Prompt+16);
- while(1)
- {
- if(K2==0)
- {
- H_Scroll_Display();
- DelayMS(300);
- }
- }
- }
復制代碼
所有資料51hei提供下載:
水平滾動.rar
(25.88 KB, 下載次數: 15)
2018-11-18 20:33 上傳
點擊文件名下載附件
詩歌字符顯示 下載積分: 黑幣 -5
|