Problem using Else - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 47 of 47
  1. #41


    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

  2. #42
    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...

  3. #43


    Did you find this post helpful? Yes | No

    Default

    Yes, I have a mess thanks for your help

  4. #44
    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.

  5. #45


    Did you find this post helpful? Yes | No

    Default

    ok, on the transmitting side after stripping everything down I am sending the data for the button that is pressed and when I release each button I send the data again and it clears that particular output on the receiver. Seems to work ok. Thanks for everyones help and I read something here on the forum about closing the post when finished so,... if so how do I do that?

  6. #46
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tazntex View Post
    ok, on the transmitting side after stripping everything down I am sending the data for the button that is pressed and when I release each button I send the data again and it clears that particular output on the receiver. Seems to work ok. Thanks for everyones help and I read something here on the forum about closing the post when finished so,... if so how do I do that?
    Well, what I'm trying to do is show you a much better way of doing things, one that's much much easier to read thru and takes up a lot less code space, by breaking it down, and building it back up again.

    Closing - I wouldn't worry about it. I think I've only ever seen a handful of threads that are closed here.

  7. #47


    Did you find this post helpful? Yes | No

    Default

    Thanks Skimask and everyone else who has helped me. I appreciate you trying to teach me by giving pointers, but this has been a rough one I am by no means a quitter, thought about it though, especially through the last couple of post. I am laughing now. Everything seems fine. I can pressed the button now portb 1-4 are momentary and stay on as long as I am pressing then go off when I release them. Every once in awhile one will stay on and I'll press the button and release it and that output will clear. Thanks again to all

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