//*****************************************************
// verify 40 SN if there is a same CF=1,else CF=0
//*****************************************************
bit Verify_120(void)
{
unsigned char i,addr,tmp;
addr=0;
i=40;
do
{
tmp=EEPROM_READ(addr++);
if(qk_cnt!=0) // recieve a qk signal
{
if((tmp&0x01)==0)
{addr+=2;continue;};// memory is dk
if(((tmp&0x80)==0)||((CSR0&0x80)==0))
{
if(((tmp^CSR0)&0xf0)!=0)
{addr=addr+2;continue;};
}
}
else //recieve a dk signal
{
if((tmp&0x01)==1)
{addr=addr+2;continue;};//memory is qk
if(((tmp^CSR0)&0xf0)!=0)
{addr=addr+2;continue;};
}
tmp=EEPROM_READ(addr++);
if((tmp^CSR1)!=0)
{addr+=1;continue;}
tmp=EEPROM_READ(addr++);
if((tmp^CSR2)!=0)
{addr=addr+0;continue;}
return(1);
}
while(--i!=0);
return(0);
}
bit read_s_port(unsigned char cnt)
{
unsigned char i;
TRISA2=1;
while(1)
{
rrr:
i=cnt;
if(RA2)
{
do
{
if(RA2==0)
goto rrr;
}
while(--i!=0);
RA2=1;
TRISA2=0;
return 1;
}
else
{
do
{
if(RA2==1)
goto rrr;
}
while(--i!=0);
RA2=1;
TRISA2=0;
return 0;
}
}
}
void do_up(void)
{
t0_cnt=3662;
if(led_down==1)
{
led_down=0;
delay_1s_stop();
if(CARRY==0)
{
work_led=w_on;
led_up=1;
}
}
else
{
work_led=w_on;
led_up=1;
}
}
void do_down(void)
{
t0_cnt=3662;
if(led_up==1)
{
led_up=0;
delay_1s_stop();
if(CARRY==0)
{
work_led=w_on;
led_down=1;
}
}
else
{
work_led=w_on;
led_down=1;
}
}
void do_stop(void)
{
work_led=w_off;
led_up=0;
led_down=0;
}
main()
{
volatile unsigned char j;
OSCCAL=_READ_OSCCAL_DATA();
init();
led_up=0;
led_down=0;
work_led=w_off;
TRISA2=1;
recieve();
t0_cnt=3662;
while(1)
{
if(T0IF) //0.065536 S
{
T0IF=0;
fan_reg<<=1;
if(fan)
bitset(fan,0);
if(--t0_cnt==0) // 4 minitue
{
work_led=w_off;
t0_cnt=3662;
led_up=0;
led_down=0;
}
}
key_tmp=PORTC&0x038;
j=6;
do
{
if((PORTC&0x038)!=key_tmp)
{
j=6;
continue;
}
}
while(--j!=0);
recieve();
if(CARRY==1)
{
Verify_120();
if((CARRY==1)||(key_tmp&0x38)!=0x38)
{
if((key_stop==0)||(CSR0&0xf)==4)
{
do_stop();
}
if((key_up==0)||(CSR0&0xf)==8)
{
if(fan_reg==0)
do_up();
else
do_down();
}
if((key_down==0)||(CSR0&0xf)==1)
{
if(fan_reg==0)
do_down();
else
do_up();
}
}
}
if(RA2==1)
{
work_led=w_off;
led_up=0;
led_down=0;
TRISA2=0;
RA2=1;
TMR0=0;
learn_cnt=153;
while(1)
{
recieve();
if(CARRY==1)
{
if((CSR0&0xf)==2)
{
Write_a_sn();
learn_cnt=5;
do
{
RA2=0;
delay_1ms(250);
RA2=1;
delay_1ms(250);
}
while(--learn_cnt!=0);
TRISA2=1;
break;
}
}
if(!T0IF)
continue;
T0IF=0;
if(--learn_cnt==0)
{
TRISA2=1; //10 second reach
break;
}
TRISA2=1;
if(read_s_port(10)==1)
{
if(++l_cnt2==32)
{
TRISA2=0;
RA2=0;
Erase_120();
delay_1ms(250);
delay_1ms(250);
delay_1ms(250);
delay_1ms(250);
TRISA2=1;
break;
}
}
else
{
if(l_cnt2!=0)
l_cnt2--;
}
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>