新力量 发表于 2025-2-12 16:57:17

AI8051U库函数学习打卡

第一集:I/O口模式设置,传统外部中断




#include "AI8051U.h"
#include "io_int.h"
#include "set_io.h"
void main(void)
{

    EAXFR = 1;
    WTST = 0;
    CKCON = 0;
   
    P40 = 0;
   
    set_io_mode(pp_mode, Pin02, Pin04, Pin07, Pin40, Pin_End);
    set_io_mode(pdr_mode, Pin00, Pin01, Pin_End);            
    set_io_mode(pur_mode, Pin34, Pin_End);                     
   
    set_ioint_mode(down_edge_mode, Pin34, Pin_End);
    set_ioint_mode(en_int, Pin34, Pin_End);         
    EA = 1;

    P0 = 0x00;
   
    while (1)
    {
      if (get_ioint_satae(Pin34))
      {
            P0 = ~P0;
      }
    }
}


新力量 发表于 2025-2-13 17:11:44

第二集:所有普通IO口都支持的外部中断


#include "AI8051U.h"
#include "set_int.h"   
#include "set_io.h"   
#include "set_timer.h"
void main(void)
{
    EAXFR = 1;
    WTST = 0;
    CKCON = 0;
   
    P40 = 0;

    set_io_mode(pp_mode, Pin40, Pin_End);
    set_io_mode(pu_mode, Pin00, Pin01, Pin02, Pin32, Pin33, Pin_End);
    set_int_mode(down_edge_mode, Int0, Int1, Int_End);
    set_timer_mode(freq_hz_mode, Timer0, 1.0f);
   
    EA = 1;
    while (1)
    {
      
      if (get_int_state(Int0))
            P00 = ~P00; // 如果INT0中断,则翻转P00电平
      if (get_int_state(Int1))
            P01 = ~P01; // 如果INT1中断,则翻转P01电平
      if (get_timer_state(Timer0))
            P02 = ~P02; // 对应IO口上的LED灯1S变化一次
    }
}




页: [1]
查看完整版本: AI8051U库函数学习打卡