PDA

View Full Version : character return from PIC to VB



macinug
- 28th April 2009, 16:16
Hi, I'm testing the serial communication between a 16F876 and a VB6 application. I read HSERIN then send it straight back out as HSEROUT. But I don't always receive the character I sent. eg:
Sent to PIC Recieved back to VB
1 ±
2 ²
3 3
4 '
5 5
6 6

I'm obviously not using the correct code table but I'm not sure what character set to use. Can anyone help?
Ta

Luckyborg
- 28th April 2009, 22:49
can you post your code?

macinug
- 29th April 2009, 09:09
Here is the PIC code. I am sending the data as a string from a TextBox in Visual Basic. By the way, the "END" is returned as "ÅND" if this gives any further clues!

@ DEVICE HS_OSC,LVP_OFF,WDT_OFF,PROTECT_OFF,BOD_OFF,PWRT_OF F
'declare variables
define OSC 20
DEFINE HSER_BAUD 19200 'serial
DEFINE HSER_RCSTA 90h 'serial
DEFINE HSER_TXSTA 24h 'serial
DEFINE HSER_CLROERR 1 ' automatic clear overrun error
DEFINE HSER_EVEN 1
DEFINE HSER_BITS 7

trisb = %11000000 ' set port b 0-5 o/ps 6&7 i/ps
RCIF VAR PIR1.5
SERIALDATA VAR BYTE
portb.0 = 0
portb.1 = 0
portb.2 = 0
portb.3 = 0

PAUSE 100

MAIN:
portb.0 = 0
IF RCIF THEN
pause 100
sound portb.0,[60,10]
HSERIN [SERIALDATA] 'RCIF is reset by reading HSERIN
HSEROUT [SERIALDATA,"E","N","D"]
ENDIF
GOTO MAIN

end

Ioannis
- 29th April 2009, 09:37
Have you test the code with a simple program like terminal and give the numbers by hand and slowly ?

What about you VB code?

Ioannis

Melanie
- 29th April 2009, 10:05
Your Crystal, Trimming Capacitors or a hundred other things could be affecting the Oscillator frequency. Looks like it's slightly off for your fast baud rate.

Drop your communications down to 2400 and work up from there. You'll discover there will be a point where unacceptable errors start creeping in.

Archangel
- 29th April 2009, 10:24
See what this does:


HSEROUT[IDEC,SERIALDATA,"END"10,13]

It should display Decimal digits, no modifyer should display ASCII, and HEX . . .Have not tried it, modifyer might make a mess out of the string "END"

Actually there should be a comma after END... - Melanie



HSEROUT[IDEC,SERIALDATA,"END",10,13]

macinug
- 29th April 2009, 11:58
Thanks for the quick replies.
After trying the PBP Serial Comm I realised I had not configured the Port correctly in VB ie Was 19200,N,8,1 should be 19200,E,7,1 as in the PBP code config.
Simple mistake made by a now wiser person!