数码管无法正确显示单片机的红外线低电平时间
时间:10-02
整理:3721RD
点击:
用STC12C2052单片机和红外接收器接受遥控器发过来的起始码低电平时间
#include "reg52.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
uint r_Flag=0;
sbit IR_RE=P3^2;
sbit ge=P3^7;
sbit shi=P3^5;
sbit bai=P3^4;
sbit qian=P3^3;
uint buf[4]={0,0,0,0};
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90};
uint k;
uint T_low=0;
void display(uint x)
{
uchar ge1,shi1,bai1,qian1;
ge1=x%10;
shi1=(x%100-ge1)/10;
bai1=(x%1000-ge1-shi1*10)/100;
qian1=(x-ge1-shi1*10-bai1*100)/1000;
ge=0;
P1=table[ge1];
delay(10);
ge=1;
shi=0;
P1=table[shi1];
delay(10);
shi=1;
bai=0;
P1=table[bai1];
delay(10);
bai=1;
qian=0;
P1=table[qian1];
delay(10);
qian=1;
}
void main()
{
uint t;
timer0_init();
while(1)
{
if(IR_RE==0)
{
TR0=1;
while(IR_RE==0);
TR0=0;
t=TH0*256+TL0;
TH0=0;
TL0=0;
if(r_Flag==0)
{T_low=t;}
r_Flag++;
}
display(T_low);
}
}
#include "reg52.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
uint r_Flag=0;
sbit IR_RE=P3^2;
sbit ge=P3^7;
sbit shi=P3^5;
sbit bai=P3^4;
sbit qian=P3^3;
uint buf[4]={0,0,0,0};
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90};
uint k;
uint T_low=0;
void display(uint x)
{
uchar ge1,shi1,bai1,qian1;
ge1=x%10;
shi1=(x%100-ge1)/10;
bai1=(x%1000-ge1-shi1*10)/100;
qian1=(x-ge1-shi1*10-bai1*100)/1000;
ge=0;
P1=table[ge1];
delay(10);
ge=1;
shi=0;
P1=table[shi1];
delay(10);
shi=1;
bai=0;
P1=table[bai1];
delay(10);
bai=1;
qian=0;
P1=table[qian1];
delay(10);
qian=1;
}
void main()
{
uint t;
timer0_init();
while(1)
{
if(IR_RE==0)
{
TR0=1;
while(IR_RE==0);
TR0=0;
t=TH0*256+TL0;
TH0=0;
TL0=0;
if(r_Flag==0)
{T_low=t;}
r_Flag++;
}
display(T_low);
}
}