typedef struct VPin_x_Jack{ uint8_t PIT_0: 1; uint8_t PIN_1: 1; uint8_t PIN_2: 1; uint8_t PIN_3: 1; uint8_t PIN_4: 1; uint8_t PIN_5: 1; uint8_t PIN_6: 1; uint8_t PIN_7: 1; }VPINx_Jack_TypeDef; //使用结构体的位域操作,将1个字节分成8个变量(PIT_0到PIT_7)每一个变量占用一个位
typedef struct VPin_x_Jack{ uint8_t PIT_0: 1; uint8_t PIN_1: 1; uint8_t PIN_2: 1; uint8_t PIN_3: 1; uint8_t PIN_4: 1; uint8_t PIN_5: 1; uint8_t PIN_6: 1; uint8_t PIN_7: 1; }VPINx_Jack_TypeDef; typedef struct VPort_x_Jack{ VPINx_Jack_TypeDef DIR; VPINx_Jack_TypeDef OUT; VPINx_Jack_TypeDef IN; VPINx_Jack_TypeDef INTFLAGS; }VPORTx_Jack_TypeDef; #define VPORTA_Jack (*(VPORTx_Jack_TypeDef *)0x0000) #define VPORTB_Jack (*(VPORTx_Jack_TypeDef *)0x0004) #define VPORTC_Jack (*(VPORTx_Jack_TypeDef *)0x0008) #define VPORTD_Jack (*(VPORTx_Jack_TypeDef *)0x000C) #define VPORTE_Jack (*(VPORTx_Jack_TypeDef *)0x0010) #define VPORTF_Jack (*(VPORTx_Jack_TypeDef *)0x0014)
#include <avr/io.h> #include "VPORTx.h" extern protected_write_io(void *addr, uint8_t KEY,uint8_t value); static inline void System_Clock_Setting(void *addr,uint8_t value) { protected_write_io(addr,0xD8,value); } void LED_Init(void) { VPORTF_Jack.DIR.PIN_5 = 1; // PF5输出 VPORTF_Jack.OUT.PIN_5 = 1; // LED灭 } int main(void) { // 配置系统时钟为10MHZ System_Clock_Setting((void *)&(CLKCTRL.MCLKCTRLB),CLKCTRL_PDIV_2X_gc | 1 << CLKCTRL_PEN_bp); //初始化LED端口 LED_Init(); while (1) { } }
VPORTF_Jack.OUT.PIN_5 = 1; // LED灭 VPORTF_Jack.OUT.PIN_5 = 0; // LED亮
使用特权
发表回复 本版积分规则 回帖后跳转到最后一页
27
60
0
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号