?? 1602.c
字號(hào):
#include <reg51.h>
#define LCDIO P0
sbit LCD1602_RS=P1^5;
sbit LCD1602_RW=P1^4;
sbit LCD1602_EN=P1^3;
void LCD_delay(void)//使用延時(shí)函數(shù)代替busy check 該延時(shí)函數(shù) 使用for語(yǔ)句不能作為精確延時(shí)通用函數(shù)
{
unsigned char i;
for(i=40;i>0;i--)
;
}
void LCD_en_command(unsigned char command)
{
LCDIO=command;
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_delay();
LCD1602_EN=1;
}
void LCD_en_dat(unsigned char dat)
{
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
LCD_delay();
LCDIO=dat;
LCD1602_EN=1;
}
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == 0)
address = 0x80 + x;
else
address = 0xC0 + x;
LCD_en_command(address);
}
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCDIO=*s;
LCD_en_dat(*s);
s ++;
}
}
void delay_nms(unsigned int n)//長(zhǎng)延時(shí)函數(shù),同樣不能作為精確延時(shí)的用函數(shù)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<1140;j++);
}
void LCD_init(void)//初始化函數(shù) 具體見(jiàn) hd44780的命令詳解
{
LCD_en_command(0x01);
delay_nms(5);
LCD_en_command(0x38);
delay_nms(5);
LCD_en_command(0x38);
delay_nms(5);
LCD_en_command(0x38);
delay_nms(5);
LCD_en_command(0xC0);
delay_nms(5);
LCD_en_command(0x80);
delay_nms(5);
LCD_en_command(0x01);
delay_nms(5);
}
void main(void)
{
LCD_init();
while(1)
{
//CLEARSCREEN;
delay_nms(2);
LCD_write_string(0,0," bg8wj");
LCD_write_string(0,1," cdrom contral ");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -