#includereg52.h>sbit RS=P2^0;sbit RW=P2^1;sbit EN=P2^2;//LCD的三個控制端unsigned char table[]={0x15,0x0A,0x15,0x0A,0x15,0x0A,0x15,0x0A};void delay(unsigned int i){while(--i);}void Read_busy()
//忙檢測,DB7為1則busy,不能進(jìn)行讀寫操作 ;每次讀寫前應(yīng)"讀忙"檢測{P0=0x00;RS=0;RW=1;EN=1;while(P0 0x80);EN=0;}void write_LCD_command(unsigned char value)//寫命令函數(shù){Read_busy();RS=0;RW=0; EN=1;P0=value;delay(100);EN=0;}void write_LCD_data(unsigned char value)//寫命令函數(shù){Read_busy();RS=1;RW=0; EN=1;P0=value;delay(100);EN=0;}void init_LCD(){write_LCD_command(0x38);//在這里加延時delay(5);write_LCD_command(0x0c);//開顯示,不顯示光標(biāo),且不閃爍//在這里加延時delay(5); write_LCD_command(0x06);//每次寫入數(shù)據(jù)后地址指針加1 //在這里加延時delay(5);write_LCD_command(0x01);//清屏}void main(){unsigned char num;init_LCD();write_LCD_command(0x40);
//對CGRAM第一個自定義字符操作,若是第二個則為0x48,其次類推(上面有對頂?shù)年P(guān)系)for(num=0;num8;num++){write_LCD_data(table[num]);}write_LCD_command(0x80); //規(guī)定顯示在第一行第一個位置write_LCD_data(0x00); //顯示第一個自定義字符 (0x40對應(yīng)第一個:0x00)while(1);}/*到這里程序結(jié)束了,第一次寫可能說的不夠清晰,有不懂的可以留言給我^_^*/
評論