Pic16f690 and basic Serial Com


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2010
    Posts
    20

    Default Pic16f690 and basic Serial Com

    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:

    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.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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
    DT

  3. #3
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Thanks so much, worked a treat

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts