📄 cpu.h
字号:
//file name : cpu.h
#ifndef _CPU_H
#define _CPU_H
//来自网络:位段方式
//定义新的数据类型,方便进行IO端口操作。
typedef struct
{
unsigned char bit0:1 ;
unsigned char bit1:1 ;
unsigned char bit2:1 ;
unsigned char bit3:1 ;
unsigned char bit4:1 ;
unsigned char bit5:1 ;
unsigned char bit6:1 ;
unsigned char bit7:1 ;
}bit_field;
#define GET_BIT(adr) (*(( volatile bit_field * )(&adr)))
//是否起用自动io口初始化
#define AUTOINIT 1
#if AUTOINIT==1
#define PORT(m,n) GET_BIT(DDR ##m).bit##n=1;\
GET_BIT(PORT##m).bit##n
#else
#define PORT(m,n) GET_BIT(PORT##m).bit##n
#endif
////////////////////////////////////////
#if AUTOINIT==1
#define PIN(m,n) ( !(u08)(GET_BIT(DDR ##m).bit##n=0)&&\
(u08)( GET_BIT(PORT##m).bit##n=1)&&\
GET_BIT(PIN ##m).bit##n )
#else
#define PIN(m,n) GET_BIT(PIN##m).bit##n
#endif
#define DRA(n) GET_BIT(DDRA).bit##n //方便直观操作 自由设定单个io口的方向
#define DRB(n) GET_BIT(DDRB).bit##n
#define DRC(n) GET_BIT(DDRC).bit##n
#define DRD(n) GET_BIT(DDRD).bit##n
#define DDR(m,n) GET_BIT(DDR##m).bit##n
//定义avr 16bit数的little—endian风格的两个宏
#define HIGHBYTE(UINT16) ( ((unsigned char *)(&UINT16))[1] )
#define LOWBYTE(UINT16) ( ((unsigned char *)(&UINT16))[0] )
/* definition for timer0 */
#define T0_MIN_TICK ((256*1000000)/F_CPU)//unit us
#define T0_TICK 1 //unit ms - overflowtime
#if (T0_TICK*1000)<T0_MIN_TICK
#error "error,please rechoose the F_CPU"
#endif
#define TIMER0_BGN_VAL (255-(T0_TICK*1000/T0_MIN_TICK)) //timer0 initial
#define T2_TICK_MIN ((256*1000000)/F_CPU)
#define T2_TICK 1000 //1ms
#define TIMER2_BGN_VAL (255-T2_TICK/T2_TICK_MIN)
/********************全局变量******************/
#ifndef _CPU_C
extern BOOL f_15ms ;
extern BOOL f_500ms ;
extern BOOL f_1s ;
extern BOOL f_5s ;
extern BOOL f_60s ;
extern u08 SYS_ch;
extern u08 AlrmStatusT ;
extern u08 AlrmStatusH ;
extern uint8 Humidity ;
extern int16 Temperature ;
extern BOOL f_sensor_t ; //温度传感器不存在
extern BOOL f_sensor_h ;
extern u08 RelayBreak ;
extern u08 SystemStatus;
extern u08 SystemMode;
#endif
void TimerInit(void);
void timer0_start(void);
void timer0_stop (void);
#endif
/********************** the end ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -