学习AI8051U单片机
学习地址:https://www.stcaimcu.com/forum.php?mod=viewthread&tid=11902学习第一集:序言
从本节课里学习认识了AI8051U的强大功能 。特别是屏幕显示功能,可以满足我的需求。
必须点赞 第二集,学习硬件及编程工具安装
这集认识了实验箱的各个部件,然后跟老师学习并安装了开发软件
第三集,点亮第一个LED灯
#include "ai805lu.h"//调用头文件
void main(void)
{
P0M0=0;//P0端口(P00-P07)为准双向口
P0M1=0;
P4M0= 0;//P4端口为准双向口
P4M1 =0;
while(1)
P40=0; //P40端缠出0V
P00=0;//P00端缠出0V
}
第四集:USB不停电下载
#include "ai805lu.h"//调用头文件
#include "stc32_stc8_usb.h"
char *USER_DEVICEDESC =NULL;
char *USER_PRODUCTDESC=NULL;
char *USER_STCISPCMD="@STCISP#";
void main(void)
{
P_SW2 |= 0x80;//B7位写1,使能访问XFR
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);
while(1)
{
if(bUsbOutReady)
{
USB_SendData(UsbOutBuffer,Outlumber);
usb_OUT_done ();
}
P40=0; //P40端输出0V
P00=0;//P00端输出0V
}
}
第五集,C语言基础知识
第六集: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);
}
}
}
第七集:定时器中断
代码太多,截图一部分重要的吧,等申请到了箱子再实验一下。
页:
[1]