Problem using Else


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Ya'll are great, I will go back through this, print it and try to figure it out. Will be back after awhile and let ya'll know what I have or haven't found.



    Thanks again

  2. #2


    Did you find this post helpful? Yes | No

    Default

    INCLUDE "bs2defs.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
    mydata1 VAR byte
    mydata2 var byte
    address1 var byte
    address2 var byte
    checksum var byte
    chk_sum var byte
    serpin VAR porta.1 'serial input pin
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50 ' settle time

    loop:
    clear 'Do I really need to do this? I tried to make sure everything is back to 0
    gosub loop1 'After button is released on tx mydata1=%00000000
    CheckSum = (address1 + address2) 'address sent %00000001 added together in this case this = 10
    CheckSum = CheckSum + (mydata1 + mydata2) '10 + (%00000000 +%00000000)= 10
    IF checksum != chk_sum THEN loop 'checksum = chk_sum because of above
    IF (mydata1) != (mydata2) THEN loop '(mydata1) = (mydata2)
    IF (address1) != (address2) THEN loop '(address1) != (address2)
    'Since everything should be a match We move on
    if mydata1=%01010110 then rly1 'this works so I will go to the next one

    if mydata1=%01011001 then rly2 '1st case will turn portb.1 on
    if mydata1=%00000000 then rly2 '2nd case appears to do nothing but as I stated above the check
    'should be correct and mydata1=%00000000
    if mydata1=%01011010 then rly3 'I will skip the rest of this area because it
    if mydata1=%00000000 then rly3 'behaves the same as rly2 the rly6 rly7 ok.

    if mydata1=%01100101 then rly4
    if mydata1=%00000000 then rly4

    if mydata1=%01100110 then rly5
    if mydata1=%00000000 then rly5

    if mydata1=%01101001 then rly6
    if mydata1=%01101010 then rly7

    rly1:
    if mydata1=%01010110 then pause 10
    if mydata1=%01010110 then toggle 0
    pause 10
    goto loop
    rly2:
    if mydata1=%01011001 then pause 10 'Down here the fun begins
    if mydata1=%01011001 then high 1 '1st case will turn portb.1 on
    if mydata1=%00000000 then low 1 'Since the checksum is correct why didn't I get here
    'mydata1=%00000000 so this should go low but doesn't
    goto loop 'here we go back to loop so I will goto loop1
    rly3:
    if mydata1=%01011010 then pause 10
    if mydata1=%01011010 then high 2
    if mydata1=%00000000 then low 2
    goto loop
    rly4:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100101 then high 3
    if mydata1=%00000000 then low 3
    goto loop
    rly5:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100110 then high 4
    if mydata1=%00000000 then low 4
    goto loop
    rly6:
    if mydata1=%01101001 then pause 10
    if mydata1=%01101001 then TOGGLE 5
    pause 10
    goto loop
    rly7:
    if mydata1=%01101010 then pause 10
    if mydata1=%01101010 then TOGGLE 6
    pause 10
    GOTO loop


    loop1:
    SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
    Return
    'loop1 receives the following
    'transmit:

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

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

    'on the GOSUB loop1 after the tx button is released I should move on to x2
    'x2 sends the preamble, and I am still getting my synch plus address,data an chk_sum
    'so I should pass through the checksum area of my receiver code and on to the rest of
    'my program. When the program arrives at "if mydata1=%00000000 then rly2 " it should
    'ask "if mydata1=%00000000 then low 1" and respond and portb.0 should go low but it
    'never seems to get there. I switch from the If/Then/Else to make it simpler for me
    'to break it down.

    'I've been over the tx side and I feel confident everything there is working correctly

    ' Am I heading in the right direction?

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    So between post #34 and #39, that is your entire code for both TX and RX?

    And is it possible for you to connect an LCD to the RX for troubleshooting? Or at least replace those relays with LEDs.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Skimask here is the entire program for both sides:

    TRANSMITTER

    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ 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 preamble
    findkey:
    if keyin != nokey then dout
    goto findkey

    pressed:
    if A= 0 then pause 10
    if A= 0 then keydata = %01010110

    if B = 0 then pause 10
    if B = 0 then keydata = %01011001

    if C = 0 then pause 10
    if C= 0 then keydata = %01011010

    if D = 0 then pause 10
    if D = 0 then keydata = %01100101

    if E = 0 then pause 10
    if E = 0 then keydata = %01100110


    if F = 0 then pause 10
    if F = 0 then keydata = %01101001

    if G = 0 then pause 10
    if G = 0 then keydata = %01101010

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


    transmit:

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

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

    end


    RECEIVER

    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_ON
    @ DEVICE pic16F628a, BOD_ON
    @ DEVICE pic16F628a, LVP_OFF
    @ DEVICE pic16F628a, CPD_OFF
    @ DEVICE pic16F628a, PROTECT_OFF
    DEFINE OSC 4
    mydata1 VAR byte
    mydata2 var byte
    address1 var byte
    address2 var byte
    checksum var byte
    chk_sum var byte
    serpin VAR porta.1
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50

    loop:
    clear
    gosub loop1
    CheckSum = (address1 + address2)
    CheckSum = CheckSum + (mydata1 + mydata2)
    IF checksum != chk_sum THEN loop
    IF (mydata1) != (mydata2) THEN loop
    IF (address1) != (address2) THEN loop

    if mydata1=%01010110 then rly1

    if mydata1=%01011001 then rly2
    if mydata1=%00000000 then rly2

    if mydata1=%01011010 then rly3
    if mydata1=%00000000 then rly3

    if mydata1=%01100101 then rly4
    if mydata1=%00000000 then rly4

    if mydata1=%01100110 then rly5
    if mydata1=%00000000 then rly5

    if mydata1=%01101001 then rly6
    if mydata1=%01101010 then rly7

    rly1:
    if mydata1=%01010110 then pause 10
    if mydata1=%01010110 then toggle 0
    pause 10
    goto loop

    rly2:
    if mydata1=%01011001 then pause 10
    if mydata1=%01011001 then high 1
    if mydata1=%00000000 then low 1
    goto loop

    rly3:
    if mydata1=%01011010 then pause 10
    if mydata1=%01011010 then high 2
    if mydata1=%00000000 then low 2
    goto loop

    rly4:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100101 then high 3
    if mydata1=%00000000 then low 3
    goto loop

    rly5:
    if mydata1=%01100101 then pause 10
    if mydata1=%01100110 then high 4
    if mydata1=%00000000 then low 4
    goto loop

    rly6:
    if mydata1=%01101001 then pause 10
    if mydata1=%01101001 then TOGGLE 5
    pause 10
    goto loop

    rly7:
    if mydata1=%01101010 then pause 10
    if mydata1=%01101010 then TOGGLE 6
    pause 10
    GOTO loop


    loop1:
    SERIN2 serpin,16780,[wait(254),address1,address2,mydata1,mydata2,chk_su m]
    Return

    No LCD, I do have leds and also monitoring the pins with scope.

    thanks

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quite frankly...what a cluster! You really have to work on your flow. There's too many places where you expect a value to be during one if/then, and then be there again at another if/then even though you just got done changing it.

    Give me a few minutes to work it out...

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Yes, I have a mess thanks for your help

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, for awhile, forget about your receiver...
    Forget about the sync, forget about the preamble, forget about the checksum, forget about everything else. Pretend this TX is transmitting to nowhere and nowhere likes it that way...

    You know how to set up your PIC, you can set the pins, etc....
    You have 7 buttons, each connected to a PortB pin...
    When these buttons AREN'T pressed, the pins are high, when pressed the pin is low...
    Easy enough...

    Write a program that does nothing but reads the state of the pins and sends that value out in a SEROUT statement of some sort.

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