⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc2420.i

📁 使用avr--cc2420模块程序,需要原理图的联系 QQ:120304948
💻 I
📖 第 1 页 / 共 2 页
字号:
// CodeVisionAVR C Compiler
// (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.

// I/O registers definitions for the ATmega128


#pragma used+
sfrb PINF=0;
sfrb PINE=1;
sfrb DDRE=2;
sfrb PORTE=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4;      // 16 bit access
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRR0L=9;
sfrb UCSR0B=0xa;
sfrb UCSR0A=0xb;
sfrb UDR0=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e;   // 16 bit access
sfrb SFIOR=0x20;
sfrb WDTCR=0x21;
sfrb OCDR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrw ICR1=0x26;   // 16 bit access
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28;  // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a;  // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c;  // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb ASSR=0x30;
sfrb OCR0=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TIFR=0x36;
sfrb TIMSK=0x37;
sfrb EIFR=0x38;
sfrb EIMSK=0x39;
sfrb EICRB=0x3a;
sfrb RAMPZ=0x3b;
sfrb XDIV=0x3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-


// Interrupt vectors definitions


/*
  CodeVisionAVR C Compiler
  (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.

  Prototype for SPI access function */
  

#pragma used+
unsigned char spi(unsigned char data);
#pragma used-

#pragma library spi.lib

// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.


#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-



typedef unsigned int UINT;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef long LONG;
typedef unsigned int WORD;
typedef unsigned char BOOL;
typedef unsigned char uchar;


//timer
typedef struct 
{
    unsigned char bUsed;
    DWORD ltimes;
}TIMERTICK;


//serial port and protocol buffer status


typedef struct 
{
	BYTE buffer[10       ];
	UINT empty;
	UINT data;
    unsigned char overflow;
    unsigned char timeout;
//    UINT timer;
}SPSTATUS;









extern bit study_ok;
extern bit system_initial_flag;

void workingloop();
void CPU_init(void);






extern bit receive_ok;
extern unsigned char cc2420_data_send[30];
extern unsigned int CALL_TIMER;

void myid_no(unsigned char value);
void cc2420_initial(void);
void cc2420_ready(void);
void cc2420_send(unsigned char ncont);
unsigned char cc2420_receive(unsigned char ncont);
void cc2420_test(void);
void cc2420_deal(void);
void data_proc(void);


extern unsigned char count;
extern unsigned char study_key;

extern unsigned char my_usart0_data[25];

void usart0_init();
void usart1_init();
void sp_init();
BYTE sp_getchar();
unsigned char sp_notempty();
void sp_flush();
void sp_init_buf();
void usart0_send(BYTE * pBuf, unsigned char ncont);
void usart1_send(BYTE * pBuf, unsigned char ncont);
void sp_rcv_proc(BYTE data);
void sp_usart0_proc(BYTE data);
void sp_writebyte(BYTE c);
unsigned char sp_proc();
void usart0_proc();
void led_send0(unsigned char onoff);
void led_send1(unsigned char * seed_data);

extern int g_itemp_c[1];


void ts_init();

void ts_delay(unsigned int counter);
//void ts_delay(unsigned long counter);
void ts_delay_0(unsigned int wcounter, unsigned int incounter);

unsigned char ts_ow_reset();
unsigned char ts_read_bit();
void ts_write_bit(char bitval);
unsigned char ts_read_byte(void);
void ts_write_byte(char val);
void Read_Temperature(void);

void ts_FindDevices(void);
unsigned char ts_First(void);
unsigned char ts_Next(void);
unsigned char ts_ow_crc( unsigned char x);
void Read_Temp(unsigned int nID); 
void temp_deal();





bit receive_ok = 0;
bit on_ok = 0;

unsigned char cc2420_data_send[30];
unsigned char cc2420_data_recive[30];
unsigned char cc2420_data_temp[30];

#pragma warn-
eeprom unsigned char SET_OUT;
#pragma warn+

unsigned int HOME_ID;
unsigned int MY_ID;
unsigned int CALL_TIMER;

// SPI functions

// SPI interrupt service routine
/*interrupt [SPI_STC] void spi_isr(void)
{
unsigned char data;
data=SPDR;
// Place your code here

}*/  

void myid_no(unsigned char value)
{

    HOME_ID = 10001;
	MY_ID = 18180 + value;  
    CALL_TIMER = 60000 + value;        //60000
}

