比如 PC_1 = 1;//是可以正常编译的,自己看看喽
/********************************************************************
**说明:此头文件为AVR编程自制通用头文件
**内容:数据类型的定义,位操作的定义。。。
********************************************************************/
#ifndef ___AVRextern_h
#define ___AVRextern_h
#include<iom16v.h>//mega16
#include<macros.h>//AVR单片机系统函数头文件;
//-------------数据类型-------------//
#define UINT8 unsigned char
#define INT8 char
#define UINT16 unsigned int
#define INT16 int
#define UINT32 unsigned long
#define INT32 long
#define FLOAT float
//sbit 定义位变量
//------------IO口操作--------------//
#define OUT 1
#define IN 0
// PORTA&=~BIT(PA0)//PA0 输出低电平
// PORTA|=BIT(PA0) //PA0 输出高电平
// PORTA^=BIT(PA0) //将PA0输出单独取反
// DDRx = 0Xxx; //端口方式设置寄存器
// PORTx = 0Xxx; //端口数据寄存器
// PINx //读取端口的电平状态
// SFIOR|=BIT(PUD) //禁止所有端口的上拉电阻;
/*------------------*
* 功 能 宏 定 义 *
*------------------*/
# define SET_BIT8_FORMAT(Addr) (*((volatile BYTEBIT *)&Addr))
# define SET_BYTE_DIV_2(Addr) (*((volatile BYTE2HBYTE *)&Addr))
# define SET_BIT16_FORMAT(Addr) (*((volatile WORDBIT *)&Addr))
# define SET_WORD_DIV_2(Addr) (*((volatile WORD2BYTE *)&Addr))
# define SET_WORD_DIV_4(Addr) (*((volatile WORD2HBYTE *)&Addr))
# define SET_BIT32_FORMAT(Addr) (*((volatile DWORDBIT *)&Addr))
# define SET_DWORD_DIV_2(Addr) (*((volatile DWORD2WORD *)&Addr))
# define SET_DWORD_DIV_4(Addr) (*((volatile DWORD2BYTE *)&Addr))
# define SET_DWORD_DIV_8(Addr) (*((volatile DWORD2HBYTE *)&Addr))
/********************
* 结 构 体 定 义 区 *
********************/
/*------------------*
* 8位变量位映射 *
*------------------*/
typedef struct BYTE_BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
}BYTEBIT;
/*------------------*
* 16位变量位映射 *
*------------------*/
typedef struct WORD_BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
unsigned BIT8:1;
unsigned BIT9:1;
unsigned BIT10:1;
unsigned BIT11:1;
unsigned BIT12:1;
unsigned BIT13:1;
unsigned BIT14:1;
unsigned BIT15:1;
}WORDBIT;
/*------------------*
* 32位变量位映射 *
*------------------*/
typedef struct DWORD_BIT
{
unsigned BIT0:1;
unsigned BIT1:1;
unsigned BIT2:1;
unsigned BIT3:1;
unsigned BIT4:1;
unsigned BIT5:1;
unsigned BIT6:1;
unsigned BIT7:1;
unsigned BIT8:1;
unsigned BIT9:1;
unsigned BIT10:1;
unsigned BIT11:1;
unsigned BIT12:1;
unsigned BIT13:1;
unsigned BIT14:1;
unsigned BIT15:1;
unsigned BIT16:1;
unsigned BIT17:1;
unsigned BIT18:1;
unsigned BIT19:1;
unsigned BIT20:1;
unsigned BIT21:1;
unsigned BIT22:1;
unsigned BIT23:1;
unsigned BIT24:1;
unsigned BIT25:1;
unsigned BIT26:1;
unsigned BIT27:1;
unsigned BIT28:1;
unsigned BIT29:1;
unsigned BIT30:1;
unsigned BIT31:1;
}DWORDBIT;
/*------------------*
* 32位变量4分映射 *
*------------------*/
typedef struct DWORD_BYTE
{
unsigned BYTEA:8;
unsigned BYTEB:8;
unsigned BYTEC:8;
unsigned BYTED:8;
}DWORD2BYTE;
/*------------------*
* 32位变量2分映射 *
*------------------*/
typedef struct DWORD_WORD
{
unsigned WORDA:16;
unsigned WORDB:16;
}DWORD2WORD;
/*------------------*
* 32位变量16分映射 *
*------------------*/
typedef struct DWORD_HBYTE
{
unsigned BYTEAL:4;
unsigned BYTEAH:4;
unsigned BYTEBL:4;
unsigned BYTEBH:4;
unsigned BYTECL:4;
unsigned BYTECH:4;
unsigned BYTEDL:4;
unsigned BYTEDH:4;
}DWORD2HBYTE;
/*------------------*
* 16位变量2分映射 *
*------------------*/
typedef struct WORD_BYTE
{
unsigned BYTEA:8;
unsigned BYTEB:8;
}WORD2BYTE;
/*------------------*
* 16位变量4分映射 *
*------------------*/
typedef struct WORD_HBYTE
{
unsigned BYTEAL:4;
unsigned BYTEAH:4;
unsigned BYTEBL:4;
unsigned BYTEBH:4;
}WORD2HBYTE;
/*------------------*
* 8位变量2分映射 *
*------------------*/
typedef struct BYTE_DIV2
{
unsigned BYTEAL:4;
unsigned BYTEAH:4;
}BYTE2HBYTE;
/*------------------*
* 常 数 宏 定 义 *
*------------------*/
#ifndef PDIR_OUT
# define PDIR_OUT 0x01
#endif
#ifndef PDIR_IN
# define PDIR_IN 0x00
#endif
/*------------------*
* 硬 件 连 接 定 义 *
*------------------*/
/*---------------- PORT口绑定 ---------------*/
#ifdef PORTA
# define PORTA_BIT SET_BIT8_FORMAT(PORTA)
#endif
#ifdef PORTB
# define PORTB_BIT SET_BIT8_FORMAT(PORTB)
#endif
#ifdef PORTC
# define PORTC_BIT SET_BIT8_FORMAT(PORTC)
#endif
#ifdef PORTD
# define PORTD_BIT SET_BIT8_FORMAT(PORTD)
#endif
#ifdef PORTE
# define PORTE_BIT SET_BIT8_FORMAT(PORTE)
#endif
#ifdef PORTF
# define PORTF_BIT SET_BIT8_FORMAT(PORTF)
#endif
#ifdef PORTG
# define PORTG_BIT SET_BIT8_FORMAT(PORTG)
#endif
/*---------------- DDR 口绑定 ---------------*/
#ifdef DDRA
# define DDRA_BIT SET_BIT8_FORMAT(DDRA)
#endif
#ifdef DDRB
# define DDRB_BIT SET_BIT8_FORMAT(DDRB)
#endif
#ifdef DDRC
# define DDRC_BIT SET_BIT8_FORMAT(DDRC)
#endif
#ifdef DDRD
# define DDRD_BIT SET_BIT8_FORMAT(DDRD)
#endif
#ifdef DDRE
# define DDRE_BIT SET_BIT8_FORMAT(DDRE)
#endif
#ifdef DDRF
# define DDRF_BIT SET_BIT8_FORMAT(DDRF)
#endif
#ifdef DDRG
# define DDRG_BIT SET_BIT8_FORMAT(DDRG)
#endif
/*---------------- PIN 口绑定 ---------------*/
#ifdef PINA
# define PINA_BIT SET_BIT8_FORMAT(PINA)
#endif
#ifdef PINB
# define PINB_BIT SET_BIT8_FORMAT(PINB)
#endif
#ifdef PINC
# define PINC_BIT SET_BIT8_FORMAT(PINC)
#endif
#ifdef PIND
# define PIND_BIT SET_BIT8_FORMAT(PIND)
#endif
#ifdef PINE
# define PINE_BIT SET_BIT8_FORMAT(PINE)
#endif
#ifdef PINF
# define PINF_BIT SET_BIT8_FORMAT(PINF)
#endif
#ifdef PING
# define PING_BIT SET_BIT8_FORMAT(PING)
#endif
/*------------------*
* 端 口 宏 定 义 *
*------------------*/
/*-------------PORT位操作定义--------------*/
#ifdef PORTA
# define PA_0 PORTA_BIT.BIT0
# define PA_1 PORTA_BIT.BIT1
# define PA_2 PORTA_BIT.BIT2
# define PA_3 PORTA_BIT.BIT3
# define PA_4 PORTA_BIT.BIT4
# define PA_5 PORTA_BIT.BIT5
# define PA_6 PORTA_BIT.BIT6
# define PA_7 PORTA_BIT.BIT7
# define PORTA_0 PORTA_BIT.BIT0
# define PORTA_1 PORTA_BIT.BIT1
# define PORTA_2 PORTA_BIT.BIT2
# define PORTA_3 PORTA_BIT.BIT3
# define PORTA_4 PORTA_BIT.BIT4
# define PORTA_5 PORTA_BIT.BIT5
# define PORTA_6 PORTA_BIT.BIT6
# define PORTA_7 PORTA_BIT.BIT7
#endif
#ifdef PORTB
# define PB_0 PORTB_BIT.BIT0
# define PB_1 PORTB_BIT.BIT1
# define PB_2 PORTB_BIT.BIT2
# define PB_3 PORTB_BIT.BIT3
# define PB_4 PORTB_BIT.BIT4
# define PB_5 PORTB_BIT.BIT5
# define PB_6 PORTB_BIT.BIT6
# define PB_7 PORTB_BIT.BIT7
# define PORTB_0 PORTB_BIT.BIT0
# define PORTB_1 PORTB_BIT.BIT1
# define PORTB_2 PORTB_BIT.BIT2
# define PORTB_3 PORTB_BIT.BIT3
# define PORTB_4 PORTB_BIT.BIT4
# define PORTB_5 PORTB_BIT.BIT5
# define PORTB_6 PORTB_BIT.BIT6
# define PORTB_7 PORTB_BIT.BIT7
#endif
#ifdef PORTC
# define PC_0 PORTC_BIT.BIT0
# define PC_1 PORTC_BIT.BIT1
# define PC_2 PORTC_BIT.BIT2
# define PC_3 PORTC_BIT.BIT3
# define PC_4 PORTC_BIT.BIT4
# define PC_5 PORTC_BIT.BIT5
# define PC_6 PORTC_BIT.BIT6
# define PC_7 PORTC_BIT.BIT7
# define PORTC_0 PORTC_BIT.BIT0
# define PORTC_1 PORTC_BIT.BIT1
# define PORTC_2 PORTC_BIT.BIT2
# define PORTC_3 PORTC_BIT.BIT3
# define PORTC_4 PORTC_BIT.BIT4
# define PORTC_5 PORTC_BIT.BIT5
# define PORTC_6 PORTC_BIT.BIT6
# define PORTC_7 PORTC_BIT.BIT7
#endif
#ifdef PORTD
# define PD_0 PORTD_BIT.BIT0
# define PD_1 PORTD_BIT.BIT1
# define PD_2 PORTD_BIT.BIT2
# define PD_3 PORTD_BIT.BIT3
# define PD_4 PORTD_BIT.BIT4
# define PD_5 PORTD_BIT.BIT5
# define PD_6 PORTD_BIT.BIT6
# define PD_7 PORTD_BIT.BIT7
# define PORTD_0 PORTD_BIT.BIT0
# define PORTD_1 PORTD_BIT.BIT1
# define PORTD_2 PORTD_BIT.BIT2
# define PORTD_3 PORTD_BIT.BIT3
# define PORTD_4 PORTD_BIT.BIT4
# define PORTD_5 PORTD_BIT.BIT5
# define PORTD_6 PORTD_BIT.BIT6
# define PORTD_7 PORTD_BIT.BIT7
#endif
#ifdef PORTE
# define PE_0 PORTE_BIT.BIT0
# define PE_1 PORTE_BIT.BIT1
# define PE_2 PORTE_BIT.BIT2
# define PE_3 PORTE_BIT.BIT3
# define PE_4 PORTE_BIT.BIT4
# define PE_5 PORTE_BIT.BIT5
# define PE_6 PORTE_BIT.BIT6
# define PE_7 PORTE_BIT.BIT7
# define PORTE_0 PORTE_BIT.BIT0
# define PORTE_1 PORTE_BIT.BIT1
# define PORTE_2 PORTE_BIT.BIT2
# define PORTE_3 PORTE_BIT.BIT3
# define PORTE_4 PORTE_BIT.BIT4
# define PORTE_5 PORTE_BIT.BIT5
# define PORTE_6 PORTE_BIT.BIT6
# define PORTE_7 PORTE_BIT.BIT7
#endif
#ifdef PORTF
# define PF_0 PORTF_BIT.BIT0
# define PF_1 PORTF_BIT.BIT1
# define PF_2 PORTF_BIT.BIT2
# define PF_3 PORTF_BIT.BIT3
# define PF_4 PORTF_BIT.BIT4
# define PF_5 PORTF_BIT.BIT5
# define PF_6 PORTF_BIT.BIT6
# define PF_7 PORTF_BIT.BIT7
# define PORTF_0 PORTF_BIT.BIT0
# define PORTF_1 PORTF_BIT.BIT1
# define PORTF_2 PORTF_BIT.BIT2
# define PORTF_3 PORTF_BIT.BIT3
# define PORTF_4 PORTF_BIT.BIT4
# define PORTF_5 PORTF_BIT.BIT5
# define PORTF_6 PORTF_BIT.BIT6
# define PORTF_7 PORTF_BIT.BIT7
#endif
#ifdef PORTG
# define PG_0 PORTG_BIT.BIT0
# define PG_1 PORTG_BIT.BIT1
# define PG_2 PORTG_BIT.BIT2
# define PG_3 PORTG_BIT.BIT3
# define PG_4 PORTG_BIT.BIT4
# define PG_5 PORTG_BIT.BIT5
# define PG_6 PORTG_BIT.BIT6
# define PG_7 PORTG_BIT.BIT7
# define PORTG_0 PORTG_BIT.BIT0
# define PORTG_1 PORTG_BIT.BIT1
# define PORTG_2 PORTG_BIT.BIT2
# define PORTG_3 PORTG_BIT.BIT3
# define PORTG_4 PORTG_BIT.BIT4
# define PORTG_5 PORTG_BIT.BIT5
# define PORTG_6 PORTG_BIT.BIT6
# define PORTG_7 PORTG_BIT.BIT7
#endif
/*------------- DDR 位操作定义 -------------*/
#ifdef DDRA
# define DDRA_0 DDRA_BIT.BIT0
# define DDRA_1 DDRA_BIT.BIT1
# define DDRA_2 DDRA_BIT.BIT2
# define DDRA_3 DDRA_BIT.BIT3
# define DDRA_4 DDRA_BIT.BIT4
# define DDRA_5 DDRA_BIT.BIT5
# define DDRA_6 DDRA_BIT.BIT6
# define DDRA_7 DDRA_BIT.BIT7
#endif
#ifdef DDRB
# define DDRB_0 DDRB_BIT.BIT0
# define DDRB_1 DDRB_BIT.BIT1
# define DDRB_2 DDRB_BIT.BIT2
# define DDRB_3 DDRB_BIT.BIT3
# define DDRB_4 DDRB_BIT.BIT4
# define DDRB_5 DDRB_BIT.BIT5
# define DDRB_6 DDRB_BIT.BIT6
# define DDRB_7 DDRB_BIT.BIT7
#endif
#ifdef DDRC
# define DDRC_0 DDRC_BIT.BIT0
# define DDRC_1 DDRC_BIT.BIT1
# define DDRC_2 DDRC_BIT.BIT2
# define DDRC_3 DDRC_BIT.BIT3
# define DDRC_4 DDRC_BIT.BIT4
# define DDRC_5 DDRC_BIT.BIT5
# define DDRC_6 DDRC_BIT.BIT6
# define DDRC_7 DDRC_BIT.BIT7
#endif
#ifdef DDRD
# define DDRD_0 DDRD_BIT.BIT0
# define DDRD_1 DDRD_BIT.BIT1
# define DDRD_2 DDRD_BIT.BIT2
# define DDRD_3 DDRD_BIT.BIT3
# define DDRD_4 DDRD_BIT.BIT4
# define DDRD_5 DDRD_BIT.BIT5
# define DDRD_6 DDRD_BIT.BIT6
# define DDRD_7 DDRD_BIT.BIT7
#endif
#ifdef DDRE
# define DDRE_0 DDRE_BIT.BIT0
# define DDRE_1 DDRE_BIT.BIT1
# define DDRE_2 DDRE_BIT.BIT2
# define DDRE_3 DDRE_BIT.BIT3
# define DDRE_4 DDRE_BIT.BIT4
# define DDRE_5 DDRE_BIT.BIT5
# define DDRE_6 DDRE_BIT.BIT6
# define DDRE_7 DDRE_BIT.BIT7
#endif
#ifdef DDRF
# define DDRF_0 DDRF_BIT.BIT0
# define DDRF_1 DDRF_BIT.BIT1
# define DDRF_2 DDRF_BIT.BIT2
# define DDRF_3 DDRF_BIT.BIT3
# define DDRF_4 DDRF_BIT.BIT4
# define DDRF_5 DDRF_BIT.BIT5
# define DDRF_6 DDRF_BIT.BIT6
# define DDRF_7 DDRF_BIT.BIT7
#endif
#ifdef DDRG
# define DDRG_0 DDRG_BIT.BIT0
# define DDRG_1 DDRG_BIT.BIT1
# define DDRG_2 DDRG_BIT.BIT2
# define DDRG_3 DDRG_BIT.BIT3
# define DDRG_4 DDRG_BIT.BIT4
# define DDRG_5 DDRG_BIT.BIT5
# define DDRG_6 DDRG_BIT.BIT6
# define DDRG_7 DDRG_BIT.BIT7
#endif
/*------------- PIN 位操作定义 -------------*/
#ifdef PINA
# define READ_PA0 PINA_BIT.BIT0
# define READ_PA1 PINA_BIT.BIT1
# define READ_PA2 PINA_BIT.BIT2
# define READ_PA3 PINA_BIT.BIT3
# define READ_PA4 PINA_BIT.BIT4
# define READ_PA5 PINA_BIT.BIT5
# define READ_PA6 PINA_BIT.BIT6
# define READ_PA7 PINA_BIT.BIT7
# define PINA_0 PINA_BIT.BIT0
# define PINA_1 PINA_BIT.BIT1
# define PINA_2 PINA_BIT.BIT2
# define PINA_3 PINA_BIT.BIT3
# define PINA_4 PINA_BIT.BIT4
# define PINA_5 PINA_BIT.BIT5
# define PINA_6 PINA_BIT.BIT6
# define PINA_7 PINA_BIT.BIT7
#endif
#ifdef PINB
# define READ_PB0 PINB_BIT.BIT0
# define READ_PB1 PINB_BIT.BIT1
# define READ_PB2 PINB_BIT.BIT2
# define READ_PB3 PINB_BIT.BIT3
# define READ_PB4 PINB_BIT.BIT4
# define READ_PB5 PINB_BIT.BIT5
# define READ_PB6 PINB_BIT.BIT6
# define READ_PB7 PINB_BIT.BIT7
# define PINB_0 PINB_BIT.BIT0
# define PINB_1 PINB_BIT.BIT1
# define PINB_2 PINB_BIT.BIT2
# define PINB_3 PINB_BIT.BIT3
# define PINB_4 PINB_BIT.BIT4
# define PINB_5 PINB_BIT.BIT5
# define PINB_6 PINB_BIT.BIT6
# define PINB_7 PINB_BIT.BIT7
#endif
#ifdef PINC
# define READ_PC0 PINC_BIT.BIT0
# define READ_PC1 PINC_BIT.BIT1
# define READ_PC2 PINC_BIT.BIT2
# define READ_PC3 PINC_BIT.BIT3
# define READ_PC4 PINC_BIT.BIT4
# define READ_PC5 PINC_BIT.BIT5
# define READ_PC6 PINC_BIT.BIT6
# define READ_PC7 PINC_BIT.BIT7
# define PINC_0 PINC_BIT.BIT0
# define PINC_1 PINC_BIT.BIT1
# define PINC_2 PINC_BIT.BIT2
# define PINC_3 PINC_BIT.BIT3
# define PINC_4 PINC_BIT.BIT4
# define PINC_5 PINC_BIT.BIT5
# define PINC_6 PINC_BIT.BIT6
# define PINC_7 PINC_BIT.BIT7
#endif
#ifdef PIND
# define READ_PD0 PIND_BIT.BIT0
# define READ_PD1 PIND_BIT.BIT1
# define READ_PD2 PIND_BIT.BIT2
# define READ_PD3 PIND_BIT.BIT3
# define READ_PD4 PIND_BIT.BIT4
# define READ_PD5 PIND_BIT.BIT5
# define READ_PD6 PIND_BIT.BIT6
# define READ_PD7 PIND_BIT.BIT7
# define PIND_0 PIND_BIT.BIT0
# define PIND_1 PIND_BIT.BIT1
# define PIND_2 PIND_BIT.BIT2
# define PIND_3 PIND_BIT.BIT3
# define PIND_4 PIND_BIT.BIT4
# define PIND_5 PIND_BIT.BIT5
# define PIND_6 PIND_BIT.BIT6
# define PIND_7 PIND_BIT.BIT7
#endif
#ifdef PINE
# define READ_PE0 PINE_BIT.BIT0
# define READ_PE1 PINE_BIT.BIT1
# define READ_PE2 PINE_BIT.BIT2
# define READ_PE3 PINE_BIT.BIT3
# define READ_PE4 PINE_BIT.BIT4
# define READ_PE5 PINE_BIT.BIT5
# define READ_PE6 PINE_BIT.BIT6
# define READ_PE7 PINE_BIT.BIT7
# define PINE_0 PINE_BIT.BIT0
# define PINE_1 PINE_BIT.BIT1
# define PINE_2 PINE_BIT.BIT2
# define PINE_3 PINE_BIT.BIT3
# define PINE_4 PINE_BIT.BIT4
# define PINE_5 PINE_BIT.BIT5
# define PINE_6 PINE_BIT.BIT6
# define PINE_7 PINE_BIT.BIT7
#endif
#ifdef PINF
# define READ_PF0 PINF_BIT.BIT0
# define READ_PF1 PINF_BIT.BIT1
# define READ_PF2 PINF_BIT.BIT2
# define READ_PF3 PINF_BIT.BIT3
# define READ_PF4 PINF_BIT.BIT4
# define READ_PF5 PINF_BIT.BIT5
# define READ_PF6 PINF_BIT.BIT6
# define READ_PF7 PINF_BIT.BIT7
# define PINF_0 PINF_BIT.BIT0
# define PINF_1 PINF_BIT.BIT1
# define PINF_2 PINF_BIT.BIT2
# define PINF_3 PINF_BIT.BIT3
# define PINF_4 PINF_BIT.BIT4
# define PINF_5 PINF_BIT.BIT5
# define PINF_6 PINF_BIT.BIT6
# define PINF_7 PINF_BIT.BIT7
#endif
#ifdef PING
# define READ_PG0 PING_BIT.BIT0
# define READ_PG1 PING_BIT.BIT1
# define READ_PG2 PING_BIT.BIT2
# define READ_PG3 PING_BIT.BIT3
# define READ_PG4 PING_BIT.BIT4
# define READ_PG5 PING_BIT.BIT5
# define READ_PG6 PING_BIT.BIT6
# define READ_PG7 PING_BIT.BIT7
# define PING_0 PING_BIT.BIT0
# define PING_1 PING_BIT.BIT1
# define PING_2 PING_BIT.BIT2
# define PING_3 PING_BIT.BIT3
# define PING_4 PING_BIT.BIT4
# define PING_5 PING_BIT.BIT5
# define PING_6 PING_BIT.BIT6
# define PING_7 PING_BIT.BIT7
#endif
#endif |