Problem using Else


Results 1 to 40 of 47

Threaded View

  1. #10


    Did you find this post helpful? Yes | No

    Default

    Joe, here is the code I am sending from pic to pic:

    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    ' Watchdog Timer
    @ DEVICE pic16F628a, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628a, MCLR_ON
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628a, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628a, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628a, CPD_OFF
    ' Data Memory Code Protect
    ' Set to CPD_OFF for Development Copy
    ' Set to CPD_ON for Release Copy
    @ DEVICE pic16F628a, PROTECT_OFF
    define osc 4
    CMCON=%00000111
    trisb = %11111111
    trisa = %00010111
    chk_sum var byte
    dgood var porta.2
    serpin var porta.3
    nokey con %11111111
    synch con 254
    address con %00000001
    keyin var portb
    keydata var byte
    E VAR PORTB.0
    D VAR PORTB.1
    G VAR PORTB.2
    A VAR PORTB.3
    B VAR PORTB.4
    C VAR PORTB.5
    F VAR PORTB.6
    na VAR PORTB.7
    PreAmble CON $A5 ' 10100101
    findkey:
    if A = 0 then sw0
    if B = 0 then sw1
    if C = 0 then sw2
    if D = 0 then sw3
    if E = 0 then sw4
    if F = 0 then sw5
    if G = 0 then sw6

    goto findkey
    sw0:
    keydata = %01010110
    goto dout
    sw1:
    keydata = %01011001
    goto dout
    sw2:
    keydata = %01011010
    goto dout
    sw3:
    keydata = %01100101
    goto dout
    sw4:
    keydata = %01100110
    goto dout
    sw5:
    keydata = %01101001
    goto dout
    sw6:
    keydata = %01101010
    goto dout

    dout:
    low dgood
    pause 100
    chk_sum = (address + address)
    chk_sum = chk_sum + (keydata + keydata)
    goto transmit

    transmit:

    serout serpin,N9600[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    if keyin = nokey then x2
    goto findkey

    x2:
    high dgood
    keydata = %00000000
    serout serpin,N9600,[$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,synch,addr ess,address,keydata,keydata,chk_sum]
    goto findkey
    end

    Anyhow, it works, tx side seems to be fine, my big problem is on the rx side each output that is a if/then statement will come on but when I release the button it stays on. The only way to make it turn off is to press another momentary button. The toggle function works fine, although if I hold onto the button to long it will toggle on/off. if/then example I have tried after Skimask post:

    if mydata1=%01011001 then pause 50
    if mydata1=%01011001 then
    high 1
    else
    low 1
    endif

    I am using a direct cable link, and will try again later with the Linx modules.

    "logic dictates, cmcon goes before anything portA, then tris registers dictate input or output, then port dictates hi or low status."
    And I have modified the suggestion to this tx program yet, but I will later this evening.

    Many thanks for the help.
    Last edited by tazntex; - 7th August 2008 at 04:41.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 21:39
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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