資源簡介
在IAR環境中,用STM8S003單片機PC3、PC4口模擬串口收發數據,支持查詢接收和中斷接收。

代碼片段和文件信息
#include?“iostm8s103F3.h“
#include?“main.h“
#include?“delay.h“
#include?“myuart.h“
extern??unsigned?char?recEnd;
extern??unsigned?char?recBUFF[100];
void?SysClkInit(?void?)
{
????CLK_SWR?=?0xe1;??????????????????//HSI為主時鐘源??16MHz?CPU時鐘頻率
????CLK_CKDIVR?=?0x00;???????????????//CPU時鐘0分頻,系統時鐘0分頻
}
u8?command?=?0;
u8?powerH?=?0;
u8?powerL?=?0;
void?send_data(?void?)
{
????SendChar(?0xA5?);
????SendChar(?0x5A?);
????SendChar(?0x00?);???????????//?地址
????SendChar(?command?);????????//?高四位為電源狀態??低四位為?發送的命令值
????SendChar(?powerH?);?????????//?功率高位
????SendChar(?powerL?);?????????//?功率低位
????SendChar(?0x55?);
????SendChar(?0xAA?);
}
void?main(?void?)
{
????unsigned?int?t?=?0?i?=?0;
????__asm(?“sim“?);?????????????????????????????//禁止中斷
????SysClkInit();
????delay_init(?16?);
????MyUart_Init();
????__asm(?“rim“?);??????????????????????????????//開啟中斷
????
????WriteString(“start!“);
????while(?1?)
????{
??????delay_ms(1);
??????i++;
??????if(i>2000)
??????{
????????i=0;
????????WriteString(?“0123456789?abcdefghijklmnopqrstuvwxyz?ABCDEFGHIJKLMNOPQRSTUVWXYZ?“?);
??????}
????????
//??????ReadString();????????//查詢方式接收
????????
????????if(?recEnd?==?0x03?)???//判斷數據是否接收完成
????????{
????????????WriteString(?recBUFF?);
????????????recEnd?=?0x00;
????????????for(?i?=?0;?i?100;?i++?)?//清空發送緩沖區
????????????{
????????????????recBUFF[i]?=?0;
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-10-11?16:37??STM8S_Sim_Uart\
?????文件????????2397??2018-05-15?14:52??STM8S_Sim_Uart\BuildLog.log
?????目錄???????????0??2018-10-11?16:34??STM8S_Sim_Uart\Debug\
?????目錄???????????0??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Exe\
?????文件???????43820??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Exe\power_soft.out
?????文件????????3888??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Exe\sim_uart.hex
?????目錄???????????0??2018-10-11?16:37??STM8S_Sim_Uart\Debug\List\
?????文件???????15669??2018-10-11?16:37??STM8S_Sim_Uart\Debug\List\power_soft.map
?????目錄???????????0??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\
?????文件????????8942??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\delay.o
?????文件????????1718??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\delay.pbi
?????文件???????11831??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\delay.pbi.xcl
?????文件???????16636??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\led.o
?????文件???????11829??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\led.pbi.xcl
?????文件???????11676??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\main.o
?????文件??????228056??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\main.pbi
?????文件???????11721??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\main.pbi.xcl
?????文件???????27133??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\myuart.o
?????文件??????229741??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\myuart.pbi
?????文件???????11832??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\myuart.pbi.xcl
?????文件??????232696??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\Sim_Uart.pbd
?????文件??????232696??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\Sim_Uart.pbd.browse
?????文件?????????194??2018-10-11?16:37??STM8S_Sim_Uart\Debug\Obj\Sim_Uart.pbd.linf
?????文件???????11830??2018-10-11?16:33??STM8S_Sim_Uart\Debug\Obj\uart.pbi.xcl
?????目錄???????????0??2018-10-11?16:35??STM8S_Sim_Uart\HardWare\
?????文件????????2315??2018-08-04?09:57??STM8S_Sim_Uart\HardWare\delay.c
?????文件?????????375??2018-05-29?14:27??STM8S_Sim_Uart\HardWare\delay.h
?????文件????????4720??2018-10-11?16:21??STM8S_Sim_Uart\HardWare\myuart.c
?????文件?????????407??2018-10-11?14:18??STM8S_Sim_Uart\HardWare\myuart.h
?????文件????????1598??2018-10-11?16:37??STM8S_Sim_Uart\main.c
?????文件????????1797??2018-10-11?13:39??STM8S_Sim_Uart\main.c.orig
............此處省略29個文件信息
評論
共有 條評論