擎天柱学习:《8051U深度入门到32位51大型实战教学视频》,打卡
第三集 点亮第一个LED#include "ai8051u.h"
void main(void)
{
P2M0 = 0;
P2M1 = 0;
while(1)
{
P20 = 0;
P21 = 0;
P22 = 0;
P23 = 0;
P24 = 0;
P25 = 0;
P26 = 0;
P27 = 0;
}
}
第四集 不停电下载
466
#include "ai8051u.h"
#include "stc32_stc8_usb.h"
char *USER_DEVICEDESC = NULL;
char *USER_PRODUCTDESC = NULL;
char *USER_STCISPCMD = "@STCISP#";
void main(void)
{
P_SW2 |= 0x80;
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,OutNumber);
usb_OUT_done();
}
P20 = 0;
P21 = 0;
P22 = 0;
P23 = 0;
P24 = 0;
P25 = 0;
P26 = 0;
P27 = 0;
}
}
第五集 使用【Ai8051U】擎天柱核心板—— C语言基础
代码如下:
#include "ai8051u.h"
#include "stc32_stc8_usb.h"
#define u8unsigned char
#define u16 unsigned int
u8 X = 200;
u8 Y = 10;
char *USER_DEVICEDESC = NULL;
char *USER_PRODUCTDESC = NULL;
char *USER_STCISPCMD = "@STCISP#";
void main(void)
{
P_SW2 |= 0x80;
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,OutNumber);
if( X && Y )
{
printf("条件为真\r\n");
}
else
{
printf("条件为假\r\n");
}
printf("X / Y = %u \r\n",(u16)(X/Y));
printf("X %% Y = %u \r\n",(u16)(X%Y));
usb_OUT_done();
}
}
}
第六集、使用【Ai8051U】擎天柱核心板——IO口输入输出
任务一:按下P32按钮灯亮,松开P32按钮灯灭
#include "ai8051u.h"
#include "stc32_stc8_usb.h"
#include "intrins.h"
#define u8unsigned char
#define u16 unsigned int
u8 state = 0;
char *USER_DEVICEDESC = NULL;
char *USER_PRODUCTDESC = NULL;
char *USER_STCISPCMD = "@STCISP#";
void Delay20ms(void) ;
{
unsigned long edata i;
_nop_();
_nop_();
i = 119998UL;
while (i) i--;
}
void main(void)
{
WTST = 0;
EAXFR = 1;
CKCON = 0;
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,OutNumber);
usb_OUT_done();
}
//任务1:按下P32按钮灯亮,松开P32按钮灯灭;
if( P32 == 0 )
{
P20 = 0;
}
else
{
P20 = 1;
}
482
任务二:任务2:按下P32按钮灯灭,松开P32按钮灯亮
#include "ai8051u.h"
#include "stc32_stc8_usb.h"
#include "intrins.h"
#define u8unsigned char
#define u16 unsigned int
u8 state = 0;
char *USER_DEVICEDESC = NULL;
char *USER_PRODUCTDESC = NULL;
char *USER_STCISPCMD = "@STCISP#";
void Delay20ms(void) //@24.000MHzDelay20ms();
{
unsigned long edata i;
_nop_();
_nop_();
i = 119998UL;
while (i) i--;
}
void main(void)
{
WTST = 0;
EAXFR = 1;
CKCON = 0;
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,OutNumber);
usb_OUT_done();
}
//任务2:按下P32按钮灯灭,松开P32按钮灯亮;
if( P32 == 1 ) //判断P32按钮是否按下
{
P20 = 0;
}
else
{
P20 = 1;
}483
任务三:按一下灯亮,按一下灯灭
#include "ai8051u.h"
#include "stc32_stc8_usb.h"
#include "intrins.h"
#define u8unsigned char
#define u16 unsigned int
u8 state = 0;
char *USER_DEVICEDESC = NULL;
char *USER_PRODUCTDESC = NULL;
char *USER_STCISPCMD = "@STCISP#";
void Delay20ms(void) //@24.000MHzDelay20ms();
{
unsigned long edata i;
_nop_();
_nop_();
i = 119998UL;
while (i) i--;
}
void main(void)
{
WTST = 0;
EAXFR = 1;
CKCON = 0;
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,OutNumber);
usb_OUT_done();
}
//任务3:按一下灯亮,按一下灯灭
if( P32 == 0 ) //判断P32按钮是否按下
{
Delay20ms(); //延时20ms消抖
if( P32 == 0 )
{
state = !state; //变量取反 0 1 0 1 0 1
P20 = state;
printf("state:%d\r\n",(int)state);
while( P32 == 0 ); //等待P32松开
}
}
}
}484
页:
[1]