PDA

View Full Version : Pic18F4455 to PC communication RS232



anmproj
- 29th July 2005, 18:22
Hi,
Following is the code I have as I am just trying to get my PIC to communicate both ways with a PC using RS232. With this code, I can get the computer to send characters to the pic, which show up on my LCD screen. However, the character I send from the PIC to the PC, does not show up on the computer. I am using the Serial Communication Window in Microcode Studio. Compiler is PicBasic Pro. I have the RX/TX lines directly connected to the Serial cable on the computer, and I have also tried using resistor in series, with no luck. Please help with any ideas!

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''
DEFINE OSC 32

DEFINE LCD_DREG PORTD 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit (0 or 4)
DEFINE LCD_RSREG PORTB 'Register select port
DEFINE LCD_RSBIT 7 'Register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 6 'LCD enable bit
DEFINE LCD_BITS 8 'Defines the number of bits wide
DEFINE LCD_LINES 2 'Sets the number of LCD lines
DEFINE LCD_COMMANDUS 2000 'Sets the LCD command delay time in us
DEFINE LCD_DATAUS 50 'Sets the LCD data delay in us

TRISB = %00011111
PORTB = %00000000
TRISE.0 = 0 'Set PORTE.0 to output
TRISE.1 = 0 'Set PORTE.1 to output
TRISE.2 = 0
TRISD = 0

TRISC = %10010000 ' Bits 7 & 4 set as Inputs
PORTC = %00000000 ' All off to start

bootupscreen:

LCDOUT $fe,1 'Clear LCD screen
LCDOUT "USART TESTING" 'Put up self test display

Vars: Tx var PORTC.6
Rx Var PORTC.7
rec var byte[1]

loop:
serin2 rx, 84, [STR rec\1]
lcdout $fe, 1, "RECEIVE = ", STR rec\1
serout2 tx, 84, ["@#$"]

goto loop

Bruce
- 29th July 2005, 22:43
With a "direct" serial connection to your PC use inverted mode.

anmproj
- 30th July 2005, 02:32
Thanks for your response! All it needed is the signal to be inverted and some tweaking on the baudrate. Works very well now.