新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)教程之51單片機(jī)紅外搖控,并在LCD1602上顯示

單片機(jī)教程之51單片機(jī)紅外搖控,并在LCD1602上顯示

作者: 時(shí)間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
#include

#include
typedef unsigned int uint;
typedefunsigned char uchar;

本文引用地址:http://m.butianyuan.cn/article/201611/322564.htm

sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_EN=P2^2;


sbit IRINPUT=P3^2;

uchar code Display_LINE0[]={"VALUE FROM IR:"};
ucharDisplay_LINE1[]={"IR CODE:H"};
uchar IR_Input_Buffer[8];
uchar Display_Buffer[3]={0x00,0x00};//數(shù)碼管顯示緩沖






void _delay_us(uint x)
{
uchar i;
while(x--)
for(i=0;i<13;i++);
}

void _delay_ms(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i=0;i<120;i++);
}
}

uchar LCD_Busy(void)//測忙
{
uchar LCD_Status;//返回值變量
LCD_RS=0;//讀取狀態(tài)
LCD_RW=1;
LCD_EN=1;
_nop_();_nop_();_nop_();_nop_();
LCD_Status=P0;
LCD_EN=0;
return LCD_Status;
}

void LCD_Write_Command(uchar cmd)//寫指令
{
while((LCD_Busy()&0x80)==0x80);//測忙
LCD_RS=0;//
LCD_RW=0;
LCD_EN=0;
P0=cmd;
LCD_EN=1;
_nop_();_nop_();
LCD_EN=0;
_nop_();_nop_();
}

void LCD_Write_Data(uchar dat)//寫數(shù)據(jù)
{
while((LCD_Busy()&0x80)==0x80);
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
P0=dat;
LCD_EN=1;
_nop_();_nop_();
LCD_EN=0;
_nop_();_nop_();
}

void Init_LCD(void)//液晶初始化
{
_delay_ms(15);
LCD_Write_Command(0x38);
_delay_ms(5);
LCD_Write_Command(0x06);
_delay_ms(5);
LCD_Write_Command(0x0c);
_delay_ms(5);
LCD_Write_Command(0x01);
_delay_ms(5);

}

void LCD_POS(uchar pos)//字符顯示位置
{
LCD_Write_Command(0x80|pos);
}

void Show_String(uchar *str)//顯示字符串
{
while(*str!=