PDA

View Full Version : Pic16f690 and basic Serial Com



ross246
- 14th May 2010, 22:36
Hi everyone im new to this hobby and these forums :)

Im having trouble communicating between my serial port and a pic16f690 using a max232. I have searched all over the web but for some reason I just cannot find anything helpful to me.

I have gone over the hardware multiple times and I have all 5 caps connected correctly to the max232, I have put together a basic program from searching Google that just sends back what it receives but it does not send back the correct characters. For example if I send a "d" it returns an "ä", if I send an "H" it returns an "È" etc. I have also noticed that it returns the same character (although it's wrong) 90% of the time now and then it returns a different character all together.

Now I understand that using the internal clock is not a good idea with serial communication, which to me seems like the reason it sends back a different character 10% of the time, but surely it shouldnt always be wrong - must be my code:


Include "modedefs.bas"
DEFINE OSC 3
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 92
DEFINE HSER_CLROERR 1
cm1con0 = 0
cm2con0 = 0
ansel = 0
anselh = 0
Char VAR BYTE
led var portb.6
output led
input portb.5
output portb.7
led=1
pause 500
led=0
pause 500
led=1
pause 500
led=0
pause 500
Main
HSERIN [Char]
led = 1
HSEROUT [Char]
pause 10
led = 0
GOTO Main
END

As I said this is a very new hobby but I am trying to learn here :) I am using microcode studio and picbasic pro with a pickit 2 starter kit if that helps.

Thanks for any help,
Ross.

Darrel Taylor
- 15th May 2010, 03:38
DEFINE OSC 3
Would be for an external 3.579Mhz "Color Burst" crystal.

If you are using the Internal Oscillator, the default on a 16F690 is 4Mhz.

DEFINE OSC 4

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

ross246
- 15th May 2010, 12:12
Thanks so much, worked a treat :)