|
求求各位大神帮我看看这个程序错哪了,怎么出来的信号不对的,我发的是900us的起始码,1200us的逻辑0码,600us的逻辑1码,还有数据码和数据反码,最后是600us结束码
#include
uint8 key_data=0;
eeprom uint8 ee_temp=0xFF;
void timer_init(void) //定时器初始化
{
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x01;
TCNT0=0xd1;
OCR0A=0x00;
OCR0B=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x02;
}
void main (void)
{
DDRB=0xef;
PORTB=0x0f;
PINB=0x10;
timer_init();
#asm("sei")
while (1){
if(key_data >=0x01){
key_data =0;
RF_S1=0;
delay_ms(500);
RF_S1=1;
delay_ms(500);
}
}
}
interrupt [TIM0_OVF] void Timer0_ovf(void)
{
// interrupt time 50us
static uint8 flag = 0; // 标志位: 是否读到起始位
static uint8 read_cnt = 0;//低电平计数
static uint8 read_high_cnt = 0,data = 0,count=0;//高电平计数,数据,位码个数
TCNT0=0xd1;//50um中断
if (flag == 0){
if (IR_Signed == 0){
read_cnt++;
}else {
if (read_cnt >=17){
// 读到低电平大于17次(900us 至少读到17次)
flag = 1;
}
read_cnt = 0;
}
}else {
if(IR_Signed == 0){
read_high_cnt = 0;
read_cnt++;
}else{
read_high_cnt++;
if ((read_cnt >=11) && (read_cnt <=13)){
data = (data<<1)+1;
read_cnt = 0;
count++;
}else if ((read_cnt >=23) && (read_cnt <=25)){
data = (data<<1);
read_cnt = 0;
count++;
}
if (count==6){
read_high_cnt = 0;
// 响应按键
key_data = data;
data = 0;
count=0;
flag = 0;
}
}
}
}
|
|