Do I need a pause?


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1

    Default

    Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

    IF mydata1=%01011001 THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF

    I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low. I do not have a serial LCD but you mentioned using terminal, what do you mean using a PC??? If so, would you tell me how ?

    Thanks
    Last edited by tazntex; - 20th August 2008 at 15:31.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by tazntex View Post
    Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

    IF mydata1=%01011001 THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF

    I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low. I do not have a serial LCD but you mentioned using terminal, what do you mean using a PC??? If so, would you tell me how ?

    Thanks
    download realterm, works well, use a max 232 if needed, some nice kits on ebay for cheap,gets you a PCB, connector, caps and the max chip. Or roll your own, use the code from post 16 of this thread:http://www.picbasic.co.uk/forum/showthread.php?t=4972 here is an ebay seller http://cgi.ebay.com/RS232-Serial-UAR...QQcmdZViewItem
    and another http://cgi.ebay.com/MAX232-RS232-Ser...QQcmdZViewItem
    Last edited by Archangel; - 20th August 2008 at 22:49.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Quote Originally Posted by tazntex View Post
    Thanks for the reply. I see your point about checking twice but I just wanted to check twice, the first brings me into this and the second does the if/then. I've taken this out and now I have:

    IF mydata1=%01011001 THEN
    HIGH 1
    ELSE
    LOW 1
    ENDIF

    I had a previous previous thread "else" which you help me on and it is all working but like I said before, I press a button on the tx ,the outputs being portb.0-6 on the rx , the momentary outputs 1-4 come on and when I release the button they go off. Every so often one stays on, check the selected output pin with scope and it is high, but if I press and release the same button for the output again it will go back low.
    So if I understand correctly, you only want the lights on WHILE receiving mydata=%01011001
    HIGH 1 otherwise you WEND want it to stay Low, Correct ?
    Last edited by Archangel; - 20th August 2008 at 23:31.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4

    Default

    "So if I understand correctly, you only want the lights on WHILE receiving mydata=%01011001
    HIGH 1 otherwise you WEND want it to stay Low, Correct?"

    yes that is correct.

    One thing though, I checked the circuit to make sure that is was the processor keep the led on and the output pin is High, while checking the pin I just wanted to make sure that the voltage coming from the output was correct, it is. Looking at the same pin with the scope there is some noise, so I switched from a switch mode power supply to a gel cell (12v). I am using a 7805 regulator with 10uf electrolytic on the input and .01 disc on the regulators output to ground. The noise is still there. Perhaps a cap between the VCC and Vss of the Pic will clear up the rest. I have change processors on both the tx and rx side to rule out a defective one just in case static damage them. On the 4mhz crystal I am using 33pf caps to ground.

    I will explore realterm tommorrow, thanks for that info.

    Thanks again

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default

    Try something like this:
    Code:
    IF mydata1=%01011001 THEN
    WHILE  mydata1=%01011001
    HIGH 1
    WEND
    ELSE
    LOW 1
    ENDIF
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6

    Default

    Thanks Joe for the example, I did try it but it locks up, let me explain. On the receiver I have read and reread what I have written, but I added a datagood LED that way I can see what is going on the the variable mydata1. When the momentary output stays on, datagood is also on so I don't think the mydata1 is %00000000 so what is your opinion. I removed the other outputs from the program to reduce the space here. Here is the receiver:
    INCLUDE "MODEDEFS.BAS"
    @ DEVICE PIC16F628a,XT_OSC
    @ DEVICE pic16F628a, WDT_OFF
    @ DEVICE pic16F628a, PWRT_ON
    @ DEVICE pic16F628a, MCLR_OFF
    @ 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
    'do I need vrcon=0 ?
    datagood VAR porta.2
    serpin VAR porta.1 'serial input pin
    PORTA = 0
    PORTB = 0
    trisa = %00000010
    trisb = %10000000
    CMCON=%00000111
    PAUSE 50

    loop:
    mydata1=%00000000
    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>0) && (checksum = chk_sum) THEN
    datagood = 1
    else
    datagood = 0
    endif
    if mydata1=%01010110 then loop2
    if mydata1=%10101111 then loop2
    if portb.0=1 then loop3
    goto loop

    loop2:
    if mydata1=%10101111 then high 0 'master relay turn on
    pause 50

    if mydata1=%01010110 then portb=0 'master relay turn off
    pause 50
    goto loop

    loop3:
    if mydata1=%01011001 then
    high 1 'portb.1 is on
    else
    low 1 'portb.1 is off
    endif
    GOTO loop


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

    And here is the tx:
    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 pressed
    goto findkey
    pressed:
    if A = 0 and B = 0 then p3
    if A = 0 then p1
    if B = 0 then p2
    goto findkey

    p1:
    if A = 0 then keydata = %01010110
    gosub validate
    gosub transmit
    goto findkey

    p2:
    if B = 0 then keydata = %01011001
    gosub validate
    gosub transmit
    pause 250
    if B = 1 then pause 10
    if B = 1 then keydata=%00000000
    gosub validate
    gosub transmit
    goto findkey

    p3:
    if A = 0 && B = 0 then keydata = %10101111
    gosub validate
    gosub transmit
    goto findkey
    validate:
    chk_sum = (address + address)
    chk_sum = chk_sum + (keydata + keydata)
    return
    transmit:
    serout serpin,N2400,[$55,$55,$55,$55,$55,$55,$AA,$AA,$AA,$AA,$AA,$AA,sy nch,address,address,keydata,keydata,chk_sum]
    return

    Thanks again
    Last edited by tazntex; - 22nd August 2008 at 20:18.

  7. #7

    Default

    I have looked over this for the last two days and when the output is stuck on the led I have for datagood is on so this tells me that mydata1 is not clearing. I've search this forum to see if anyone else has or had this kind of problem but could not find any information. Does anyone have any suggestions? Thank you

  8. #8
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default

    tazntex, What do you mean by this line?, if mydata1=%10101111 then high 0 'master relay turn on. What is "high 0"?

    Dave Purola,
    N8NTA

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Replies: 11
    Last Post: - 12th July 2008, 02:36
  4. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 10:50
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

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