- 打卡等级:初来乍到
- 打卡总天数:5
- 最近打卡:2025-02-03 18:03:50
已绑定手机
注册会员
- 积分
- 78
|
发表于 2024-12-28 21:05:09
|
显示全部楼层
第六集:IO口的输入输出
//任务1:按下P32按钮灯亮,松开P32按钮灯灭
#include "ai805lu.h"//调用头文件
#include "stc32_stc8_usb.h"
#include "intrins.h"
char *USER_DEVICEDESC =NULL;
char *USER_PRODUCTDESC=NULL;
char *USER_STCISPCMD="@STCISP#";
void Delay20ms(void) //@24.000MHz
{
unsigned char data i, j, k;
_nop_();
_nop_();
i = 2;
j = 211;
k = 231;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main(void)
{
WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
P_SW2 |= EAXFR; //扩展寄存器(XFR)访问使能
CKCON = 0; //提高访问XRAM速度
P0M1 = 0x00; P0M0 = 0x00; //设置为准双向口
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();
IE2 |= 0x80;
EA =1;
while (DeviceState !=DEVSTATE_CONFIGURED);
P40=0; //P40端输出0V
while(1)
{
if(bUsbOutReady)
{
USB_SendData(UsbOutBuffer,Outlumber);
usb_OUT_done ();
}
if(P32==0)
{
Delay20ms();
if(P32==0)
{
P0 = ~P0;
}
while(P32==0);
}
}
}
|
|