Hi,
I am just trying to transmit something from the pic to the rs232 port of the computer. Although I am using null modem cable, instead of the normal female/female, I did re-reouted my pins. The problem is that on the PC side, I am getting some garbage.
Here is the code of my program:
I thought that I will be getting 0s in the tera term terminal on the PC side, but instead of that I am getting some wierd symbols. Any advice on how to fix this issue?
Also, st232 (pin-to-pin analog to max232) was used w/ capacitors of 10uF attached as in Nigel's tutorial. I didn't use any of the 47 / 22 uF caps, instead I just used 10uF everywhere. The voltage on pin 2 of rs232 was observed to be 9.5 volts (using voltmeter).
Also, I am using external 40MHz oscillator, is it correct to drive 18f452 w/ such an oscillator, because in the spec microchip used 20 MHz max as an example.
I am just trying to transmit something from the pic to the rs232 port of the computer. Although I am using null modem cable, instead of the normal female/female, I did re-reouted my pins. The problem is that on the PC side, I am getting some garbage.
Here is the code of my program:
Code:
#include "p18f452.inc"
#define BAUD d'9600'
#define XTAL d'40'
#define X ((XTAL*d'1000000')/(d'64'*BAUD))-1
#define DATA_OUT 0x30 ; corresponds to 0 in ascii
org h'0'
goto MAIN
org h'8'
btfss PIR1, TXIF ; TX buffer is full?
retfie ; return from interrupt
TX_INT1 movf DATA_OUT, w
movwf TXREG ; put the data into the TX buf reg
retfie
MAIN
movlw X ; X is the calculated constant
movwf SPBRG ; set baud rate generator appropriately
bsf RCSTA, SPEN ; enable the serial port
bcf TRISC, 6 ; set pin 6 of port c as TX
bsf TRISC, 7 ; set pin 7 of port c as RX
bcf TXSTA, SYNC ; set the mode to asyhncronous
bsf TXSTA, TXEN ; enable the TX
; we want to enable to interrupts associated with TX and RX, so
bsf PIE1, TXIE ; enable the TX interrupts
bsf INTCON, GIE ; enable all unmasked interrupts
bsf INTCON, PEIE ; enable all unmasked peripheral ints
movf DATA_OUT
movwf TXREG
INF_LOOP goto INF_LOOP
END
I thought that I will be getting 0s in the tera term terminal on the PC side, but instead of that I am getting some wierd symbols. Any advice on how to fix this issue?
Also, st232 (pin-to-pin analog to max232) was used w/ capacitors of 10uF attached as in Nigel's tutorial. I didn't use any of the 47 / 22 uF caps, instead I just used 10uF everywhere. The voltage on pin 2 of rs232 was observed to be 9.5 volts (using voltmeter).
Also, I am using external 40MHz oscillator, is it correct to drive 18f452 w/ such an oscillator, because in the spec microchip used 20 MHz max as an example.