芯远航 发表于 2024-12-26 16:28:36

擎天柱学习:《8051U深度入门到32位51大型实战教学视频》打卡

第三集,点亮第一颗LED灯




#include "ai8051u.h"               

void main(void)
{
      P2M0 = 0;               
      P2M1 = 0;
      
      while(1)
      {
                P20 = 0;      
                P21 = 0;      
      }
}



芯远航 发表于 2024-12-28 18:11:02

第四集 ,不停电下载


#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;                                                                                        //IE |= 0X80;
      
      while (DeviceState != DEVSTATE_CONFIGURED);   
      
      while(1)
      {
               
      if (bUsbOutReady)
      {
            USB_SendData(UsbOutBuffer,OutNumber);
            
            usb_OUT_done();
      }
               
                P20 = 0;                                       
                P22 = 0;                                       

      }
}






芯远航 发表于 2024-12-30 15:06:58

第五集,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();                                                       
      }
               

        }
}


芯远航 发表于 2024-12-30 15:30:23

第六集,IO口输入输出



#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;
//                }
//               
               
                //任务2:按下P32按钮灯灭,松开P32按钮灯亮;
//                if( P32 == 1 )                                                               
//                {
//                        P20 = 0;
//                }
//                else
//                {
//                        P20 = 1;
//                }
               
                //任务3:按一下灯亮,按一下灯灭
                if( P32 == 0 )                                                               
                {
                        Delay20ms();                                                      
                        if( P32 == 0 )
                        {
                              state = !state;                                                
                              P20 = state;
                              printf("state:%d\r\n",(int)state);
                              
                              while( P32 == 0 );                                       
                              
                        }
                }
      
               
      }
}








芯远航 发表于 2024-12-30 15:44:07

第七集,定时器中断



#include "ai8051u.h"                        
#include "stc32_stc8_usb.h"               
#include "intrins.h"                        

#define u8unsigned char               
#define u16 unsigned int                        
      
u8 state = 0;                                       
u8 Run_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 Timer0_Init(void);                //3秒@24.000MHz               

void main(void)
{
      int count=1;                                                                        
      
    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;                                    
//      Timer0_Init();                                                                        
      
    EA = 1;                                                                                       
      
      P40 = 0;
      
      while (DeviceState != DEVSTATE_CONFIGURED);   
      
      while(1)
      {
               
      if (bUsbOutReady)                                                      
      {
            //USB_SendData(UsbOutBuffer,OutNumber);   
            
            usb_OUT_done();                                                      
      }
               
                //任务1:
//                if( P32 == 0 )                                                               
//                {
//                        Delay20ms();                                                      
//                        if( P32 == 0 )
//                        {
//                              printf("按键按下次数\xfd:%d 次\r\n",(int)count);
//                              count++;
//                              
//                              while( P32 == 0 );                                       
//                              
//                        }
//                }
      
//                //任务2:灯按一下点亮三秒后熄灭。
                if( P32 == 0 )                                                               
                {
                        Delay20ms();                                                      
                        if( P32 == 0 )
                        {
//                              printf("按键按下次数\xfd:%d 次\r\n",(int)count);
//                              count++;
                              P20 = 0;
                              Timer0_Init();
                              while( P32 == 0 );                                       
                              
                        }
                }

//               
                //任务3:救护车灯控制器,按下报警按钮,红蓝交替闪烁(LED1和LED2表示红和蓝灯),再按一下报警按钮,红蓝灯停止。
                if( P32 == 0 )                                                               
                {
                        Delay20ms();                                                      
                        if( P32 == 0 )
                        {
                              Run_State = !Run_State;                              
                              
                              if( Run_State==1 )                                       
                              {
                                        Timer0_Init();
                              }
                              else
                              {
                                        TR0 = 0;                                                
                                        P20 = 1;
                                        P21 = 1;
                              }
                              while( P32 == 0 );                                       
                              
                        }
                }
               
      }
}






页: [1]
查看完整版本: 擎天柱学习:《8051U深度入门到32位51大型实战教学视频》打卡