📄 untitled.c
字号:
#include <pic.h>
unsigned int sync;
const timing[4]={0x16,0x14,0x17,0x11};
bit down,startplus,syncplus;
union
{
struct
{
unsigned b0:1;
unsigned b1:1;
unsigned b2:1;
unsigned b3:1;
unsigned b4:1;
unsigned b5:1;
unsigned b6:1;
unsigned b7:1;
}bits;
unsigned char word;
}signal,count;
void scankey(void);
void interrupt ISR(void)
{
//RD0=!RD0;
if(T0IE & T0IF)
{
//RBIF=0;
INTF=0;
T0IF=0;
RC3=!RC3;
// RBIE=0;
INTE=0;
T0IF=0;
T0IF=0;
TMR0=0x86;
RC4=1;
if(!syncplus){++sync;RC1=0;if(sync>12){syncplus=1;sync=0;RC1=1;}}
if(syncplus && (!startplus)){++sync;}
if(sync>500){startplus=1;sync=0;RC1=0;}//sync>976
if(startplus)
{
if(count.bits.b1){RC0=signal.bits.b4;}
if(count.bits.b2){RC0=signal.bits.b3;}
if(count.bits.b3){RC0=signal.bits.b2;}
if(count.bits.b4){RC0=signal.bits.b1;}
if(count.bits.b5){RC0=signal.bits.b0;}
if(count.bits.b6){RC0=1;}
if(count.bits.b7)
{count.word=1;syncplus=0;startplus=0;sync=0;RC1=1;RC0=1;}
count.word<<=1;
if(!T0IE){count.word=1;}
}
RC4=0;
}
}
void main(void)
{
//
down=0;
syncplus=0;
startplus=0;
TRISC=0;
PORTC=0;
RAPU=0;
INTCON=0;
WPUA=0X37;
PORTA=0;
CMCON=0X07;
ANSEL=0;
TRISA=0xff;
PORTA=0XFF;
T0IF=0;
T0IE=0;
OPTION=0x02;
TMR0=0x86;
count.word=0x01;
GIE=1;
while(1)
{
scankey();
RC5=down;
}
}
void scankey(void)
{
static bit other1,other2,other3,other4;
if(!down)
{
down=1;
other1=RA1 & RA2 & RA4;
other2=RA0 & RA4 & RA2;
other3=RA0 & RA1 & RA4;
other4=RA0 & RA1 & RA2;
if((!RA0)&&(other1)){signal.word=0x16;T0IF=0;T0IE=1;}
if((!RA1)&&(other2)){signal.word=0x14;T0IF=0;T0IE=1;}
if((!RA2)&&(other3)){signal.word=0x17;T0IF=0;T0IE=1;}
if((!RA4)&&(other4)){signal.word=0x11;T0IF=0;T0IE=1;}
RC0=1;
count.word=0x01;
}
if(RA0 & RA1 & RA2 & RA4)
{
signal.word=0;
down=0;count.word=0x01;
sync=0;syncplus=0;startplus=0;
T0IF=0;
T0IE=0;
RC1=1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -