完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我编写了一个简单的程序,用于测试一些代码。我试图模拟串口上的击键字符来测试命令解析例程。我用模拟器注册表注入一个包含十进制整数的简单文本文件,用于从串口接收字符。当我使用RCREG或ADRESH或ADRESL时,寄存器不会从文件中更新。我想可能是因为我没有初始化外设,所以我创建了一个全局的挥发性char Serchar=“0”。当我尝试使用注册表注入时,我得到了错误:Err:E0103-SIM:解析SCL E9816-SCL失败:无效的参数行(48),我在其他项目中使用注册表注入,没有问题,但是外围设备被设置了。以下是我的代码:有什么想法吗?谢谢!
以上来自于百度翻译 以下为原文 I have written a simple program to be used for testing some code. I'm trying to simulate keystroke characters on a serial port to test a command parsing routine. I am using the simulator register injection with a simple text file containing decimal integers for the characters to be received from the serial port. When I use RCREG or ADRESH or ADRESL the registers are not being updated from the file. I figured maybe it was because I had not initialized the peripherals, so I created a global volatile char SERCHAR = '0'. When I try to use that for the register injection, I get the error: Error: E0103-SIM: Failed to parse SCL E9816-SCL: Invalid parameter line(48) I have used register injection in other projects with no problem, but the peripherals were set up. Here is my code: #include int get_temp( int adc ); int adcval[] = { 906,890,868,836,795,743,682,613,540,468,399 }; __eeprom int tempC[] = { 0,10,20,30,40,50,60,70,80,90,100 }; void Program_Constants(void); volatile char SERCHAR = '0'; char EUSART_Read(void) { return SERCHAR; } void main(void) { int readadc, readC; while(1) { for(readadc = 900; readadc > 468; readadc -= 20) readC = get_temp(readadc); Program_Constants(); } } void Program_Constants(void) { //Send_Programming_String; char Command[]="******"; int count=0; char Input_Char = '£'; while (Input_Char != 'X') { //Process multiple commands until X while (Input_Char != 'X' && count < 6 && Input_Char != 'r'){ //Read up to 6 characters only and stop early if X or r. Input_Char = EUSART_Read(); Command[count] = Input_Char; count++; } count=0; if (Input_Char != 'X') { //Examine and process command. Skip if X entered. if ((Command[0] == 'B' || Command[0] == 'S' || Command[0] == 'F') && (Command[1] == ' ')){ //Check command for input ?????errors. //Process command and print revised values etc //Send_Programming_String; } else { //printf("INPUT ERRORnn"); //Send_Programming_String; } } } } int get_temp( int adc ) { int offset, temp, temp1, temp2; for(offset=1; offset<10; offset++) { if( adcval[offset] < adc) { temp1 = tempC[offset-1]; temp2 = tempC[offset]; temp = temp1 + ((temp2-temp1)*(adcval[offset-1]-adc))/(adcval[offset-1]-adcval[offset]); return temp; } } return -1; } Any ideas? Thanks! |
|
相关推荐
7个回答
|
|
当我将串行端口设置为缺省条件CREN=1,Syc=0,SPEN=1,等待RCIF清除时,我在RCREG寄存器中获取字符,但是它们不对应于注入文件中的值:BTW,如何在文件中放置注释?我认为他们只是前面的“;”还是“//”?[编辑]我尝试了“;”并且得到了一个错误“没有找到源代码行……”。“//”看起来不错,但其他问题仍然存在。[编辑2]我找到了一种在串口上模拟字符流的方法: 以上来自于百度翻译 以下为原文 When I set up the serial port to default conditions CREN=1, SYNC=0, SPEN=1, and wait for RCIF to clear, I am getting characters on the RCREG register, but they do not correspond to the values in the injection file: 66 32 49 50 51 52 13 88 13 BTW, how can comments be placed in the file? I think they are just preceded by ";" or "//"? [edit] I tried ";" and got an error "No source lines found...". The "//" seems OK, but other problems remain. [edit2] I found a way to simulate a stream of characters on the serial port: char RXDsim[] = {'B',' ','1','2','3','4','n','X',' |