|
- /*lcd12864只需三根線與單片機(jī)相連就可以實(shí)現(xiàn)串行通訊,lcd12864自帶ASCII碼庫 以下是程序代碼*/
- #include"reg52.h"
- #include"intrins.h"
- #define uint unsigned int
- #define uchar unsigned char
- #define x1 0x80
- #define x2 0x88
- #define y 0x80
- #define comm 0//0代表寫指令
- #define dat 1//1代表寫數(shù)據(jù)
- sbit LCD_cs =P2^7;
- sbit LCD_std =P2^6;
- sbit LCD_sclk =P2^5;
- void wr_lcd(uchar dat_comm,uchar content);
- void delay (uint us);
- void lcd_char(uchar x0,uchar y0,uchar k,uchar *chn);
- void init_lcd(void);
- void lcd_string(uchar x0,uchar y0,uchar k,uchar *chn);
- //------------------初始化 -----------------
- void init_lcd(void)
- {
- //rst=1;
- wr_lcd(comm,0x30);//30---基本指令動作
- wr_lcd(comm,0x01);//清屏,地址指針指向 00H
- wr_lcd(comm,0x06);//光標(biāo)的移動方向
- wr_lcd(comm,0x0c);//開顯示,關(guān)游標(biāo)
- }
- void wr_lcd(uchar dat_comm,uchar content)
- {
- uchar a,i,j;
- delay (500);//此延時是必須的,以防在連續(xù)操作中 LCD 內(nèi)部動作沒有完成, 不響應(yīng)后面的指令或數(shù)據(jù)
- a=content;
- LCD_cs=1;
- _nop_();
- LCD_sclk=0;
- _nop_();
- LCD_std=1;
- _nop_();
- for(i=0; i<5; i++)
- {
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- }
- LCD_std=0;
- _nop_();
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- _nop_();
- if(dat_comm) //如果 dat_comm為高則表示送的是顯示數(shù)據(jù)
- LCD_std=1; //data
- else //如果 dat_comm為低則表示送的是控制指令
- LCD_std=0; //command
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- LCD_std=0;
- _nop_();
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- for(j=0; j<2; j++)
- {
- for(i=0; i<4; i++)
- {
- a=a<<1;
- LCD_std=CY;
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- }
- LCD_std=0;
- for(i=0; i<4; i++) {
- LCD_sclk=1;
- _nop_();
- _nop_();
- _nop_();
- LCD_sclk=0;
- }
- }
- }
- void delay (uint us)//delaytime
- {
- while(us--);
- }
- void delay1(uint ms)
- {
- uint i,j;
- for(i=0; i<ms; i++)
- for(j=0; j<15; j++)
- delay(1);
- }
- //-------在任意位置顯示一串漢字或字符 ------
- //其中 一個漢字算兩個個字節(jié)
- //X0為行, Y0為列, chn 為所要顯示的漢字串 ,k 為字符個數(shù)
- void lcd_char(uchar x0,uchar y0,uchar k,uchar *chn)
- {
- uchar adr,i;
- switch(x0)
- {
- case 1:
- adr =0x80+y0;
- break; //在第 1行 y 列顯示
- case 2:
- adr =0x90+y0;
- break; //在第 2行 y 列顯示
- case 3:
- adr =0x88+y0;
- break; //在第 3行 y 列顯示
- case 4:
- adr =0x98+y0;
- break; //在第 4行 y 列顯示
- default:
- ;
- }
- wr_lcd(comm,adr);
- for(i=0; i<k; i++)
- wr_lcd(dat,chn[i]);
- }
- //------------------主程序 --------------------
- void main ()
- {
- uchar chn[3]= {0x32,0x31,0x33};
- // uchar chn[6]= {32,50,32,54,32,56};
- // uchar b[]= {"歡迎使用本程序 "};
- //
- // uchar b1[]= {"啦啦啦啦 "};
- // char b2[]= {"歡迎你 "};
- init_lcd();
- while (1)
- {
- // lcd_char(1,0,14,b);//顯示漢字
- lcd_char(2,0,3,chn);//顯示字符串
- // lcd_char(3,0,12,b1);
- // lcd_char(4,0,6,b2);
- delay1(8000);//此處延時是為了防止送顯示過快,屏?xí)W動
- }
- }
復(fù)制代碼
|
-
-
LCD12864串行顯示.zip
2019-3-7 18:53 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
58.75 KB, 下載次數(shù): 194, 下載積分: 黑幣 -5
評分
-
查看全部評分
|