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

📄 global.h

📁 射频芯片cc2420的使用例程
💻 H
字号:
#ifndef GLOBAL_H
#define GLOBAL_H

/* enable use of extended keywords */
#pragma language=extended

#include <stdio.h>
#include <inavr.h>

#ifndef ENABLE_BIT_DEFINITIONS
#define ENABLE_BIT_DEFINITIONS
/* Enable the bit definitions in the iom128.h file */
#endif

#include <iom128.h>

//全局AVR库定义
#include "defs.h"
// 全局AVR库类型定义
#include "types.h"

/******************************************************************************
			此文件定义了编程板上的器件连接
******************************************************************************/
/*******************************************************************************************************
		ATmega128 I/O  端口
 *******************************************************************************************************/
// 空闲端口在:A,B,C,D,E;共16腿。
//PortA(nop:0~7)

// Port B(nop:4,6)
#define CSN             0  // PB.0 - Output: SPI Chip Select (CS_N)
#define SCK             1  // PB.1 - Output: SPI Serial Clock (SCLK)
#define MOSI            2  // PB.2 - Output: SPI Master out - slave in (MOSI)
#define MISO            3  // PB.3 - Input:  SPI Master in - slave out (MISO)
#define FIFO            5  // PB.5 - 输入:CC2420 的 FIFO引脚输入
#define VREG_EN        	7  // PB.7 - 输入:CC2420 的 FIFO引脚输入

//Port C(nop:1,2,5,6,7)
#define LIGHT_SEN	0
#define I2C_SCL	        3
#define I2C_SDA	        4

// Port D(nop:0)
//#define     //D0 口可以外接中断
#define YLED        	1
#define GLED		2
#define RLED		3
#define FLASH_CS	4
#define FLASH_SCK	5
#define FLASH_SI	6
#define FLASH_SO	7

// Port E(nop:2)
#define UART0_RXD       0
#define UART0_TXD       1
#define RESET_N         3
#define SFD             4  // PE.4 - 输入:  来自于CC2420的SFD
#define CCA             5  // PE.5 - 输入: 来自于CC2420的CCA
#define FIFOP           6  // PE.6 - 输入:CC2420 的 FIFO引脚输入
#define FIFOP_INT       7  // PE.7 - 输入:来自于CC2420的FIFOP引脚,引起外部中断7

// Port F
#define ADC0		0  // adc7 with light sensor
#define ADC1     	1  // adc6
#define ADC2     	2  // adc4
#define ADC3     	3  // adc5

// Port G
// External RAM interface:
//     PA and PC - Multiplexed address/data
//     PG.0 - Output: Write enable: WR_N
//     PG.1 - Output: Read enable: RD_N
//     PG.2 - Output: Address Latch Enable: ALE


/******************************************************************************
							LEDs指示灯                                     
******************************************************************************/
// Set LED
#define SET_RLED()                  (PORTD &= ~BV(RLED))
#define SET_GLED()                  (PORTD &= ~BV(GLED))
#define SET_YLED()                  (PORTD &= ~BV(YLED))

// Clear LED
#define CLR_RLED()                  (PORTD |= BV(RLED))
#define CLR_GLED()                  (PORTD |= BV(GLED))
#define CLR_YLED()                  (PORTD |= BV(YLED))

//初始化LED
#define INIT_LED() \
	do \
	{ \
		DDRA |= 0x0E; \
		CLR_RLED(); \
		CLR_GLED(); \
		CLR_YLED(); \
	} \
	while (0);

// 所有指示灯同时显示4bit二进制码
#define SET_LED_MASK(n) \
    do { \
        if (n & 0x08) SET_RLED(); else CLR_RLED(); \
        if (n & 0x04) SET_GLED(); else CLR_GLED(); \
        if (n & 0x02) SET_YLED(); else CLR_YLED(); \
    } while (0)
// project/system dependent defines

// CPU clock speed
//#define F_CPU        16000000               		// 16MHz processor
//#define F_CPU        14745000               		// 14.745MHz processor
#define F_CPU        8000000               		// 8MHz processor
//#define F_CPU        7372800               		// 7.37MHz processor
//#define F_CPU        4000000               		// 4MHz processor
//#define F_CPU        3686400               		// 3.69MHz processor
#define CYCLES_PER_US ((F_CPU+500000)/1000000) 	// cpu cycles per microsecond  =8.5

#endif

⌨️ 快捷键说明

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