📄 1602.c
字号:
#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)//使用延时函数代替busy check 该延时函数 使用for语句不能作为精确延时通用函数
{
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)//长延时函数,同样不能作为精确延时的用函数
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<1140;j++);
}
void LCD_init(void)//初始化函数 具体见 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 ");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -