/*------------------------------------------------------------------------------------- PICC菜鸟玩PICC位变量潇洒走一回 HotPower@126.com 2004.10.31 于西安大雁塔村队部 --------------------------------------------------------------------------------------*/ #include <pic.h>
typedef struct { unsigned BIT0: 1; unsigned BIT1: 1; unsigned BIT2: 1; unsigned BIT3: 1; unsigned BIT4: 1; unsigned BIT5: 1; unsigned BIT6: 1; unsigned BIT7: 1; }PICCBIT;//定义一个只能按位域寻址的新变量类型
typedef union { PICCBIT BIT;//可以按位域寻址 unsigned char BYTE;//可以按字节寻址 }PICCBITBYTE;//定义一个既能按位域寻址也可按字节寻址的新变量类型
//定义特殊寄存器位类型 PICCBITBYTE SystemGPIO @((unsigned)&PORTA);//重新说明PORTA为新变量类型PICCBITBYTE名称为SystemGPIO PICCBITBYTE SystemTRISIO @((unsigned)&TRISA);//重新说明TRISA为新变量类型PICCBITBYTE名称为SystemTRISIO
//定义绝对定位寄存器位类型 PICCBITBYTE myvars @(unsigned)0x25;//申请新变量类型PICCBITBYTE名为myvars,并绝对定位在bank0的0x25处 PICCBIT myvar @((unsigned bank1) 0x80+0x25);//申请新变量类型PICCBIT名为myvar,并绝对定位在bank1的0x25处
//定义任意寄存器位类型 PICCBIT myvarbit;//申请一个新变量类型PICCBIT名称为myvarbit,地址由PICC自动定位 PICCBITBYTE myvarbyte;//申请一个新变量类型PICCBITBYTE名称为myvarbyte,地址由PICC自动定位
#define GPIO0 SystemGPIO.BIT.BIT0 //同PORTA0 #define GPIO1 SystemGPIO.BIT.BIT1 //同PORTA1 #define GPIO2 SystemGPIO.BIT.BIT2 //同PORTA2 #define GPIO3 SystemGPIO.BIT.BIT3 //同PORTA3 #define GPIO4 SystemGPIO.BIT.BIT4 //同PORTA4 #define GPIO5 SystemGPIO.BIT.BIT5 //同PORTA5 #define GPIO6 SystemGPIO.BIT.BIT6 //同PORTA6 #define GPIO7 SystemGPIO.BIT.BIT7 //同PORTA7
#define TRISIO0 SystemTRISIO.BIT.BIT0 //同TRISA0 #define TRISIO1 SystemTRISIO.BIT.BIT1 //同TRISA1 #define TRISIO2 SystemTRISIO.BIT.BIT2 //同TRISA2 #define TRISIO3 SystemTRISIO.BIT.BIT3 //同TRISA3 #define TRISIO4 SystemTRISIO.BIT.BIT4 //同TRISA4 #define TRISIO5 SystemTRISIO.BIT.BIT5 //同TRISA5 #define TRISIO6 SystemTRISIO.BIT.BIT6 //同TRISA6 #define TRISIO7 SystemTRISIO.BIT.BIT7 //同TRISA7
#define myvars0 myvars.BIT.BIT0 //myvars.0 #define myvars1 myvars.BIT.BIT1 //myvars.1 #define myvars2 myvars.BIT.BIT2 //myvars.2 #define myvars3 myvars.BIT.BIT3 //myvars.3 #define myvars4 myvars.BIT.BIT4 //myvars.4 #define myvars5 myvars.BIT.BIT5 //myvars.5 #define myvars6 myvars.BIT.BIT6 //myvars.6 #define myvars7 myvars.BIT.BIT7 //myvars.7
#define myvar0 myvar.BIT0 //myvar.0 #define myvar1 myvar.BIT1 //myvar.1 #define myvar2 myvar.BIT2 //myvar.2 #define myvar3 myvar.BIT3 //myvar.3 #define myvar4 myvar.BIT4 //myvar.4 #define myvar5 myvar.BIT5 //myvar.5 #define myvar6 myvar.BIT6 //myvar.6 #define myvar7 myvar.BIT7 //myvar.7
#define myvarbit0 myvarbit.BIT0 //myvarbit.0 #define myvarbit1 myvarbit.BIT1 //myvarbit.1 #define myvarbit2 myvarbit.BIT2 //myvarbit.2 #define myvarbit3 myvarbit.BIT3 //myvarbit.3 #define myvarbit4 myvarbit.BIT4 //myvarbit.4 #define myvarbit5 myvarbit.BIT5 //myvarbit.5 #define myvarbit6 myvarbit.BIT6 //myvarbit.6 #define myvarbit7 myvarbit.BIT7 //myvarbit.7
#define myvarbyte0 myvarbyte.BIT.BIT0 //myvarbyte.0 #define myvarbyte1 myvarbyte.BIT.BIT1 //myvarbyte.1 #define myvarbyte2 myvarbyte.BIT.BIT2 //myvarbyte.2 #define myvarbyte3 myvarbyte.BIT.BIT3 //myvarbyte.3 #define myvarbyte4 myvarbyte.BIT.BIT4 //myvarbyte.4 #define myvarbyte5 myvarbyte.BIT.BIT5 //myvarbyte.5 #define myvarbyte6 myvarbyte.BIT.BIT6 //myvarbyte.6 #define myvarbyte7 myvarbyte.BIT.BIT7 //myvarbyte.7
void main(void) { //PICCBITBYTE的新变量类型可以按字节寻址,故myvarbyte可以用myvarbyte.BYTE赋值 myvarbyte.BYTE = 0x55; //myvarbit = 0;//PICCBIT新变量类型只能按位域寻址,所以myvarbit不能清零! //myvar = 0;//PICCBIT新变量类型只能按位域寻址,所以myvar不能清零! GPIO0 = 0; TRISA0 = 1; GPIO1 = 0; TRISIO0 = 1; myvar0 = 1; myvars0 = 1; myvarbyte.BIT.BIT0 = 1; myvarbyte0 = 0; myvarbit.BIT0 = 0; myvarbit0 = 0; SystemGPIO.BYTE = 0xaa;//以用SystemGPIO.BYTE赋值 SystemTRISIO.BYTE = 0x55;//以用SSystemTRISIO.BYTE赋值 while(1); }
|
|
文章评论(0条评论)
登录后参与讨论