- 打卡等级:初来乍到
- 打卡总天数:4
- 最近打卡:2025-03-10 13:37:48
版主
- 积分
- 357
|
发表于 2025-2-18 11:22:06
|
显示全部楼层
第四集 串口部分库函数
1、学习截图
实验箱这边要拨断,否则出不来现象。
2、主要代码
#include <AI8051U.H>
#include "io_int.h"
#include "set_io.h"
#include "set_uart.h"
#include "stdio.h"
int num = 0;
char str[5] = {'a','b','c','d','e'};
void main(void)
{
EAXFR = 1;
CKCON = 0;
WTST = 0;
set_io_mode(pu_mode,Pin36,Pin37,Pin42,Pin43,Pin_End);
set_uart_mode(Uart1, "115200bps", Uart1_P36_7, Use_Timerx, Uart_End);
set_uart_mode(Uart2, Uart2_P42_3, "9600bps", Use_Timerx, Uart_End);
set_io_mode(hz_mode, Pin34, Pin_End);
set_io_mode(en_pur, Pin34, Pin_End);
set_ioint_mode(falling_edge_mode, Pin34, Pin_End);
set_ioint_mode(en_int, Pin34, Pin_End);
EA = 1;
while(1)
{
if(get_ioint_state(Pin34))
{
uart_printf(Uart1, "uart1,hello!\r\n");
uart_printf(Uart2, "uart2,hello!\r\n");
}
if(get_uart_state(Uart1))
{
sscanf(_uart1_rx_buff, "num:%d", &num);
uart_printf(Uart1, "this_num:%d\r\n",num);
uart_printf(Uart2, Buff_Mode, str, 5);
}
}
}
uart.zip
(138.51 KB, 下载次数: 12)
|
|