12F683 Serial Comms


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

    Default 12F683 Serial Comms

    Hi Guys,

    A while ago I got code working for my 16F690 that allowed me to communicate back and forth with my PC Serial Port. I Picked up some 12F683's however I am struggling to convert the code to work with the 12F683. The purpose of the project is to provide some sort of Software Protection for a program I have written in vb.net so I figured an 8 pin would be perfect I can even get power off the serial port.

    Here is the existing code I have for my 16F690, if anyone has any time to point me in the right direction to use it on a 12F683

    Code:
    Include "modedefs.bas"
    
    DEFINE OSC 4
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 25
    DEFINE HSER_CLROERR 1
    
    ANSEL = 0
    ANSELH = 0
    CM1CON0 = 0
    CM2CON0 = 0
    
    stat VAR byte
    
    stat = " "
    
    Main:
    HSERIN [stat]
     if stat = "0" Then goto reqSerial
    GOTO Main
    
    reqSerial:
    HSEROUT ["51384529"]
    GOTO MAin
    END
    I am using a max232 with the circuit. I have taken out some of the original code to make it easier to post here, should compile and it works on a 16F690

    Thanks,
    Ross.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Hi Ross,

    The 12F683 does not have a hardware serial port, so you would need to use debugin and debug, or serin and serout, instead of hserin and hserout.

    If you need a hardware serial port, then there will be the 12F1822 (pretty soon).
    http://www.scalerobotics.com

  3. #3
    Join Date
    May 2010
    Posts
    20

    Default

    Ah I see. I don't know much hehe I tried to put some code together just to test but it seems not to work. Could this be close?

    Code:
    Include "modedefs.bas"
    
    OSCCON = %01100000 ' Internal 4MHz osc
    ADCON0 = 0 
    CMCON0 = 7 
    ANSEL = 0
    WPU = 0 
    GPIO = %00000000 
    
    rcx var GPIO.4 'input pin
    tcx var GPIO.2 'output pin
    
    stat VAR byte
    
    Main:
    serin rcx,N2400,STAT
    pause 100
     SEROUT tcx,n2400,[stat]
    GOTO Main
    END

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Looks very close.

    If you are still using a rs232, then you want True, if you are not, then just as you did, with inverted.
    http://www.scalerobotics.com

  5. #5
    Join Date
    May 2010
    Posts
    20

    Default

    Ah thanks for pointing that out. I was using a max232 with 'n' and not 't' :P

    Working code:

    Code:
    Include "modedefs.bas"
    
    OSCCON = %01100000      'set for 4mhz internal
    CMCON0 = 7              'TURN COMPARITORS OFF
    ANSEL  = %00000000      'Set A/D OFF
    ADCON0 = %00000000      'Analog converter OFF 
    
    rcx var GPIO.4 'input pin
    tcx var GPIO.1 'output pin
    
    stat VAR byte
    
    Main:
    serin rcx,t2400,STAT
    pause 100
     SEROUT tcx,t2400,[stat]
    GOTO Main
    END
    Is a max232 needed? I haven't had much success without it in the past but I might consider trying to lose it since space is a bit tight in the dongle case.

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Quote Originally Posted by ross246 View Post
    Is a max232 needed? I haven't had much success without it in the past but I might consider trying to lose it since space is a bit tight in the dongle case.
    When you use a hardware serial port on a pic16 device, you need an RS232. If you use hardware serial on a PIC18, then you can invert the bits to get away without one.

    For degug or serin/out you don't need one. You can follow the directions in the manual for the resistor size to protect your pic.
    http://www.scalerobotics.com

  7. #7
    Join Date
    May 2010
    Posts
    20

    Default

    Awesome thanks so much for your help. Just got to search through the manual now. 10k sticks in my head for some reason but I will check.

    Thanks again.
    Last edited by ross246; - 17th November 2010 at 15:53.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Quote Originally Posted by ross246 View Post
    Awesome thanks so much for your help. Just got to search through the manual now. 10k sticks in my head for some reason but I will check.
    Not a problem, great to see you got it going.

    It's 1K resistor for serout, and 22K (or so) for serin pins.
    http://www.scalerobotics.com

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