PDA

View Full Version : Help with pic16f690 -max232cpe



krise86
- 17th April 2010, 00:16
So i started to try out some serial com and after alot of struggling i have gotten it almoste to work.

i have pickit2 with pic16f690 and a demoboard with max232.

max232:

pin 1 & 3 - 1uf
pin 4 & 5 - 1uf

pin 2 - 1uf to vdd
pin 15 - 1uf to gnd
and gnd to vdd 1uf

so i have been able to recive text on my computer from the pic but it's somehow malformed.

i try to send "Hello World", 13, 10
and i get
Hello0World<CR><(8A)>

when i stop the pic i recive the space and cr and lf

when i make the pic hserout the hserin i returns random alphas or signs.

my current code is as follows:



DEFINE OSC 4

'intcon=0 ' Interrupts disabled
cm1con0=0 ' Comparator 1 disabled
cm2con0=0 ' Comparator 2 disabled
'cm2con1=0 ' Comparator 2 disabled

ANSEL=0 ' Pins to be Digital
ANSELH=0 ' Pins to be Digital

Include "modedefs.bas"

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h 'sets bergh = 1 or 20h sets = 0
DEFINE HSER_BAUDCON 0h ' 0h
DEFINE HSER_BAUD 9600 '16468
DEFINE HSER_SPBRG 25
'DEFINE HSER_CLROERR 1


main:
hserout ["Hello World", 13, 10]
pause 1000
goto main


and i cant figure out why!

im using picbasic with MC studio and MPASM

Please HELP:o

wolwil
- 17th April 2010, 17:41
I have never used HSEROUT before but I use SEROUT.

Try this code just change your output pin from PORTB.0 to what ever one you are using:



DEFINE OSC 4

Baud con 2 ' Define serial mode

main:
Serout PORTB.0,Baud,["Hello World",13,10]
pause 1000
goto main


If the "Baud con 2" doesn't work change it to "Baud con 6"
This is the Mode - 2 is 9600 TTL True and 6 is 9600 TTL Inverted