Serial com PIC <> PC - what is best?
Hello,
I'm struggeling to get an error free serial communication between my 16F88/4MHz and the PC's terminal (using the MCS's one).
The aim is to send data to the PIC's DATA memory and read it back in the PC.
Actually, I'm transferring data kind of "one by one" memroy location basis and it works more or less fine. If I want to transfer to more than one memory location at the time, the trouble begins.
I have read lots of threads about SERIN/SEROUT and the usage of USART. To be honest, the more I read, the more I get lost...
My PIC is equipped with AUSART. Is this a "hardware" USART?
What is the best and most reliable way to transmit data to and from the PC?
1 Attachment(s)
Fill PIC's program memory
I'll try with a 4MHz crystal.
At the end, I want to send WORDs to the PIC's program memory. I tried this internally with WRITECODE and it works as long as 4 WORDs are stored in a row.
I can't figure out how to send more than 1 data from the terminal to the PIC. So now, I have to press "Send" a couple of times until the LCD shows up some results. I send the datas comma separated, it this so?
Since I'm testing step-by-step, I didn't made an endless loop.
Here is the SERIN version:
Code:
@ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
@ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
' Register settings
OSCCON = %01100000 'Internal RC set to 4MHZ
ANSEL = %00000000 'Disable Analogue Inputs
' LCDOUT command (if defaults are not changed, DEFINEs can be omitted)
DEFINE LCD_DREG PORTB 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 on µC
DEFINE LCD_RSREG PORTA 'LCD register select port
DEFINE LCD_RSBIT 3 'LCD register select bit
DEFINE LCD_EREG PORTA 'LCD enable port
DEFINE LCD_EBIT 2 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us
Value1 var WORD
Value2 var WORD
Value3 var WORD
Value4 var WORD
'-------------------------------------------------------------------------------
' Init LCD
lcdout $FE, 1
pause 1000
'-------------------------------------------------------------------------------
' Input data from PC's terminal and show it on LCD
serin2 PORTA.0, %100000001010100, [dec3 Value1] '9600, inverted
serin2 PORTA.0, %100000001010100, [dec3 Value2] '9600, inverted
serin2 PORTA.0, %100000001010100, [dec3 Value3] '9600, inverted
serin2 PORTA.0, %100000001010100, [dec3 Value4] '9600, inverted
lcdout dec3 Value1, " ",dec3 Value2, " ",dec3 Value3, " ",dec3 Value4
END
This is the HSERIN version, same problem as before:
Code:
@ DEVICE PIC16F88,INTRC_OSC_NOCLKOUT,PROTECT_OFF,WDT_ON,PWRT_ON,MCLR_ON
@ DEVICE PIC16F88,BOD_ON,LVP_OFF,CPD_OFF,DEBUG_OFF,CCPMX_OFF
OSCCON = %01100000 'Internal RC set to 4MHZ
ANSEL = %00000000 'Disable Analogue Inputs
RCSTA = %10010000 'Enable serial port (RB2=RX & RB5=TX) and continuous receive
TXSTA = %00100000 'Enable Transmit Bit
SPBRG = 6 'Set baudrate to 9600
DEFINE LCD_DREG PORTA 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4 on µC
DEFINE LCD_RSREG PORTA 'LCD "RS" register select port
DEFINE LCD_RSBIT 7 'LCD "RS" register select bit
DEFINE LCD_EREG PORTA 'LCD "E" enable port
DEFINE LCD_EBIT 6 'LCD "E" enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us
'-------------------------------------------------------------------------------
' Init
Value1 var WORD
Value2 var WORD
Value3 var WORD
Value4 var WORD
lcdout $FE, 1
PAUSE 500
'-------------------------------------------------------------------------------
' Input data from PC's terminal and show it on LCD
Hserin [dec3 Value1] '9600, inverted
Hserin [dec3 Value2] '9600, inverted
Hserin [dec3 Value3] '9600, inverted
Hserin [dec3 Value4] '9600, inverted
lcdout dec3 Value1, " ",dec3 Value2, " ",dec3 Value3, " ",dec3 Value4
END