📄 cc1000_main.i
字号:
if ((status & ((1<<4) | (1<<2) | (1<<3)))==0)
{
rx_buffer[rx_wr_index]=data;
if (++rx_wr_index == 16) rx_wr_index=0;
if (++rx_counter == 16)
{
rx_counter=0;
rx_buffer_overflow=1;
};
};
}
// Get a character from the USART Receiver buffer
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == 16) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
// Standard Input/Output functions
// CodeVisionAVR C Compiler
// (C) 1998-2006 Pavel Haiduc, HP InfoTech S.R.L.
// Prototypes for standard I/O functions
// CodeVisionAVR C Compiler
// (C) 1998-2002 Pavel Haiduc, HP InfoTech S.R.L.
// Variable length argument list macros
typedef char *va_list;
typedef char *va_list;
typedef char *va_list;
#pragma used+
char getchar(void);
void putchar(char c);
void puts(char *str);
void putsf(char flash *str);
char *gets(char *str,unsigned int len);
void printf(char flash *fmtstr,...);
void sprintf(char *str, char flash *fmtstr,...);
void snprintf(char *str, unsigned int size, char flash *fmtstr,...);
void vprintf (char flash * fmtstr, va_list argptr);
void vsprintf (char *str, char flash * fmtstr, va_list argptr);
void vsnprintf (char *str, unsigned int size, char flash * fmtstr, va_list argptr);
signed char scanf(char flash *fmtstr,...);
signed char sscanf(char *str, char flash *fmtstr,...);
#pragma used-
#pragma library stdio.lib
// Timer 0 overflow interrupt service routine
interrupt [10] void timer0_ovf_isr(void)
{
// Place your code here
if(search_counter==5)
{
search_counter = 0;
DDRD &=0xFC;
get_key = PIND&0x03;
if((get_key!=0x03)&&(lock_key==0))
{
//sprintf(&cc1000_table[9],"%x",get_key);
cc1000_table[4]=Self_ID[0];
cc1000_table[5]=Self_ID[1];
cc1000_table[6]=Self_ID[2];
cc1000_table[7]=Self_ID[3];
cc1000_table[9]=get_key;
cc1000_table[10]=17;
cc1000_table[11]=c++;
key_flag = SendOnePacketToCC1000(cc1000_table);
}
}
search_counter++;
TCNT0=0x00;
}
// Timer 1 overflow interrupt service routine
interrupt [9] void timer1_ovf_isr(void)
{
// Place your code here
DDRD &=0xFC;
get_long_key = PIND&0x03;
temp_key=get_long_key;
temp_long_key=(old_long_key<<4);
get_long_key = get_long_key+temp_long_key;
switch(get_long_key)
{
case 0x33: break;
case 0x30:
case 0x31:
case 0x32: old_long_key=temp_key;
break;
case 0x03:
case 0x13:
case 0x23:
break;
case 0x00:
case 0x11:
case 0x22: long_counter++;
break;
default : long_counter=0;
old_long_key=temp_key;
break;
}
if(long_counter==7)lock_key=1;
if(long_counter==12)
{
old_long_key=0x03;
long_counter = 0;
Registration_table[4]=temp_key;
Self_ID[0]=temp_key;
Registration_table[5]=Self_ID[1];
Registration_table[6]=Self_ID[2];
Registration_table[7]=Self_ID[3];
Registration_Return_table[0]=Self_ID[0];
Registration_Return_table[1]=Self_ID[1];
Registration_Return_table[2]=Self_ID[2];
Registration_Return_table[3]=Self_ID[3];
key_flag = SendOnePacketToCC1000(&Registration_table[0]);
lock_key=0;
}
TCNT1H=0xFE;
TCNT1L=0x18;
}
void bell(unsigned char abc)
{
for( ;abc>0;abc--)
{
DDRD |=0x08;
PORTD.3 = 1;
delay_ms(150);
PORTD.3 =0;
delay_ms(300);
}
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
unsigned char i = 0,j = 0;
//unsigned char low = 0;
// Input/Output Ports initialization
// Port B initialization
// Func7=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=0 State6=T State5=T State4=T State3=T State2=T State1=T State0=1
PORTB=0x07;
DDRB=0x81;
// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=1 State6=1 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTD=0xC0;
DDRD=0xE0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 0.977 kHz
TCCR0=0x05;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1B = 0x00; //stop
TCNT1H = 0xFE; //setup
TCNT1L = 0x18;
OCR1AH = 0x01;
OCR1AL = 0xE8;
OCR1BH = 0x01;
OCR1BL = 0xE8;
ICR1H = 0x01;
ICR1L = 0xE8;
TCCR1A = 0x00;
TCCR1B = 0x05; //start Timer
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x05;
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 4800
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x0C;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Place your code here
#asm("sei")
if(InitialCC1000())
bell(2);
// DS1302 Real Time Clock initialization
// Trickle charger: On
// Trickle charge resistor: 2K
// Trickle charge diode(s): 1
while (1)
{
// Place your code here
#asm("WDR")
while(key_flag==0) ;
key_flag = 0;
bell(1);
while(string!=ReceiveOnePacketFromCC1000(string,0));
bell(1);
delay_ms(500);
if(string[8] == Registration_Return_table[8])
{
for(i=0;i<4;i++)
{
if(string[i] != Registration_Return_table[i])
break;
}
if(i==4)
{
//for(i=0;i<4;i++)
cc1000_table[0]=string[4];
cc1000_table[1]=string[5];
cc1000_table[2]=string[6];
cc1000_table[3]=string[7];
// sprintf(&cc1000_table[0],"%x%x%x%x",string[4],string[5],string[6],string[7]);
bell(1);
}
}
// else if(string[8] == cc1000_SetTime_show[8])
// key_flag = SendOnePacketToCC1000(cc1000_SetTime_show);
delay_ms(300);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -