- #include <REG51.H>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- //延時子程序模塊
- //**********************************************
- void mdelay(uint delay)
- { uint i;
- for(;delay>0;delay--)
- {for(i=0;i<80;i++) //1ms延時.
- {;}
- }
- }
- //************************************************
- void show(); //液晶顯示程序
- //****************************************
- //12864液晶顯示部分子程序模塊
- //****************************************
- sbit rs = P2^0;
- sbit rw = P2^1;
- sbit e = P2^2;
- #define lcddata P0
- sbit busy=P0^7; //lcd busy bit
- void wr_d_lcd(uchar content);
- void wr_i_lcd(uchar content);
- void clrram_lcd (void);
- void init_lcd(void);
- void busy_lcd(void);
- void rev_row_lcd(uchar row);
- void rev_co_lcd(uchar row,uchar col,uchar mode);
- void clr_lcd(void);
- void wr_co_lcd(uchar row,uchar col,uchar lcddata1,uchar lcddtta2);
- void wr_row_lcd(uchar row,char *p);
- //**********************************
- //液晶初始化
- //**********************************
- void init_lcd(void)
- {
- wr_i_lcd(0x06); /*光標的移動方向*/
- wr_i_lcd(0x0c); /*開顯示,關游標*/
- }
- //***********************************
- //填充液晶DDRAM全為空格
- //**********************************
- void clrram_lcd (void)
- {
- wr_i_lcd(0x30);
- wr_i_lcd(0x01);
- }
- //***********************************
- //對液晶寫數據
- //content為要寫入的數據
- //***********************************
- void wr_d_lcd(uchar content)
- {
- busy_lcd();
- rs=1;
- rw=0;
- lcddata=content;
- e=1;
- ;
- e=0;
- }
- //********************************
- //對液晶寫指令
- //content為要寫入的指令代碼
- //*****************************
- void wr_i_lcd(uchar content)
- {
- busy_lcd();
- rs=0;
- rw=0;
- lcddata=content;
- e=1;
- ;
- e=0;
- }
- //********************************
- //液晶檢測忙狀態
- //在寫入之前必須執行
- //********************************
- void busy_lcd(void)
- {
- lcddata=0xff;
- rs=0;
- rw=1;
- e =1;
- while(busy==1);
- e =0;
- }
- //********************************
- //指定要顯示字符的坐標
- //*******************************
- void gotoxy(unsigned char y, unsigned char x)
- {
- if(y==1)
- wr_i_lcd(0x80|x);
- if(y==2)
- wr_i_lcd(0x90|x);
- if(y==3)
- wr_i_lcd((0x80|x)+8);
- if(y==4)
- wr_i_lcd((0x90|x)+8);
- }
- //**********************************
- //液晶顯示字符串程序
- //**********************************
- void print(uchar *str)
- {
- while(*str!='\0')
- {
- wr_d_lcd(*str);
- str++;
- }
- }
- //***************************************
- //液晶顯示主程序模塊
- //***************************************
- void show()
- {
-
- gotoxy(1,0);
- print("歡迎光臨銳志電子");
- mdelay(200);
- gotoxy(2,0);
- print("【銳志電子】");
- mdelay(200); //掃描延時
- gotoxy(3,0);
- print("WWWwwwwwwwwwww");
- mdelay(200); //掃描延時
- gotoxy(4,0);
- print("12864 液晶測試");
- mdelay(200); //掃描延時
- }
- //************************************
- //主程序
- //*************************************
- main()
- {
-
- init_lcd();
- clrram_lcd();
-
- while(1)
- {
-
- show(); //液晶顯示數據
-
- }
-
- }
-
復制代碼
|