Menu

Software serial on a 12F683

Help
2010-04-20
2013-05-30
  • Nobody/Anonymous

    Hi, this is my first time programming a 8-pin chip.
    Since they are all labeled as GPIO.0 … GPIO.6, what does channel mean in "Init Serial" ?
    I have the options of Channels 1, 2, 3.
    In Hardware Settings, under RS232(software) it shows Send A High and Send A Low, Recv A Hi/Low.
    What do those do ? I have no options available when I select Edit.

    Please advice.

     
  • Hugh Considine

    Hugh Considine - 2010-04-20

    When setting up the RS232 routines in GCBASIC/GCGB, you first need to define the serial channels. When doing this, you tell it what command to use to send a 0 and what command to use to send a 0, and give it a condition that will be true when a 0 is received, and when a 1 is received. Once this is done, you can use Init Serial to set up the speed of the channel, and the send and receive commands to transfer data.

    Send A High and Send A Low will generally be Set commands to set the right pin on or off. Copy and paste these two lines into your program:

    #define SendAHigh Set GPIO.0 Off
    #define SendALow Set GPIO.0 On

    Then, go to Hardware Settings, and change the pin to whichever pin you are using to send data from. Make sure the Set and the On/Off stay where they are. Next, copy these two lines in:

    #define RecAHigh GPIO.1 = Off
    #define RecALow GPIO.1 = On

    Open Hardware Settings again, and change GPIO.1 to the pin you are using to receive data, leaving the = and On/Off as they are.

    Then, use Ser Init to set the speed for the connection. You can copy and paste this in as an example of some suitable settings:

    InitSer 1, r9600, 1, 8, 1, none, invert

    Then, you can use the send and receive commands. Set them to use channel 1.

    (Note: To copy and paste the #define lines into GCGB, copy them here as normal, then click Edit > Paste in GCGB. You won't see anything appear in the program, but when you go to Hardware Settings you'll see that the appropriate boxes have been filled in.)

     
  • Nobody/Anonymous

    Thank you very much, that was very helpful.

    Another question, does SerReceive wait till data is received? As in, it halts the program flow and waits for the input before continuing. It seems like so in the Help file.
    If so, how would I make it poll for X seconds then timeout and continue even if no data is received?

     
  • Hugh Considine

    Hugh Considine - 2010-04-20

    How SerReceive behaves is controlled by InitSer. With this line:

    InitSer 1, r9600, 1, 8, 1, none, invert

    SerReceive will not wait. It will exit if there is no data coming in. However, with this line:

    InitSer 1, r9600, 1 + WaitForStart, 8, 1, none, invert

    It will wait until there is data. (The WaitForStart is added to the start bits setting.)

    To make it poll for a certain length of time, you would need to set it not to wait. Instead, you would need to have some code like this:

    TimeoutCounter = 0
    Do While RecALow
        Wait 100 us
        TimeoutCounter += 1
        If TimeoutCounter > 10000 Then
            Goto NoData
        End If
    Loop
    'Data is about to come in, read it
    NoData:
    'Data has come or timeout has occurred, continue
    

    TimeoutCounter would need to be a word variable. This code would loop until data was about to come in, or until the 100 microsecond delay had been repeated 10000 times (total of 1 second). For higher baud rates, the 100 us delay might be too long - might need to drop it to 20 us, and repeat 50000 times.

     
  • Nobody/Anonymous

    Understood. Your explanations and suggestions have been very clear and concise. Thank you very much for sharing your expertise.

     
  • Chris

    Chris - 2011-12-27

    I know this is an old post but this just fixed a problem I have been trying to figure out litterly ALL DAY. I have been trying to get a pic model in proteus pro simulator to send serial data out through virtual terminal. Ive been trying everything to get it to send me anything other then garbage (or sometimes nothing at all). I tryed changing the delays in the rs232 and everything then I saw this post. I changed me set  "PORTC.0 on" to "set PORTC.0 off" and "set PORTC.0 off" to "set PORTC.0 on" and set inversion to "invert" and bingo! now its saying "test" through virtual terminal like it should! yay! many thanks to the person who answered this question, youve helped at least 2 people with your answer.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.