请高手指点: 学习码630解码1527,1527遥控两个键,请问程序有什么问题, 编译成功,但 写不进芯片去
#include <pic.h>
#include <pic16630.h>
__CONFIG( WDTDIS & PWRTEN &INTOSCIO & MCLRDIS);
#define uchar unsigned char
#define uint unsigned int
#define rfin RA2 //11脚
#define fmq RC0 //10脚蜂鸣器
#define laba RC2 //8脚报警
#define chufa RC3 //7 脚传感踩下为低
#define unlock RC5 //5脚 解锁
#define ceshi RC4 //6脚
#define led RC2 //8脚
#define study RC1 //9脚学习按钮
uint l1, m1,n1;
uchar tlow;
uchar thigh;
uchar recnt; //接收位数24位
uchar keygeshu;//键数
uchar tmp1; //键按下时间变量
uchar tmp2; //学习按下时间变量
uchar tmp3; //临时
uchar ks11; //开锁码1
uchar ks12;
uchar ks13;
uchar js11; //加锁码1
uchar js12;
uchar js13;
uchar ma01; //学习码变量
uchar ma02;
uchar ma03;
uchar ma11; //上次学习码变量
uchar ma12;
uchar ma13;
uchar ma21; //学习码变量
uchar ma22;
uchar ma23;
uchar tmp,tmp0;
const uchar Cs@0x3ff;
bit tongbutou; //同步头接收成功标志
bit rfok;
bit rf_er;//接收失败
bit signth; //信号高低标志
bit study1;//是否学习状态标志
bit cdj; //踩下标志
bit press;//有键按下
bit anxia;//有键持续按下
bit xuexi;//学习时间标志
bit diffkey; //不同的键
bit kaisuo;
bit jiasuo;
/*
void delay1(void)
{
for(tmp3=0;tmp3<100;tmp3++)
{}
}*/
void delay2(n1)
{
for(l1=0;l1<100;l1++)
{
for(m1=0;m1<n1;m1++)
{}
}
}
void delay1(void)
{
asm("nop");
asm("nop");
asm("nop");
asm("nop");
}
void interrupt ISR (void)
{
CLRWDT();
if(T0IF==1) //time0 100us中断
{
T0IF=0;
TMR0=179;
if(rfin==1)
{
if(signth==1)//由低到高开始接收
{
if(tlow>thigh)//判断是否低电平
{
if(tlow>5&&tlow<19&&thigh>2&&thigh<9)
{
recnt++;//是低电平
ma01<<=1;//移动一位
}
else
{//接收失败
rf_er=1;
}
}
else if(tlow<thigh) //判断是否低高电平
{
if(tlow>2&&tlow<9&&thigh>5&&thigh<19)//
{
recnt++;//是高电平
ma01<<=1;//移动一位
ma01++;
}
else
{
rf_er=1;
}
}
else if(tlow==thigh)
{
rf_er=1;
}
if(rf_er==1)
{
tongbutou=0;//接收失败
recnt=0;
rfok=0;
}
else
{
if(recnt==8){ma03=ma01;}
else if(recnt==16){ma02=ma01;}
}
if(recnt==24)
{
tlow=0;
thigh=0;
recnt=0;
tongbutou=0;
if(ma01==ma11 && ma02==ma12 && ma03==ma13)
{
rfok=1; //接收成功
ma11=0;ma12=0;ma13=0;
if(ma01!=ma21 || ma02!=ma22 || ma03!=ma23)
{
diffkey=1;
press=1;
anxia=0;
tmp2=0;
ma21=ma01;ma22=ma02;ma23=ma03;
}
else
{
diffkey=0;
anxia=1;
tmp2=0;
}
}
else
{
ma11=ma01;ma12=ma02;ma13=ma03;
}
}
thigh=0; //signth==1函数
}
else if(tlow>30&&tlow<180) //判断同步头判断低与if(signth==1)并行
{
tongbutou=1; //检测到正确的同步头
recnt=0; //接收位数,清除0
}
thigh++;
tlow=0;
signth=0;
rf_er=0;//接收失败标志
}
else //与if(rfin==1)接收低并行
{ //输入端口为低电
tlow++;
if(tongbutou==1)//开始接收标志
{
signth=1;
}
else
{
thigh=0;
}
}
}
if(TMR1IF==1)
{
TMR1IF=0;//清中断标志位
TMR1H=0xcf;//初值53035
TMR1L=0x2b;
if(xuexi)//
{
++tmp2;
if(tmp2==25)
{
tmp2=0;
if(!study)
{
xuexi=0;
study1=1; //学习状态标志
led=1;
keygeshu=0;
ma23=ma22=ma21=0;
}
}
}
if(anxia)
{
press=0;
++tmp1;
if(tmp1==5)
{
tmp1=0;
anxia=0;
press=1;
}
}
}
}
void main(void)
{
OSCCAL=Cs;
PORTC=0x20;
PORTA=0x00;
CMCON=0x07;
TRISA=0x07;
TRISC=0x0a;
WPUA=0x04;
IOCA=0x04;
OPTION=0x0e;
unlock=0;
TMR0=179;
INTCON=0xe0; //使能timer0;
T0IE=1; //使能timer0;
if(eeprom_read(1)!=1)
{
// delay1();
eeprom_write(1,1);
delay1();
eeprom_write(2,0); //存开锁码
delay1();
eeprom_write(3,0);
delay1();
eeprom_write(4,0);
delay1();
eeprom_write(5,0); //存加锁码
delay1();
eeprom_write(6,0);
delay1();
eeprom_write(7,0);delay1();
}
ks11=eeprom_read(2);
//delay1();
ks12=eeprom_read(3);
//delay1();
ks13=eeprom_read(4);
//delay1();
js11=eeprom_read(5);
//delay1();
js12=eeprom_read(6);
//delay1();
js13=eeprom_read(7);
delay1();
if(eeprom_read(6)!=0) {ceshi=1;}
TMR1H=0xcf;
TMR1L=0x2b; //time1 0.025s*8预分频定时
T1CON=0x30; //关闭Timer1 设置1:8预分频
PIE1=0x01; //使能time1定时中断
TMR1IF=0;
TMR1ON=1; //启动timer1
while(1)
{
if(rfok)
{
rfok=0;
if(!study1)
{
if(press)
{
if(ks11==ma01 && ks12==ma02 && ks13==ma03)
{
unlock=1;
kaisuo=1;
jiasuo=0;
fmq=1; delay2(100); fmq=0; delay2(100);
fmq=1; delay2(100); fmq=0; delay2(100);
}
else if(js11==ma01 && js12==ma02 && js13==ma03)
{
unlock=0;
kaisuo=0;
jiasuo=1;
fmq=1; delay2(100); delay2(100); delay2(100);
fmq=0;
}
}
}
else
{
if (diffkey)
{
++keygeshu;
if(keygeshu==1)
{
eeprom_write(2,ma01); //存开锁码
delay1();
eeprom_write(3,ma02);
delay1();
eeprom_write(4,ma03);
delay1();
//save();
}
else if(keygeshu==2)
{
eeprom_write(5,ma01); //存加锁码
delay1();
eeprom_write(6,ma02);
delay1();
eeprom_write(7,ma03);
delay1();
// save1();
keygeshu=0;
led=0;
study1=0;
}
//ceshi=1;
//anxia=1;
//press=1;
}
}
}
if(!study)//学习
{
if(!study1 && !xuexi)
{
xuexi=1;
tmp2=0;
}
}
else
{
xuexi=0;
tmp2=0;
led=0;
study1=0;
keygeshu=0;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>