Serial com: in need of help


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    Default Serial com: in need of help

    This code that runs on two 16F628A's is not working. There are four buttons on the transmitter that control the five pins on the receiver. A packet is sent out for each change in the button state. Please help!
    Thanks.

    -Mike

    Transmitter code
    ----------------
    define HSER_TXSTA 20h
    define HSER_BAUD 2400

    cmcon = 7

    sone var byte
    sone = 0
    stwo var byte
    stwo = 0
    sthree var byte
    sthree = 0
    sfour var byte
    sfour = 0
    Synch var byte
    Synch = "~"
    Pre var byte
    Pre = $A5

    Main:

    if (PORTA.0 = 0 && sone = 0) then
    hserout [Pre,Synch,"1"]
    sone = 1
    pause 200
    endif
    if (PORTA.0 = 1 && sone = 1) then
    hserout [Pre,Synch,"2"]
    sone = 0
    pause 200
    endif


    if (PORTA.1 = 0 && stwo = 0) then
    hserout [Pre,Synch,"3"]
    stwo = 1
    pause 200
    endif
    if (PORTA.1 = 1 && stwo = 1) then
    hserout [Pre,Synch,"4"]
    stwo = 0
    pause 200
    endif


    if (PORTA.2 = 0 && sthree = 0) then
    hserout [Pre,Synch,"5"]
    sthree = 1
    pause 200
    endif
    if (PORTA.2 = 1 && sthree = 1) then
    hserout [Pre,Synch,"6"]
    sthree = 0
    pause 200
    endif


    if (PORTA.3 = 0 && sfour = 0) then
    hserout [Pre,Synch,"7"]
    sfour = 1
    pause 200
    endif
    if (PORTA.3 = 1 && sfour = 1) then
    hserout [Pre,Synch,"8"]
    sfour = 0
    pause 200
    endif

    goto Main

    Receiver code
    -------------
    define HSER_CLROERR 1
    define HSER_RCSTA 90h
    define HSER_BAUD 2400

    Msg Var BYte
    cmcon = 7

    Main:
    hserin [WAIT("~"),Msg]


    if (Msg = "1") then
    high PORTA.0
    goto main
    endif
    if (Msg = "2") then
    low PORTA.0
    goto main
    endif

    if (Msg = "3") then
    high PORTA.1
    goto main
    endif
    if (Msg = "4") then
    low PORTA.1
    goto main
    endif

    if (Msg = "5") Then
    high PORTA.2
    goto main
    endif
    if (Msg = "6") then
    low PORTA.2
    goto main
    endif

    if (Msg = "7") Then
    high PORTA.3
    goto main
    endif
    if (Msg = "8") then
    low PORTA.3
    endif
    goto main

    -------------------

    Thanks again!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Some IF THEN statement are weird to me
    Code:
    if (PORTA.0 = 0 && sone = 0) then
    Should be
    Code:
    if (PORTA.0 = 0) AND (sone = 0) then
    OR
    Code:
    if (PORTA.0 = 0) && (sone = 0) then
    There's few missing info.
    Config Fuse setting.
    Internal OSC or external?
    wich speed?
    Schematic?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Replies: 33
    Last Post: - 19th March 2010, 03:02
  2. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  3. Serial data to USB
    By cooksydesign in forum USB
    Replies: 18
    Last Post: - 29th October 2008, 15:10
  4. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  5. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35

Members who have read this thread : 0

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