找回密码
 立即注册

第六集 I/O输入输出

国学芯用 2025-6-24 15:46 | 分类: Ai8051U | 播放次数:66 |点赞 0

上一条: 第五集 C语言基础 下一条: 第七集 定时器中断
< 按“左方向键”切换 按“右方向键”切换 >

评论区

全部评论共1条评论

熊能

2025-9-26 09:07

什么是GPIO(通用输入/输出端口) 按键输入检测 按键消抖程序 #include "AI8051U.h" #include "stc32_stc8_usb.h" #include "stdio.h" #include "intrins.h" typedef unsigned char u8; typedef unsigned int u16; typedef unsigned long u32; #define MAIN_Fosc 24000000UL char *USER_DEVICEDESC = NULL; char *USER_PRODUCTDESC = NULL; char *USER_STCISPCMD ="@STCISP#" void delay_ms(u8 ms); void main(void) { WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快 P_SW2 |= EAXFR; //扩展寄存器(XFR)访问使能 CKCON = 0; //提高访问XRAM速度 P0M1 = 0x00; P0M0 = 0xff; //设置为推挽输出 P1M1 = 0x00; P1M0 = 0x00; //设置为准双向口 P2M1 = 0x00; P2M0 = 0x00; //设置为准双向口 P3M1 = 0x00; P3M0 = 0x00; //设置为准双向口 P4M1 = 0x00; P4M0 = 0x00; //设置为准双向口 P5M1 = 0x00; P5M0 = 0x00; //设置为准双向口 P6M1 = 0x00; P6M0 = 0x00; //设置为准双向口 P7M1 = 0x00; P7M0 = 0x00; //设置为准双向口 usb_init(); //USB CDC 接口配置 IE2|=0x80; EA = 1; while(DeviceState != DEVICE_CONFIGURED); P40 = 0; //LED Power On while(1) { if(bUsbOutReady){ usb_OUT_done(); } if(P32 == 0){ Delay20ms(); if(P32 ==0){ state =!state; P00 = state; printf("state:%d",(int)state); while(P32==0); } } } } void delay_ms(u8 ms) { u16 i; do{ i = MAIN_Fosc / 6000; while(--i); }while(--ms); }

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-10-16 03:33 , Processed in 0.046335 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回顶部