#include "reg52.h"
#include "intrins.h"
#define databuffer P0
sbit RS= P1^0;
sbit RW= P1^1;
sbit E = P1^4;
void Delay15ms() //@11.0592MHz
{
unsigned char i, j;
i = 27;
j = 226;
do
{
while (--j);
} while (--i);
}
void Delay5ms() //@11.0592MHz
{
unsigned char i, j;
i = 9;
j = 244;
do
{
while (--j);
} while (--i);
}
void check_busy()
{
char tmp = 0x80;
databuffer = 0x80;
while(tmp & 0x80)
{
RS = 0;
RW = 1;
E = 0;
_nop_();
E = 1;
_nop_();
tmp=databuffer;
E = 0;
_nop_();
}
}
void Write_cmd_func(char cmd)
{
check_busy();
RS = 0;
RW = 0;
E = 0;
_nop_();
databuffer = cmd;
_nop_();
E = 1;
_nop_();
E = 0;
_nop_();
}
void Write_data_func(char datashow)
{
check_busy();
RS = 1;
RW = 0;
E = 0;
_nop_();
databuffer = datashow;
_nop_();
E = 1;
_nop_();
E = 0;
_nop_();
}
void LCD1602_INIT()
{
Delay15ms();
Write_cmd_func(0x38);
Delay5ms();
Write_cmd_func(0x38);
Write_cmd_func(0x08);
Write_cmd_func(0x01);
Write_cmd_func(0x06);
Write_cmd_func(0x0c);
}
void main()
{
char position = 0x80+0x05;
char datashow = 'L';
LCD1602_INIT();
Write_cmd_func(position);
Write_data_func(datashow);
}
使用LCD1602显示字母“L”
最新推荐文章于 2023-09-10 15:59:58 发布