void cc2420_initial(void)
{	
    unsigned int i;
                  
    myid_no(3     );
	
	if (SET_OUT > 1)        //8
	    SET_OUT = 0;

	if (SET_OUT)
	{
        PORTD.5 = 1;
		PORTD.4 = 0;
        delay_ms(1000);
        #asm("wdr");
        led_send0(1);
		PORTD.7 = 0;    //ON 
		on_ok = 1;
	}
	else
	{
	    PORTD.5 = 0;
		PORTD.4 = 0;
//        delay_ms(1000);
        #asm("wdr");
//        led_send0(0);
		PORTD.7 = 1;    //OFF
	}

// CC2420 initialization

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 115.200 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
    SPCR=0x52;     
    SPSR=0x00;

	for (i=0;i<30;i++)
	{
		cc2420_data_send[i]=0x00;
		cc2420_data_recive[i]=0x00;
	}
}

void cc2420_ready(void)
{	
    unsigned int i;

	PORTD.1=0;
    delay_ms(100);       //100ms  //100
	PORTD.1=1;
    delay_ms(5);       //0.6ms //5
	PORTB.4=0;
    delay_ms(50);       //100ms  //100
	PORTB.4=1;
    #asm("wdr");
	
	PORTB.0=0;
	i=spi(0x01);
    delay_ms(2);       //0.86ms  //5
	while ((i&0x40)==0)
	{
		i=spi(0x01);
        #asm("wdr");
	}

	i=spi(0x08);
	i=spi(0x09);
	i=spi(0x10);
	i=spi(0xF8);
	i=spi(0x00);
	i=spi(0x11);
	i=spi(0x02);   //0A
	i=spi(0xE2);
	i=spi(0x12);
	i=spi(0x05);
	i=spi(0x00);
	i=spi(0x13);
	i=spi(0xE0);
	i=spi(0x80);
	i=spi(0x14);
	i=spi(0xA7);
	i=spi(0x0F);
	i=spi(0x15);
	i=spi(0xA0);
	i=spi(0xFF);
	i=spi(0x16);
	i=spi(0x12);
	i=spi(0xE5);
	i=spi(0x17);
	i=spi(0x0A);
	i=spi(0x56);
	i=spi(0x18);
	i=spi(0x41);
	i=spi(0x65);
	i=spi(0x19);
	i=spi(0x01);   //03
	i=spi(0xC4);
	i=spi(0x1A);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x1B);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x1C);
	i=spi(0x00);
	i=spi(0x40);
	i=spi(0x1D);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x20);
	i=spi(0x7A);
	i=spi(0x94);
	i=spi(0x21);
	i=spi(0xFF);
	i=spi(0xFF);
	i=spi(0x22);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x23);
	i=spi(0x07);
	i=spi(0xF0);
	i=spi(0x24);
	i=spi(0x36);
	i=spi(0x49);
	i=spi(0x25);
	i=spi(0x08);
	i=spi(0x54);
	i=spi(0x26);
	i=spi(0x01);
	i=spi(0x2A);
	i=spi(0x27);
	i=spi(0x02);
	i=spi(0x00);
	i=spi(0x28);
	i=spi(0x50);
	i=spi(0x02);
	i=spi(0x29);
	i=spi(0x06);
	i=spi(0x00);
	i=spi(0x2A);
	i=spi(0x82);
	i=spi(0xDD);
	i=spi(0x2B);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x2C);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x2D);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x2E);
	i=spi(0x00);
	i=spi(0x00);
	i=spi(0x2F);
	i=spi(0x00);
	i=spi(0x10);
 	i=spi(0x03);
	PORTB.0=1;

	PORTB.0=0;
 	i=spi(0x03);
	PORTB.0=1;
    #asm("wdr");
}	

void cc2420_send(unsigned char ncont)
{	
    unsigned char i;

    while (PINB.5);
    PORTB.0=0;
    i=spi(0x09);
    PORTB.0=1;
   			
    PORTB.0=0;
    i=spi(0x3E);
    for (i=0; i<ncont; i++)
    {
   	    spi(cc2420_data_send[i]);
    }
    PORTB.0=1;
   			    
    PORTB.0=0; 
    i=spi(0x04);
    while (PINB.5);
    PORTB.0=1; 
}

// External Interrupt 0 service routine

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -