写一个51单片机lcd1602显示iloveyou的代码
时间: 2023-05-29 12:06:31 浏览: 183
51单片机lcd1602模块代码
下面是51单片机LCD1602显示iloveyou的代码:
#include <reg51.h>
#define LCD_DATA P0
sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;
void delay(unsigned int i)
{
while(i--);
}
void lcd_write_cmd(unsigned char cmd)
{
RS = 0;
RW = 0;
EN = 1;
LCD_DATA = cmd;
delay(100);
EN = 0;
}
void lcd_write_data(unsigned char dat)
{
RS = 1;
RW = 0;
EN = 1;
LCD_DATA = dat;
delay(100);
EN = 0;
}
void lcd_init()
{
lcd_write_cmd(0x38);
lcd_write_cmd(0x0c);
lcd_write_cmd(0x06);
lcd_write_cmd(0x01);
}
void main()
{
lcd_init();
lcd_write_data('i');
lcd_write_data('l');
lcd_write_data('o');
lcd_write_data('v');
lcd_write_data('e');
lcd_write_data('y');
lcd_write_data('o');
lcd_write_data('u');
}
阅读全文