麦丽素 发表于 2025-2-12 17:05:56

Ai8051U创新风格库函数学习打卡

打卡第一集I/O口模式设置


#include <AI8051U.H>
#include "set_int.h"
#include "set_io.h"
#include "intrins.h"

void Delay1ms(void)        //@40.000MHz
{
        unsigned long edata i;

        _nop_();
        _nop_();
        _nop_();
        i = 9998UL;
        while (i) i--;
}

void   main(void)
{
        EAXFR=1;
    CKCON =0;
        WTST =0;
        set_io_mode(pu_mode, Pin40, Pin00, Pin01, Pin02, Pin03,Pin_End);
        P40=0;
    set_io_mode(hz_mode, Pin32, Pin33,Pin34,Pin35, Pin_End);            
    set_io_mode(en_pur, Pin32,Pin33,Pin34,Pin35, Pin_End);
        Delay1ms( );
        set_int_mode(falling_edge_mode,Int0,Int1,Int_End);
       
        EA=1;
       
    while(1)       
        {
                if (get_int_state(INT0))
      {
            P00 = ~P00;
      }
                if (get_int_state(INT1))
                        {       
                       P01 = ~P01;        
                        }
      P02 =P34;
                P03= P35;
                }
        }



麦丽素 发表于 2025-2-14 16:47:23

第二集所有io口都支持的外部中断

#include <AI8051U.H>
#include "io_int.h"
#include "set_io.h"
#include "set_uart.h"


void main (void)
{
      EAXFR = 1 ;   
      CKCON = 0 ;   
      WTST = 0 ;   
      
      set_io_mode(hz_mode,Pin32,Pin33,Pin36,Pin_End);
      
      set_io_mode(en_pur,Pin32,Pin33,Pin36,Pin_End);
      
      set_io_mode(pp_mode,Pin37,Pin_End);
      
      
      set_ioint_mode(falling_edge_mode,Pin32,Pin_End);
      
      set_ioint_mode(rising_edge_mode,Pin33,Pin_End);         
    set_ioint_mode(en_int,Pin32,Pin33,Pin_End);   
      
      
      set_uart_mode(Uart1,"115200bps",Use_Timer2,Base_8b,"64byte", Uart1_P36_7,Uart_End);
         
      
      EA = 1;
    while(1)
               
{
      
      if(get_ioint_state(Pin32))
      {
      uart_printf(Uart1,"P32 Click\r\n");
      }
      if(get_ioint_state(Pin33))
      {
                uart_printf(Uart1,"P33 Click\r\n");
      
      }
}



}

麦丽素 发表于 2025-2-20 16:26:45

打卡第三集24位定时器


#include <AI8051U.H>
#include "set_io.h"
#include "set_timer.h"

void main(void)
{
      EAXFR = 1;
      CKCON = 0; //设置访问片内扩展XDATA部分速度为最快
      WTST =0;      //设置取程序代码不等待,以最快速度运动
      
      //初始化代码
      //P40设置为准双向口,同时设置为低电平
         set_io_mode(pu_mode,Pin40,Pin00,Pin01,Pin02,Pin03,Pin_End);
         P40 = 0;
      //设置P00~P05 I/O口为准双向口
         //set_timer_fosc(11059200UL);
         set_timer_mode(Timer0,"0.5s",Timer_End);
         set_timer_mode(Timer1,Timer_End);
         set_timer_mode(Timer2,"200ms",Timer_End);
         set_timer_mode(Timer3,"10hz",Timer_End);
         set_timer_mode(Timer4,"2s",Timer_End);
         set_timer_mode(Timer11,"300ms",Timer_End);

      //设置定时0为0.5s,定时器1为1S,定时器2为200ms,定时器3为10Hz
      //定时器4为2S,定时器11为300ms,
      //初始化定时器,让P00每隔1S闪烁一次,p01每隔0.5S闪烁一次
      
         EA = 1;
while(1)
{
         //循环执行代码
         //检测定时器是否中断
         //对LED对应的IO口进行取反
         if(get_timer_state(Timer0))//1s改变一次
         {
                P00 = ~P00;
         }
         if(get_timer_state(Timer1))//0.5s改变一次
         {
                P01 = ~P01;
         }
         if(get_timer_state(Timer2))
         {
                P02 = ~P02;
         }               
               if(get_timer_state(Timer3))
         {
                P03 = ~P03;
         }
               if(get_timer_state(Timer4))
         {
                P04 = ~P04;
   }
         if(get_timer_state(Timer11))
         {
                P05 = ~P05;
         }
}
}

页: [1]
查看完整版本: Ai8051U创新风格库函数学习打卡