Problem with WHILE - WEND


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink little help

    Try ( to understand ) this ...

    'device: 16F627A master clear is on pin#4 (RA5)
    TRISA = %00010000 ' port A all outputs, except MCLR is input
    TRISB = %00111111 'PORT B ALL INPUT, EXCEPT 6 & 7 OUTPUT
    option_REG = %01111111 'enable weak pullups on port B
    FOOTSW var portb.5 'Foot switch OR CCREADY must be high
    READY var portb.4 'at start

    T var word
    J VAR WORD


    RENCA var portb.7 'FREQUENCY OUTPUT TO J1 PIN 13
    EJECT var portb.6 '100 mS PULSE TO J1 PIN 21
    on interrupt goto poo


    START:
    LOW RENCA : LOW EJECT

    WHILE READY = 0

    'zzzzzzzzzzzzzzzzzzzz ... waiting !!!
    WEND

    GOTO what to do if not ready ???


    DISABLE INTERRUPT
    poo:
    T = 1 '1mS AT 4 mHZ

    freq:

    TOGGLE RENCA
    PAUSE T 'frequency should be 500 Hz (2mS period)

    GOTO freq

    RESUME
    ENABLE INTERRUPT

    end

    NOTE : RESUME and ENABLE INTERRUPT are not compulsory here as program enters an endless loop ...

    Alain
    Last edited by Acetronics2; - 26th May 2006 at 17:57.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Smile little MORE Help

    and now we're here :


    'device: 16F627A master clear is on pin#4 (RA5)
    TRISA = %00010000 ' port A all outputs, except MCLR is input
    PORTB = 0
    TRISB = %00111111 'PORT B ALL INPUT, EXCEPT 6 & 7 OUTPUT
    option_REG = %01111111 'enable weak pullups on port B

    INTCON = %10001000 ' Define the interrupt origin ....YESSSS

    FOOTSW var portb.5 'Foot switch OR CCREADY must be high
    READY var portb.4 'at start

    T var word
    J VAR WORD


    RENCA var portb.7 'FREQUENCY OUTPUT TO J1 PIN 13
    EJECT var portb.6 '100 mS PULSE TO J1 PIN 21

    on interrupt goto poo


    START:
    LOW RENCA : LOW EJECT

    WHILE READY = 0

    'zzzzzzzzzzzzzzzzzzzz ... waiting !!!
    WEND

    GOTO Start 'GOTO what to do if not ready ???




    DISABLE INTERRUPT

    poo:

    IF NOT FOOTSW THEN false 'we are looking for a Portb.5 interrupt ... not PortB.4 or else

    T = 1000 '1mS AT 4 mHZ ...........Note: 1000 for MPSIM, 1 for real

    freq:

    TOGGLE RENCA
    PAUSE T 'frequency should be 500 Hz (2mS period)

    GOTO freq

    false:

    RESUME
    ENABLE INTERRUPT

    end
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I really appreciate your help, I hope you are not tired of my dumb questions!
    I tried your program; the clock starts when power is applied but nothing happens when footsw is low. When footsw goes high, the clock stops and reset will not start it. I have to turn power off and on or if I put footsw low, the clock will start again, as long as footsw is low. I put the nap statement in to see if it was seeing that part of the program; it isn't.

    I don't understand the WHILE - WEND, what is that doing?

    TRISB = %00111111 'PORT B ALL INPUT, EXCEPT 6 & 7 OUTPUT
    option_REG = %01111111 'enable weak pullups on port B
    FOOTSW var portb.5 'Foot switch OR CCREADY must be high
    READY var portb.4 'at start

    T var word
    J VAR WORD


    RENCA var portb.7 'FREQUENCY OUTPUT TO J1 PIN 13
    EJECT var portb.6 '100 mS PULSE TO J1 PIN 21
    on interrupt goto poo
    START:
    LOW RENCA : LOW EJECT

    WHILE READY = 0
    WEND
    GOTO START
    DISABLE INTERRUPT
    poo:
    IF NOT FOOTSW THEN FALSE
    nap 6
    T = 100

    freq:

    toggle renca 'frequency should be 500 Hz (2mS period)
    PAUSEus T*7 ' 1 mS at 4 mHz

    GOTO freq
    false:
    RESUME
    ENABLE INTERRUPT

    end

  4. #4
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I had a thought and used this code:
    IF footsw = 0 THEN LOW portb.5
    IF footsw =1 THEN poo

    I figgured that since portb.5 was changed to an output, it could not generate an interupt; but the clock does not run so nothing happens.

    I think I will take a break and go do something physical.

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Russ Kincaid
    I really appreciate your help, I hope you are not tired of my dumb questions!
    I tried your program; the clock starts when power is applied but nothing happens when footsw is low.

    > YOU must define what the pic does if ready is low !!! I Wrote something the program to run ... ( GOTO start ) ... so program just loops !!!

    When footsw goes high, the clock stops and reset will not start it.

    > No reason the clock stops ... except ...

    > mmmhhh, I do not see PORTA settings anymore ...and is Reset tied to Vcc ???
    > Got it ... we must add CMCON = 7 at the program top !!! to turn comparators OFF

    I have to turn power off and on or if I put footsw low, the clock will start again, as long as footsw is low. I put the nap statement in to see if it was seeing that part of the program; it isn't.

    I don't understand the WHILE - WEND, what is that doing?

    > As long as READY = 0 does the following lines ... here, as there is nothing to do, it just verfies READY state ... and also allows interrupts !!!



    TRISB = %00111111 'PORT B ALL INPUT, EXCEPT 6 & 7 OUTPUT
    option_REG = %01111111 'enable weak pullups on port B
    FOOTSW var portb.5 'Foot switch OR CCREADY must be high
    READY var portb.4 'at start

    T var word
    J VAR WORD


    RENCA var portb.7 'FREQUENCY OUTPUT TO J1 PIN 13
    EJECT var portb.6 '100 mS PULSE TO J1 PIN 21
    on interrupt goto poo
    START:
    LOW RENCA : LOW EJECT

    WHILE READY = 0
    WEND
    GOTO START
    DISABLE INTERRUPT
    poo:
    IF NOT FOOTSW THEN FALSE
    nap 6
    T = 100

    freq:

    toggle renca 'frequency should be 500 Hz (2mS period)
    PAUSEus T*7 ' 1 mS at 4 mHz

    GOTO freq
    false:
    RESUME
    ENABLE INTERRUPT

    end
    > Pauseus 700 won't give 500 Hz ...

    Alain
    Last edited by Acetronics2; - 27th May 2006 at 13:46.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Enlightments ???

    Hi, Russ

    For those who follow the thread ...

    Here is the MPLAB Project.

    The .BAS file is dirctly usable ... the .Hex too !!!

    Alain
    Attached Files Attached Files
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I copied your program, my hex file is different: it starts with 020000002C28AA but your hex file starts with 020000040000FA and then has 020000002C28AA. The last two lines of the hex files agree, but everything in between is different. I double-checked and did not make an error in copying the program. Do you suppose my assembler is corrupted?

    Russ

  8. #8
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    I compared the .ASM files: If it is true that lines starting with semicolon are comments, and if lines starting at the far left edge are wraparound from the previous comment, then there are no differences in the files. Otherwise, there are significant differences. So, if the .ASM files are the same, why would the .HEX files be different?

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 15:46
  2. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 20:12
  3. 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, 09:12
  4. while wend problem
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 19th March 2007, 03:53
  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, 23: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