|
|
View previous topic :: View next topic |
Author |
Message |
fs123
Joined: 11 May 2011 Posts: 1 Location: UK
|
RS232 data not correct? |
Posted: Wed May 11, 2011 2:35 pm |
|
|
I'm trying to communicate with a PIC16F88 through RS232 but cannot get it working properly.
The PIC is able to send text data correctly to the PC (teraterm) but when I send a character to the PIC it doesn't seem to be correct.
For example, when I type 'A' I expect the PIC to receive that and send the same character back to the pc terminal but instead of 'A' I get 'O' and 'S' gives 'F'.
It seems to be sending back ASCII characters but not the correct one according to the key pressed.
Can anyone help?
i'm using the following code to test..
Code: | #include <16F88.H>
#device adc=8
#include <stdlib.h>
#fuses XT,NOWDT, NOLVP
#use delay(clock=4000000)
#use standard_io(A)
#use rs232(baud=9600,parity=N, xmit=PIN_B5,rcv=PIN_B2)
#byte PORTA = 0x05
#byte PORTB = 0x06
#bit rb7 = PORTB.7
#bit rb6 = PORTB.6
#bit rb5 = PORTB.5
#bit rb4 = PORTB.4
#bit rb3 = PORTB.3
#bit rb2 = PORTB.2
#bit rb1 = PORTB.1
#bit rb0 = PORTB.0
char ch;
char rom buffer[256];
float value, volt;
int i, min, max;
#int_rda
void serial_isr()
{
ch = getc(); // Get character from PC
printf("%c \r\n",ch); // Send it back to the PC
if (ch<=50)
output_high(PIN_B3);
else
output_low(PIN_B3);
}
main()
{setup_adc_ports(sAN0);
;setup_adc(ADC_CLOCK_DIV_32);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
while(1)
{
//
}
}
| [/code] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 11, 2011 3:15 pm |
|
|
First try a simple program without the #int_rda:
Code: |
#include <16F88.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2, ERRORS)
//============================
void main()
{
int8 c;
while(1)
{
c = getc(); // Get char from PC
putc(c); // Send it back to the PC
}
} |
Make sure the TeraTerm settings are the same as in your #use rs232()
statement: 9600 baud, 8 bits, no parity, no handshaking. |
|
|
|
|
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
|