?? cc1000main.c
字號:
//===========================================================
//= CC1000 Demo board Hand-set =
//= MCU: PIC16F72 =
//= Ver: 1.0 =
//= Designed by: Figo =
//= Start Date: 2005-1-12 =
//=---------------------------------------------------------=
//= Revision History =
//= V1.0: Orginal Version =
//===========================================================
#include <pic.h>
#include "CC1000Main.h"
//===========================================================
void main(void)
{
SysInit();
b_RxGo = NO;
b_PreFound = NO;
PreCtr = 0;
Rxbuf1 = 0;
b_UnlockAvg = YES;
GIE = ON;
while(1)
{
if (b_UnlockAvg == YES)
{
b_UnlockAvg = NO;
GIE = NO;
AverageFreeRunCC1000();
INTF = NO;
GIE = ON;
}
if (b_LockAvg == YES)
{
b_LockAvg = NO;
GIE = NO;
AverageManualLockCC1000();
INTF = NO;
GIE = ON;
}
if (TMR2IF == YES)
{
TMR2IF = NO;
Readkey();
Keyproc();
if (FlashCtr!=0)
{
o_led2 = LOW;
FlashCtr--;
}
else
{
o_led2 = HIGH;
}
}
}
}
//===========================================================
//= =
//===========================================================
static void interrupt int_isr(void)
{
Tmr1b = (unsigned int)TMR1H<<8 | (unsigned int)TMR1L;
TMR1H = 0;
TMR1L = 0;
INTF = NO;
if ((b_UART==YES && b_Tstbase==NO) || (b_Tstbase==YES && b_IsTx==NO))
{
if (i_clock == HIGH) {OPTION = 0B00001111;}
else {OPTION = 0B01001111;}
if (b_RxGo == YES)
{
if (Tmr1b<1300 && Tmr1b>250)
{
if (i_clock == HIGH)
{
if (Tmr1bb > Tmr1b) CARRY=0;
else CARRY=1;
asm("rlf _Rxbuf8,F");asm("rlf _Rxbuf7,F");asm("rlf _Rxbuf6,F");asm("rlf _Rxbuf5,F");
asm("rlf _Rxbuf4,F");asm("rlf _Rxbuf3,F");asm("rlf _Rxbuf2,F");asm("rlf _Rxbuf1,F");
if (++BitCtr >= 64)
{
if ((Rxbuf1^Rxbuf2^Rxbuf3^Rxbuf4^Rxbuf5^Rxbuf6^Rxbuf7^Rxbuf8) == 0)
{
if (!tstbit(Rxbuf7,7)) {b_Answer=YES;}
clrbit(Rxbuf7,7);
FlashCtr=25;
PORTC=Digit09[Rxbuf7];
}
b_RxGo=NO;b_PreFound=NO;PreCtr=0;b_UnlockAvg=YES;
}
}
Tmr1bb = Tmr1b;
}
else {b_RxGo=NO;b_PreFound=NO;PreCtr=0;b_UnlockAvg=YES;}
}
else
{
if (b_PreFound == YES)
{
if (i_clock == HIGH)
{
if (Tmr1b > 3000 && Tmr1b < 5000) {b_RxGo=YES;BitCtr=0;}
if (++PreCtr > 8) {b_PreFound=NO;PreCtr=0;b_UnlockAvg=YES;}
}
}
else
{
if (Tmr1b > 250 && Tmr1b < 550)
{
if (++PreCtr > 11) {b_PreFound=YES;b_LockAvg=YES;PreCtr=0;}
}
else PreCtr = 0;
}
}
}
else
{
if (b_IsTx == YES)
{
if (b_TxGo == YES)
{
if (b_Tstbase==NO)
{
asm("rlf _Txbuf8,F");
asm("rlf _Txbuf7,F");
asm("rlf _Txbuf6,F");
asm("rlf _Txbuf5,F");
asm("rlf _Txbuf4,F");
asm("rlf _Txbuf3,F");
asm("rlf _Txbuf2,F");
asm("rlf _Txbuf1,F");
io_data = CARRY;
if (--BitCtr == 0) b_TxGo = NO;
}
else
{
if (b_Txtrue==NO)
{
notbit(PORTB,1);
if (++TransCtr >= 32) {b_Txtrue=YES;}
}
else
{
if (b_Headov==NO)
{
io_data = LOW;
if (++TransCtr>(32+10)) {b_Headov=YES; TransCtr=0;}
}
else
{
if (++TransCtr == 1) io_data = HIGH;
else if (TransCtr == 2)
{
asm("rlf _Txbuf8,F");
asm("rlf _Txbuf7,F");
asm("rlf _Txbuf6,F");
asm("rlf _Txbuf5,F");
asm("rlf _Txbuf4,F");
asm("rlf _Txbuf3,F");
asm("rlf _Txbuf2,F");
asm("rlf _Txbuf1,F");
io_data = !CARRY;
}
else
{
TransCtr = 0;
io_data = LOW;
if (--BitCtr == 0) b_TxGo = NO;
}
}
}
}
}
}
else
{
if (b_RxGo == YES)
{
CARRY = io_data;
asm("rlf _Rxbuf1,F");
if (++BitCtr == 8)
{
BitCtr = 0;
if (b_IdOk == YES)
{
if (b_Checksum == YES)
{
if ((Rxbuf2^Rxbuf1)==0xFF)
{
if (!tstbit(Rxbuf2,7)) {b_Answer=YES;}
clrbit(Rxbuf2,7);
FlashCtr=25;
PORTC=Digit09[Rxbuf2];
}
b_RxGo = NO;
b_PreFound = NO;
PreCtr = 0;
Rxbuf1 = 0;
b_IdOk = NO;
b_UnlockAvg = YES;
}
else
{
b_Checksum = YES;
Rxbuf2 = Rxbuf1;
}
}
else
{
if (Rxbuf1 == UI2)
{
b_IdOk = YES;
b_Checksum = NO;
}
else
{
b_RxGo = NO;
b_PreFound = NO;
PreCtr = 0;
Rxbuf1 = 0;
b_IdOk = NO;
b_UnlockAvg = YES;
}
}
}
}
else
{
CARRY = io_data;
asm("rlf _Rxbuf1,F");
if (b_PreFound == YES)
{
if (Rxbuf1 == UI1)
{
b_RxGo = YES;
BitCtr = 0;
}
else if (Rxbuf1!=0x55 && Rxbuf1!=0xAA && PreCtr==0)
{
PreCtr++;
}
if (PreCtr > 0)
{
PreCtr++;
}
if (PreCtr > 10)
{
b_PreFound = NO;
b_UnlockAvg = YES;
}
}
else
{
if (Rxbuf1==0x55 || Rxbuf1==0xAA)
{
if (++PreCtr >= 6)
{
b_PreFound = YES;
b_LockAvg = YES;
PreCtr = 0;
}
}
else
{
PreCtr = 0;
}
}
}
}
}
}
//===========================================================
//= =
//===========================================================
void Keyproc(void)
{
if (b_Kvalid == YES || b_Answer == YES)
{
b_Kvalid = NO;
GIE = OFF;
if (b_UART==YES && b_Tstbase==YES) WriteToCC1000Register(CC1000_MODEM0,0x37);
SetupCC1000TX(TXDL);
Dly1000(1);
while(1)
{
BitCtr = 64+1;
Txbuf1 = 0xAA;
Txbuf2 = 0xAA;
Txbuf3 = 0xAA;
Txbuf4 = 0xAA;
Txbuf5 = UI1;
Txbuf6 = UI2;
Txbuf7 = Txdata;
if (b_Answer == YES)
{
if (b_UART == YES)
{
Txbuf7 = Rxbuf7;
}
else
{
Txbuf7 = Rxbuf2;
}
setbit(Txbuf7,7);
b_Answer = NO;
}
else PORTC=0xFF;
Txbuf8 = ~Txbuf7;
if (b_UART==YES && b_Tstbase==NO) {Txbuf2=0x55;Txbuf4=0x55;}
o_led1 = LOW;
if (b_UART==YES && b_Tstbase==NO)
{
Transmit();
}
else
{
b_IsTx = YES;
b_TxGo = YES;
TransCtr = 0;
io_data = LOW;
b_Txtrue = NO;
b_Headov = NO;
TRISB &= 0B11111101;
OPTION = 0B00001111;
GIE = ON;
while(b_TxGo==YES);
TRISB |= 0B00000010;
GIE = OFF;
OPTION = 0B01001111;
}
o_led1 = HIGH;
break;
/*
Dly1000(250);
Dly1000(250);
if ((PORTB&0xF0) == 0xF0)
{
Dly1000(1);
if ((PORTB&0xF0) == 0xF0) break;
}
*/
}
if (b_UART==YES && b_Tstbase==YES) WriteToCC1000Register(CC1000_MODEM0,0x2B);
SetupCC1000RX(RXDL);
b_IsTx = NO;
b_RxGo = NO;
b_PreFound = NO;
PreCtr = 0;
Rxbuf1 = 0;
b_UnlockAvg = YES;
}
}
void Transmit(void)
{
TRISB &= 0B11111101;
io_data = LOW;
for (Temp1=11*2+1+1 ; ; )
{
notbit(PORTB,1);
CLRWDT();
if (Temp1==1) {Dly1000(3);Dly5(118);}
Dly5(77);
if(--Temp1==0) break;
}
notbit(PORTB,1);
NOP();
for (Temp1=64; ; )
{
Dly5(75);
NOP();NOP();NOP();
asm("rlf _Txbuf8,F");
asm("rlf _Txbuf7,F");
asm("rlf _Txbuf6,F");
asm("rlf _Txbuf5,F");
asm("rlf _Txbuf4,F");
asm("rlf _Txbuf3,F");
asm("rlf _Txbuf2,F");
asm("rlf _Txbuf1,F");
if(!CARRY) {Dly5(79);}
notbit(PORTB,1);
if(CARRY) {Dly5(79);}
Dly5(77);NOP();NOP();NOP();NOP();
notbit(PORTB,1);
if(--Temp1==0) break;
}
Dly5(80);
io_data = LOW;
Dly5(80);
TRISB |= 0B00000010;
}
//===========================================================
//= =
//===========================================================
void Readkey(void)
{
#asm
movlw 0xF0
andwf _PORTB,W
xorwf _Kbuf,W
xorwf _Kbuf,F ;PORTB&0xF0 -> Kbuf
movwf _Temp1
movf _Temp1,F
#endasm
if (ZERO == NO) {Kctr=0;return;}
if (++Kctr > 5)
{
Kctr = 0;
if (Kbuf == 0xF0)
{
b_Khold = NO;
}
else if (b_Khold == NO)
{
b_Khold = YES;
if (Kbuf == 0x70)
{
b_Kvalid = YES;
Txdata = 6;
}
else if (Kbuf == 0xB0)
{
b_Kvalid = YES;
Txdata = 7;
}
else if (Kbuf == 0xD0)
{
b_Kvalid = YES;
Txdata = 8;
}
else if (Kbuf == 0xE0)
{
b_Kvalid = YES;
Txdata = 9;
}
}
}
}
//===========================================================
//= =
//===========================================================
void SysInit(void)
{
CLRWDT();
PORTA = 0b00111110;
TRISA = 0b11000000;
PORTB = 0b00000000;
TRISB = 0b11111111;
PORTC = 0b11111111;
TRISC = 0b00000000;
OPTION = 0B01001111;
T1CON = 0B00000001;
CCPR1L = 0;
CCPR1H = 0;
CCP1CON = 0b00000000;
TMR2 = 0;
T2CON = 0b01111101;
PR2 = 124;
ADCON0 = 0b00000000;
ADCON1 = 0b00000111;
PIR1 = 0;
PIE1 = 0;
INTCON = 0B01010000;
while(1)
{
#asm
movlw 0x0C
andwf _PORTB,W
xorwf _Optbuf,W
xorwf _Optbuf,F ;3 2 1 0
movwf _Temp1
movf _Temp1,F
#endasm
if (ZERO == NO)
{
Optctr = 0;
}
else
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -