找回密码
 立即注册
查看: 214|回复: 1

AI8051U库函数学习打卡

[复制链接]
  • 打卡等级:偶尔看看I
  • 打卡总天数:13
  • 最近打卡:2025-04-27 09:58:37

8

主题

37

回帖

367

积分

版主

积分
367
发表于 2025-2-12 16:48:17 | 显示全部楼层 |阅读模式
第一集:I/O口模式设置,传统外部中断【INT0, INT1, INT2, INT3, INT4】
截图202502121646455012.jpg

#include "AI8051U.h"
#include "io_int.h" //设置IO中断的库函数,会依赖set_io.h
#include "set_io.h" //设置IO模式的库函数,可以阅读H文件中的详细说明,或者直接看以下例程的使用

/*
使用说明:
效果应该是P02、P04、P07口亮起,P00,001微微亮。
按一次试验箱上的P34按键就会对原来LED的状态取反。
*/

void main(void)
{

    EAXFR = 1; // 允许访问扩展寄存器
    WTST = 0;
    CKCON = 0;
    // AI8051U试验箱所需配置
    P40 = 0; // 打开试验箱LED电源供电
    // set_io.h 函数使用例程
    set_io_mode(pp_mode, Pin02, Pin04, Pin07, Pin40, Pin_End); // 设置P02,P04,P07,P40为推挽输出模式
    set_io_mode(en_pdr, Pin00, Pin01, Pin_End);              // 设置P00,P01为下拉电阻开启
    set_io_mode(en_pur, Pin34, Pin_End);                     // 设置P34按键的上拉电阻开启
    // 最后一个参数必须是Pin_End,否则函数无法停止解析,Pin_End是结束标志
    // 变长函数,可以设定任意数量的引脚

    // io_int.h 函数使用例程
    set_ioint_mode(falling_edge_mode, Pin34, Pin_End); // 设置P34为下降沿中断模式
    set_ioint_mode(en_int, Pin34, Pin_End);         // 打开P34的IO口中断
    EA = 1;                                         // 打开总中断

    P0 = 0x00;
    // 让P0口的测试LED亮起来,这里使用AI8051U试验箱测试
    // 实际效果应该是P02、P04、P07口亮起,P00,001微微亮
    while (1)
    {
        if (get_ioint_state (Pin34))
        {
            P0 = ~P0; // 翻转P0的值,按一次试验箱上的P34按键就会完成一次亮/灭切换
        }
    }
}




回复

使用道具 举报 送花

  • 打卡等级:偶尔看看I
  • 打卡总天数:13
  • 最近打卡:2025-04-27 09:58:37

8

主题

37

回帖

367

积分

版主

积分
367
发表于 2025-2-13 16:58:36 | 显示全部楼层
第二集所有普通I/O口都支持的外部中断
截图202502131653477286.jpg

#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(falling_edge_mode, Int0, Int1, Int_End);
    set_timer_mode(Timer0, Timer_End);
    et_timer_state查询即可
    EA = 1;
    while (1)
    {
        
        if (get_int_state(Int0))
            P00 = ~P00;
        if (get_int_state(Int1))
            P01 = ~P01;
        if (get_timer_state(Timer0))
            P02 = ~P02;
    }
}

回复 支持 反对

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-4 09:58 , Processed in 0.113070 second(s), 54 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表