新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > C0851F410與12864液晶顯示

C0851F410與12864液晶顯示

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
#include "C8051F410.h"
#define uchar unsigned char#define LCMdata P2#define Busy 0x80sbit RS  = P1^3;sbit RW  = P1^4;sbit E   = P1^5;sbit PSB = P1^6;sbit REST= P0^7;//sfr16 TMR2RL = 0xCA;                   // Timer2 Reload Register//sfr16 TMR2   = 0xCC;void Display_String(uchar line,uchar *string);void Wr_Data(uchar wrdata); //寫數(shù)據(jù)void Wr_Command(uchar wrcommand,busyc); //寫指令void RDbf(void);//讀忙狀態(tài)void Lcm_Init(void);//液晶初始化void Delay5Ms(void);//延時5msvoid write_show(uchar);void SET_CGRAM(uchar,uchar);void Dis_CG(uchar,uchar,uchar);void Timer0Init(void);uchar count,miao;//uchar OS_Delay[1];uchar code string_1[] = {"祖國江山好,    "};uchar code string_2[] = {"愛情少不了。    "};uchar code string_3[] = {"  溫度:00      "};uchar code string_4[] = {"溫州大學--設(shè)計  "};uchar code CGRAM_ZIKU[]={0x70,0x00,0x50,0x00,0x70,0x00,0x07,0xFC,0x1C,0x06,0x38,0x02,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x00,0x70,0x02,0x38,0x02,0x1C,0x0C,0x0F,0xF0,0x00,0x00,0x00,0x00};void main(void){PCA0MD &= ~0x40;                    // Clear watchdog timer enableOSCICN = 0x81;                    while ((OSCICN & 0x40 ) == 0);      // Wait until stableP0MDOUT   = 0x80;P1MDOUT   = 0x78;P2MDOUT   = 0xFF;XBR1      = 0x40;Lcm_Init();Timer0Init() ;EA = 1 ; Display_String(1,string_1);Display_String(2,string_2); Display_String(3,string_3); Display_String(4,string_4);SET_CGRAM(1,&CGRAM_ZIKU);Dis_CG(2,6,1);while(1){if(count==20){count=0;miao++;if(miao==100){miao=0;}write_show(miao);}}}void SET_CGRAM(uchar num,uchar *CGRAM_ZIKU){uchar i,add;Wr_Command(0x34);Wr_Command(0x02);Wr_Command(0x30);add=(num<<4)|0x40;for(i=0;i<16;i++){Wr_Command(add+i);Wr_Data(CGRAM_ZIKU[i*2]);Wr_Data(CGRAM_ZIKU[i*2+1]);   }}void Set_Cursor(uchar x,uchar y){uchar i;switch(x){case 0x00:i=0x80;break;case 0x01:i=0x90;break;case 0x02:i=0x88;break;case 0x03:i=0x98;break;default:break; }i=y+i;Wr_Command(i);}void Dis_CG(uchar x,uchar y,uchar num){Set_Cursor(x,y);Wr_Data(0x00);Wr_Data(num*2); }void write_show(uchar date)//顯示計時{uchar shi,ge;shi=date/10;ge=date%10;Set_Cursor(2,4);Wr_Data(0x30+shi);Wr_Data(0x30+ge); }void Display_String(uchar line,uchar *string)//顯示字符串{ uchar addr,i;if(line==1)addr=0x80;else if(line==2)addr=0x90;else if(line==3)addr=0x88; else if(line==4)addr=0x98;  Wr_Command(addr,1);for(i=0;i<16;i++){ Wr_Data(*string++);} }void Wr_Data(uchar wrdata) //寫數(shù)據(jù){//RDbf();RS=1;RW=0;E=1;LCMdata=wrdata;E=0; }void Wr_Command(uchar wrcommand,busyc) //寫指令{//if(busyc)//RDbf();RS=0;RW=0;E=1;LCMdata=wrcommand;E=0;}void RDbf(void) //讀忙狀態(tài){while(1){RS=0;RW=1; E=0;LCMdata=P2;  E=1;if((LCMdata&Busy)==0)break;}}void Lcm_Init(void){PSB = 1;Delay5Ms(); REST=1;Delay5Ms(); Wr_Command(0x30,0);Delay5Ms();Wr_Command(0x30,0); //2次顯示模式設(shè)置,不用判忙Delay5Ms();Wr_Command(0x0C,1); //開顯示及光標設(shè)置Delay5Ms();Wr_Command(0x01,1); //顯示清屏Delay5Ms();Delay5Ms();Wr_Command(0x06,1); //顯示光標移動設(shè)置Delay5Ms();}void Timer0Init(void){TMOD &= 0xf0 ;TMOD |= 0x01 ; //定時器0工作方式1TH0 = 0xfc ; //定時器初始值TL0 = 0x66 ;TR0 = 1 ;ET0 = 1 ;}void Time0Isr(void) interrupt 1{TH0 = 0xfc ; //定時器重新賦初值TL0 = 0x66 ;count++; //1MS時標標志位置位}void Delay5Ms(void) //延時5ms{unsigned int TempCyc=5552;while(TempCyc--);}


關(guān)鍵詞: C0851F41012864液晶顯

評論


技術(shù)專區(qū)

關(guān)閉