STC8954RD 串口接收
#include
#include
#include
#include void InitCOM(void) { #if 1 SCON = 0x50; //8bit TMOD = 0x20; //timer1 mode 2 PCON = 0x00; //SMOD=1, double baud TL1 = 0xFD; TH1 = 0xFD; //Baud = 9600, 11.0592MHz //IE |= 0x90; //Serail break enable TR1 = 1; //timer1 start ES = 0; EA = 0; //disable interrupt #else SCON = = 0x50; TH2 = 0XFF; TL2 = 0xFD //baud = 115200, 11.0592MHz RCAP2H = 0xFF; RCAP2L = 0xFD; // TCLK = 1; RCLK = 1; C-T2 = 0; TR2 = 1; #endif } void COMPutc(char cdata) { SBUF = cdata; while(!TI); TI = 0; } void COMWrite(char* str) { while(*str) COMPutc(*str++); } void COMWriteNum(int num, char* str) { char d[32]; sprintf(d, "%s:%d\n", str, num); COMWrite(d); } char COMGetc(void) { char temp; while(!RI); temp = SBUF; RI = 0; return temp; } void COMRead(char* str, unsigned char length) { unsigned char i = 0; for(i = 0; i < length; i++) { str[i] = COMGetc(); } } void COMReadEnter(char* str) { char temp; do { //Delay(1); //COMWrite("\ndata\n"); temp = COMGetc(); *str=temp; //COMPutc(temp); str++; }while(temp!=\n && temp!=\r); *str = \0; } bit COMReadTimeout(char* str, unsigned char length, unsigned int timeout) { unsigned char i = 0; unsigned int count = 0; for(i = 0; i < length; i++) { count = 0; while(RI == 0) { count++; Delay(2); if (count > timeout) return 1; } str[i] = SBUF; } return 0; } bit COMReadEnterTimeout(char* str, unsigned int timeout) { unsigned int count; char temp; do { count =0; while(!RI) { count++; _nop_(); _nop_(); if(count>timeout) return 1; } temp = SBUF; *str = temp; str++; RI=0; }while(temp!=\n && temp!=\r); *str=\0; return 0; } void main() { char comread[20]; char flag = 1; InitCOM(); COMWriteNum(flag, "flag"); COMWrite("Begin\n"); do { COMWrite("Whileloop\n"); COMReadEnter(comread); COMWrite(comread); if(strstr(comread, "QUIT"))flag = 0; else flag =1; COMWriteNum(flag, "flag"); }while(flag != 0); } //针对超时函数的Debug function /* void main() { char comread[20]; char flag = 1; char timeout = 0; InitPort(); InitCOM(); COMWriteNum(flag, "flag"); COMWrite("Begin\n"); do { do { COMWrite("keyinCommand\n"); timeout=COMReadEnterTimeout(comread,0xDfff); }while(timeout); //COMReadEnter(comread); COMWrite(comread); if(strstr(comread, "QUIT"))flag = 0; else flag =1; COMWriteNum(flag, "flag"); }while(flag != 0); }*/
//初始化串口
//写串口
//读取串口
//添加两读取超时函数
//debug 主函数
Program Size: data=161.0 xdata=0 code=9892
Target not created
此为data溢出,而xdata却为0
因此可以再定义参数时适当的将部分参数移入xdata中
如 xdata charcomread[20];
STC8954RD串口接 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)