📄 text1.c
字号:
#include "reg51.h"
#include "intrins.h"
unsigned char dis1[]="Hello";
unsigned char dis2[]="Thanks";
sbit EN_LCD=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_RS=P2^2;
sbit LCD_flat=P1^7;
void LCD_delay(void)
{
unsigned char i=248;
while(i--)
{ _nop_();
_nop_();
_nop_();
}
}
void until_notbusy(void)
{
while(1)
{ LCD_RS=0;
LCD_RW=1;
EN_LCD=1;
_nop_();
_nop_();
_nop_();
_nop_();
if(!LCD_flat) break;
EN_LCD=0;
}
}
void wr_con(unsigned char com)
{
until_notbusy();
LCD_RS=0;
LCD_RW=0;
_nop_();
_nop_();
P1=com;
_nop_();
_nop_();
_nop_();
EN_LCD=1;
_nop_();
_nop_();
_nop_();
EN_LCD=0;
}
void wr_dat(unsigned char dat)
{
until_notbusy();
LCD_RS=1;
LCD_RW=0;
// EN_LCD=0;
_nop_();
_nop_();
P1=dat;
_nop_();
_nop_();
_nop_();
EN_LCD=1;
_nop_();
_nop_();
_nop_();
EN_LCD=0;
}
void set(unsigned char add)
{
wr_con(0x80|add);
}
void lcd_init(void)
{
wr_con(0x38);
LCD_delay();
wr_con(0x0c);
LCD_delay();
wr_con(0x06);
LCD_delay();
wr_con(0x01);
LCD_delay();
}
void main(void)
{
unsigned char i;
lcd_init();
for(i=10;i>0;i--)
LCD_delay();
{
set(0x00);
for(i=0;dis1[i]!='\0';i++)
wr_dat(dis1[i]);
set(0x40);
for(i=0;dis2[i]!='\0';i++)
wr_dat(dis2[i]);
while(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -