PICBASIC serial communications problem

Jul 23, 2005 0 Replies

Hi all



I am trying to communicate with a computer using pic18f4620 in basic programming. I am using the hyperterminal to send and recieve messages. I am displaying the incoming message onto an LCD screen. When I run the code below the LCD screen displays garbage. I am not sure at what baud rate this program should be working either. Please help.



Include "modedefs.bas"



' RS232C Serin2 and Serout2 Demo Program



' Define ONINT_USED to allow use of the boot loader. ' This will not affect normal program operation.


'Define ONINT_USED 1 '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 'ADCON1 = %00001111



' OSCTUNE = $40 ' OSCCON = $72



DEFINE HSER_RCSTA 90H DEFINE HSER_TXSTA 20H DEFINE HSER_BAUD 9600 ' DEFINE HSER_SPBRG 25



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



PAUSE 1000


bootupscreen:



LCDOUT $fe,1 'Clear LCD screen pause 500 LCDOUT "USART TESTING" 'Put up self test display pause 500 ' LCDOUT $fe,1 'Clear LCD screen LCDOUT $fe, $C0 'Start of second line LCDOUT "THIS LINE IS CRAP"



pause 500



' ADCON1 = 7 ' Set PORTA and PORTE to digital ' Low PORTE.2 ' LCD R/W line low (W) ' Pause 200 ' Wait for LCD to start up



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



'loop: HSERIN [RX, STR rec\\1]



'loop: serin2 rx, 84, [STR rec\\1] 'input ' IF REC = 1 THEN GOTO loop ENDIF



'outlcd: lcdout $fe, $94, "RECEIVE = ", STR rec\\1



'HSEROUT ["RECEIVED"]



' serout2 Tx, 84, ["RECEIVED = ", STR rec\\1] 'output



' PAUSE 500


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



send="y"



' HSERIN {ParityLabel,}{Timeout,Label,}[Item{,...}] ' HSERIN2 {ParityLabel,}{Timeout,Label,}[Item{,...}] ' SERIN Pin,Mode,{Timeout,Label,}{[Qual...],}{Item...} ' SERIN2 DataPin{\\FlowPin},Mode,{ParityLabel,}{Timeout,Label,}[Item...]



' Hserin 10000, start, [char] loop: serin2 rx, 84, [STR rec\\1] ' serin rx, T9600, [STR rec\\1] outlcd: lcdout $fe, 1, "RECEIVE = ", STR rec\\1 serout2 Tx, 84, [send] ' SEROUT Tx, T9600, ["RECEIVED"]



goto loop



Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required