在用51單片機做停車場實驗的時候一直無法讓LCD12864正常顯示,用了比較久的時候才完成了這樣一個簡單且可行的程序,親測可用。并附上LCD12864的手冊與ST7920中文字型碼表。這是實驗時成功顯示的圖片:
51hei拼音截圖20190920161447.png (246.41 KB, 下載次數: 56)
下載附件
這是實驗時成功顯示的圖片
2019-9-20 16:16 上傳
代碼如下:
- #include "reg52.h" /
- #include "intrins.h"
- #define LCD_DB P0 //LCD12864顯示數據接口定義
- typedef unsigned char u8;
- typedef unsigned int u16;
- sbit LCD_RS=P2^6; //定義LCD12864使用的IO口
- sbit LCD_RW=P2^5;
- sbit LCD_EN=P2^7;
- sbit DSdat=P3^4;
- u8 usablespace; //停車場可用空間
- u16 time1; //停車時間
- u8 fee; //停車費用
- //---車牌首位漢字顯示數據編碼---//
- code u16 platenumber[32]={0xBEA9,0xBDF2,0xBBA6,0xD3E5,0xD5E3,0xC3F6,0xD4C1,0xBCBD,0xBDFA,0xC3C9, //京 津 滬 渝 浙 閩 粵 冀 晉 蒙
- 0xC1C9,0xBCAA,0xBADA,0xCBD5,0xCDEE,0xB8D3,0xC2B3,0xD4A5,0xB6F5,0xCFE6, //遼 吉 黑 蘇 皖 贛 魯 豫 鄂 湘
- 0xB9F3,0xC7ED,0xB4A8,0xB9F1,0xD4C6,0xB2D8,0xC9C2,0xB8CA,0xC7E0,0xC4FE,0xD0C2,0xA1A0}; //貴 瓊 川 桂 云 藏 陜 甘 青 寧 新 無
- u8 car1[10]={22,0x11,0x11,0x12,0x01,0x02,0x03,13}; //車輛賬戶信息:車牌省位0,車牌市位1,號牌編號2~6,余額7
- void delay_12864(u16 del) //LCD12864延時函數
- {
- u16 i;
- for(i = 0; i < del; i++){; }
- }
-
- void Init_LCD(void) //初始化LCD控制端口函數
- {
- LCD_RS=1; //輸出數據LCD_RS和LCD_EN清零
- LCD_RW=0;
- LCD_EN=0;
- }
- void LCD_write_command(u8 command) //LCD12864寫指令函數
- {
- LCD_EN=0;
- LCD_RS=0; //寫指令
- LCD_RW=0; //寫入
- LCD_DB=command;//賦值給D0-D7對應的IO引腳
- delay_12864(50);
- LCD_EN=1; //允許
- delay_12864(50);
- LCD_EN=0;
- }
- void LCD_write_data(u8 dat) //LCD12864寫數據函數
- {
- LCD_EN=0;
- LCD_RS=1; //寫數據
- LCD_RW=0; //寫入
- LCD_DB=dat;//賦值給D0-D7對應的IO引腳
- delay_12864(50);
- LCD_EN=1; //允許
- delay_12864(50);
- LCD_EN=0;
- }
- void LCD_init(void) //初始化LCD12864顯示設置函數
- {
- delay_12864(10000);
- LCD_write_command(0x30);//功能設置
- delay_12864(20);
- LCD_write_command(0x30);//功能設置
- delay_12864(20);
- LCD_write_command(0x0c);//顯示開關控制
- delay_12864(20);
- LCD_write_command(0x01);//顯示清除
- delay_12864(1200);
- LCD_write_command(0x06);//顯示清除
- delay_12864(50);
- }
- void LCD_SHOW() //LCD顯示函數
- {
- Init_LCD(); //初始化LCD控制端口
- LCD_init(); //初始化LCD顯示設置
- LCD_write_command(0x80); //第一行數據指針地址
- //-------------第一行顯示內容-------------//
- LCD_write_data(0xBF); //空
- LCD_write_data(0xD5);
- LCD_write_data(0xB3); //車
- LCD_write_data(0xB5);
- LCD_write_data(0xCE); //位
- LCD_write_data(0xBB);
- LCD_write_data(0xA1); //:
- LCD_write_data(0xC3);
- LCD_write_data(0x20);
- LCD_write_data(0x20);
- LCD_write_data(usablespace/10+'0'); //空車位十位
- LCD_write_data(usablespace%10+'0'); //空車位個位
- LCD_write_data(0xB8); //個
- LCD_write_data(0xF6);
- LCD_write_data(0x20);
- LCD_write_data(0x20);
- //-------------第三行顯示內容-------------//
- LCD_write_data(0xCA); //時
- LCD_write_data(0xB1);
- LCD_write_data(0xB3); //長
- LCD_write_data(0xA4);
- LCD_write_data(0xA1); //:
- LCD_write_data(0xC3);
- LCD_write_data(time1/600+'0'); //停車小時 十位
- LCD_write_data(time1/60%10+'0'); //停車小時 個位
- LCD_write_data(0xD0); //小
- LCD_write_data(0xA1); //
- LCD_write_data(0xCA); //時
- LCD_write_data(0xB1); //
- LCD_write_data(time1%60/10+'0'); //停車分鐘 十位
- LCD_write_data(time1%60%10+'0'); //停車分鐘 個位
- LCD_write_data(0xB7); //分
- LCD_write_data(0xD6); //
- //-------------第二行顯示內容-------------//
- LCD_write_data(0xB3); //車
- LCD_write_data(0xB5);
- LCD_write_data(0xC5); //牌
- LCD_write_data(0xC6);
- LCD_write_data(0xBA); //號
- LCD_write_data(0xC5);
- LCD_write_data(0xA1); //:
- LCD_write_data(0xC3); //
- LCD_write_data(platenumber[car1[0]]>>8); //車牌省位
- LCD_write_data(platenumber[car1[0]]&0xff);
- LCD_write_data(car1[1]+'0'); //車牌市位
- LCD_write_data(car1[2]+'0'); //車牌號編碼
- LCD_write_data(car1[3]+'0');
- LCD_write_data(car1[4]+'0');
- LCD_write_data(car1[5]+'0');
- LCD_write_data(car1[6]+'0');
- //-------------第四行顯示內容-------------//
- LCD_write_data(0xCD); //停
- LCD_write_data(0xA3);
- LCD_write_data(0xB3); //車
- LCD_write_data(0xB5);
- LCD_write_data(0xB7); //費
- LCD_write_data(0xD1);
- LCD_write_data(0xD3); //用
- LCD_write_data(0xC3); //
- LCD_write_data(0xA1); //:
- LCD_write_data(0xC3); //
- LCD_write_data(fee/10+'0'); //停車費十位
- LCD_write_data(fee%10+'0'); //停車費個位
- LCD_write_data(0xD4); //元
- LCD_write_data(0xAA); //
- LCD_write_data(0xA1); //無
- LCD_write_data(0xA0);
- delay_12864(10);
- }
- void main() //主函數
- {
- usablespace=50;
- time1=33;
- fee=5;
-
- while(1)
- {
- LCD_SHOW(); //LCD12864進行顯示
- }
- }
復制代碼
0.png (6.46 KB, 下載次數: 62)
下載附件
2019-9-20 17:12 上傳
全部資料51hei下載地址:
程序代碼及LCD12864相關資料.zip
(3.92 MB, 下載次數: 109)
2019-9-20 16:23 上傳
點擊文件名下載附件
程序代碼及LCD12864相關資料 下載積分: 黑幣 -5
|