1. 程式人生 > >基於51微控制器的LCD液晶屏

基於51微控制器的LCD液晶屏

```
#include"reg52.h"

sbit lcden=P1^0;
sbit lcdrs=P1^1;
sbit lcdrw=P1^2;

void delay_ms(unsigned int t);
void lcd_write_com(unsigned char com);
void lcd_write_dat(unsigned char dat);
void init_1602lcd(void);

unsigned char code lcd1[]="I LOVE SHUANG ZU";
unsigned char code lcd2[]="TEL:17337112944 QQ:810965811"
; /************主函式**************/ void main() { unsigned char x,y; init_1602lcd(); lcd_write_com(0x80+0x00); for(x=0;x<36;x++) { lcd_write_dat(lcd1[x]); } delay_ms(5); lcd_write_com(0x80+0x40); for(y=0;y<29;y++) { lcd_write_dat(lcd2[y]); } while
(1) { lcd_write_com(0x18); delay_ms(500); } } void delay_ms(unsigned int t) //延時函式 { unsigned int x,y; for(x=t;x>0;x--) { for(y=110;y>0;y--) { } } } void lcd_write_com(unsigned
char com) //寫命令函式 { lcdrs=0; P0=com; delay_ms(2); lcden=1; delay_ms(2); lcden=0; } void lcd_write_dat(unsigned char dat) //寫資料函式 { lcdrs=1; P0=dat; delay_ms(2); lcden=1; delay_ms(2); lcden=0; } void init_16021cd() //1602液晶初始化函式 { lcden=0; lcdrs=0; lcdrw=0; lcd_write_com(0x38); lcd_write_com(0x0f); lcd_write_com(0x06); lcd_write_com(0x01); delay_ms(5); }