微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > king沙滩的板子一个程序实现不了液晶显示红外,大神看下

king沙滩的板子一个程序实现不了液晶显示红外,大神看下

时间:10-02 整理:3721RD 点击:
用uart可以显示在串口助手上
/*
* 红外接收数据,查询方式,液晶显示
*
* 晶振:11.0592M
*/
#include <reg52.h>
//#include<intrins.h>
typedef unsigned char uint8;
sbit Ir_Pin = P3^3;
sbit RS = P1^0 ;
sbit RW = P1^1 ;
sbit EN = P1^5 ;
sbit BUSY = P0^7;
uint8 Ir_Buf[4]; //用于保存解码结果

/**
* 等待繁忙标志
*/
void wait(void)
{
        P0 = 0xFF;
       
        do
        {
                RS = 0;
                RW = 1;
                EN = 0;
                EN = 1;
        }while (BUSY == 1);
        EN = 0;
}
/**
* 写数据
*/
void w_dat(uint8 dat)
{
        wait();
        EN = 0;
        P0 = dat;
        RS = 1;
        RW = 0;
        EN = 1;
        EN = 0;
}
/**
* 写命令
*/
void w_cmd(uint8 cmd)
{
        wait();
        EN = 0;
        P0 = cmd;
        RS = 0;
        RW = 0;
        EN = 1;
        EN = 0;
}
/**
* 初始化1602
*/
void Init_LCD1602(void)
{
        w_cmd(0x38);  // 16*2显示,5*7点阵,8位数据接口
        w_cmd(0x0C);  // 显示器开、光标开、光标允许闪烁
        w_cmd(0x06);  // 文字不动,光标自动右移
        w_cmd(0x01);  // 清屏
}


/*
* 获取低电平时间
*/
unsigned int Ir_Get_Low()
{
        TL0 = 0;
        TH0 = 0;
        TR0 = 1;
        while (!Ir_Pin && (TH0&0x80)==0);  
        TR0 = 0;           
        return (TH0 * 256 + TL0);
}
/*
* 获取高电平时间
*/
unsigned int Ir_Get_High()
{
        TL0 = 0;
        TH0 = 0;
        TR0 = 1;
        while (Ir_Pin && (TH0&0x80)==0);
        TR0 = 0;
        return (TH0 * 256 + TL0);
}

main()
{
        unsigned int temp;
        char i,j;
        Init_LCD1602();
       
        while (1)
        {
start:
                while (Ir_Pin);
                temp = Ir_Get_Low();
                if ((temp < 7833) || (temp > 8755))  //引导脉冲低电平8500~9500us
                        goto start;
                temp = Ir_Get_High();
                if ((temp < 3686) || (temp > 4608))  //引导脉冲高电平4000~5000us
                        goto start;
                for (i=0; i<4; i++) //4个字节
                {
                        for (j=0; j<8; j++) //每个字节8位
                        {
                                temp = Ir_Get_Low();
                                if ((temp < 184) || (temp > 737)) //200~800us
                                        goto start;
                                temp = Ir_Get_High();
                                if ((temp < 184) || (temp > 1843)) //200~2000us
                                        goto start;
                                Ir_Buf[i] >>= 1;
                                if (temp > 1032) //1120us
                                        Ir_Buf[i] |= 0x80;
                        }
                }
                 
       
            w_cmd(0xc0);
                w_dat(Ir_Buf[0]/100%10+'0');
                w_dat(Ir_Buf[0]/10%10+'0');
                w_dat(Ir_Buf[0]%10+'0');
                w_dat('\32');
                w_dat(Ir_Buf[1]/100%10+'0');
                w_dat(Ir_Buf[1]/10%10+'0');
                w_dat(Ir_Buf[1]%10+'0');
                w_dat('\32');
                w_dat(Ir_Buf[2]/100%10+'0');
                w_dat(Ir_Buf[2]/10%10+'0');
                w_dat(Ir_Buf[2]%10+'0');
                w_dat('\32');
                w_dat(Ir_Buf[3]/100%10+'0');
                w_dat(Ir_Buf[3]/10%10+'0');
                w_dat(Ir_Buf[3]%10+'0');
//                w_dat('\32');
//                w_cmd(0xc0);
               
        }
}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top