資源簡介
在IAR環境中,用庫函數實現STM8S003單片機的模擬串口功能,用普通IO口作為串口,可以通過中斷方式接收數據,也可以通過查詢方式接收數據。9600波特率測試。

代碼片段和文件信息
#include?“bsp.h“
#include?“stdio.h“
//#define????SIM_UART_WAIT??1?????????//?如果需要查詢方式接收?取消屏蔽
void?main(?void?)
{
????u8?i?=?0;
????//ASCII碼字符串??注意?“?要用轉義字符
????char?str_ASCII[100]?=?“?!\“#$%&‘()*+-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_‘abcdefghijklmnopqrstuvwxyz{|}~“;
????disableInterrupts();
????BSP_Initializes();
????enableInterrupts();
????TIM4_Nms(?100?);
????WriteString(“simulate?URAT\r\n“);
????while(?1?)
????{
#if?defined(SIM_UART_WAIT)
???????//==============查詢方式接收數據========================//
????????GPIOB->CR2&=~(1<<4);????????????????//禁止PB4外部中斷
????????ReadString();???????????????????????//查詢方式接收
???????//======================================================//
#else
???????//-------------------中斷方式接收數據--------------------//
????????if(?recEnd?==?0x03?)??????????//判斷數據是否接收完成
????????{
????????????WriteString(?recBUFF?);
????????????recEnd?=?0x00;
????????????for(?i?=?0;?i?100;?i++?)?//清空發送緩沖區
????????????{
????????????????recBUFF[i]?=?0;
????????????}
????????}
#endif
???????//------------------------------------------------------//
????????if(?1?==?time4_Flag?)
????????{
????????????//定時發送數據
????????????//WriteByte(?i?);
????????????//WriteString(?str_ASCII?);
????????????//WriteString(?“\r\n“?);
????????????time4_Flag?=?0;
????????????LED_REVERSE;
????????????TIM4_Nms(?100?);
????????}
????}
}
/*斷言函數:它的作用是在編程的過程中為程序提供參數檢查*/
#ifdef?USE_FULL_ASSERT
void?assert_failed(?u8*?file?u32?line?)
{
????/*?User?can?add?his?own?implementation?to?report?the?file?name?and?line?number
????ex:?printf(“Wrong?parameters?value:?file?%s?on?line?%d\r\n“?file?line)?*/
????/*?Infinite?loop?*/
????while(?1?)
????{
????}
}
#endif
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1837??2018-02-06?09:32??STM8S_IR_SimUart\App\main.c
?????文件???????1527??2018-02-05?15:54??STM8S_IR_SimUart\App\main.c.orig
?????文件???????4957??2018-01-20?15:33??STM8S_IR_SimUart\App\stm8s_conf.h
?????文件??????14704??2018-02-05?14:41??STM8S_IR_SimUart\App\stm8s_it.c
?????文件???????5951??2014-10-22?00:31??STM8S_IR_SimUart\App\stm8s_it.h
?????文件???????1294??2018-02-05?11:06??STM8S_IR_SimUart\Bsp\bsp.c
?????文件????????595??2018-02-05?11:06??STM8S_IR_SimUart\Bsp\bsp.h
?????文件???????2313??2018-01-20?17:13??STM8S_IR_SimUart\Bsp\delay.c
?????文件????????376??2018-01-20?17:16??STM8S_IR_SimUart\Bsp\delay.h
?????文件????????137??2018-01-22?14:02??STM8S_IR_SimUart\Bsp\led.c
?????文件????????523??2018-01-26?11:06??STM8S_IR_SimUart\Bsp\led.h
?????文件???????5139??2018-02-05?17:32??STM8S_IR_SimUart\Bsp\sim_uart.c
?????文件????????744??2018-02-05?14:40??STM8S_IR_SimUart\Bsp\sim_uart.h
?????文件????????847??2018-02-03?09:35??STM8S_IR_SimUart\Bsp\timer4_it.c
?????文件????????242??2018-02-03?09:33??STM8S_IR_SimUart\Bsp\timer4_it.h
?????文件??????????3??2018-01-20?16:29??STM8S_IR_SimUart\BuildLog.log
?????文件??????17975??2018-01-24?09:31??STM8S_IR_SimUart\Debug\Exe\ADC.hex
?????文件??????10131??2018-01-29?10:05??STM8S_IR_SimUart\Debug\Exe\eeprom.hex
?????文件???????8216??2018-01-30?09:12??STM8S_IR_SimUart\Debug\Exe\exti.hex
?????文件??????10131??2018-01-29?11:03??STM8S_IR_SimUart\Debug\Exe\flash.hex
?????文件??????20315??2018-02-03?08:55??STM8S_IR_SimUart\Debug\Exe\iic.hex
?????文件??????16727??2018-02-03?16:21??STM8S_IR_SimUart\Debug\Exe\ir_remote.hex
?????文件???????8719??2018-01-29?14:03??STM8S_IR_SimUart\Debug\Exe\iwdg.hex
?????文件???????3211??2018-01-22?14:37??STM8S_IR_SimUart\Debug\Exe\KEY.hex
?????文件??????89744??2018-02-06?15:47??STM8S_IR_SimUart\Debug\Exe\SimUart.out
?????文件???????4651??2018-02-06?15:47??STM8S_IR_SimUart\Debug\Exe\sim_uart.hex
?????文件???????2775??2018-01-23?11:50??STM8S_IR_SimUart\Debug\Exe\TIM.hex
?????文件??????19716??2018-01-26?14:21??STM8S_IR_SimUart\Debug\Exe\tim1_pwm.hex
?????文件???????6367??2018-01-23?15:04??STM8S_IR_SimUart\Debug\Exe\UART.hex
?????文件???????8705??2018-01-29?14:51??STM8S_IR_SimUart\Debug\Exe\wwdg.hex
............此處省略143個文件信息
評論
共有 條評論