|
|
View previous topic :: View next topic |
Author |
Message |
casandralam
Joined: 26 Jan 2008 Posts: 15
|
Weird result appear on hyperterminal |
Posted: Mon Feb 11, 2008 6:51 am |
|
|
hi, i'm using PIC16f877A to do rs232 data receive sample..the data input is analog,it is obtained using an analog temperature sensor that is lm35dz. when all the circuit connection done, i connected the circuit to PC through rs232 9-pin serial port.but the result appear on hyperterminal screen is some symbol such as "XXXXXXXYYYYYXXX"..it is not any integer number i expected to get before this..what does the symbol means?and how can i solve the problem to get desired integer appear on screen..
below is my source code for the program"
#include <16F877A.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#BYTE portc=7
void main() {
int temp;
int value;
setup_port_a(ALL_ANALOG);
setup_adc_ports(AN0);
do {
value = read_ADC();
temp=value*49/100;
printf("%u",temp);
delay_ms(1000);
} while (TRUE);
} |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 11, 2008 8:19 am |
|
|
I don't know what causes the strange symbols in Hyperterm, are they really 'X' and 'Y' characters or are those just an example?
There are some other problems in your program that need to be fixed:
1) You specify 'ADC=10', a 10-bit resolution but your 'value' variable is only 8 bits. Change 'value' to be of the type int16. This will also fix the overflow problem in 'value*49'.
2) The code for selecting the ADC channel is missing, now you are sampling a random port. Add a call to SET_ADC_CHANNEL(0).
3) For easier reading in Hyperterm you should modify the "%u" format specifier. Now all data is printed directly after each other, you can not see where one value stops and the next begins. For example use "%u\r\n" to print each value on a new line.
What is your compiler version number? |
|
|
kolio
Joined: 06 Feb 2008 Posts: 26
|
|
Posted: Mon Feb 11, 2008 8:39 am |
|
|
Check this out:
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
instead of
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
and "%lu" format specifier instead of "%u" for 16-bit variables
good luck |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|