LED Blinking while main does something else


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2015
    Posts
    5

    Default LED Blinking while main does something else

    Hello, I am new to PIC programming and the forum so please be gentle. I was hoping someone could offer some suggestions on a program. I am using a PIC16f628 to check for a button press (this all works) and I have one pin set for High for a steady LED. I am trying to also have a second LED blink continuously while the main program keeps looping (checking for button presses. I am trying to use the blink LED:

    main:
    High LED5 ' Turn on LED connected to PORTB.0
    Pause 1000 ' Delay for .5 seconds
    Low LED5 ' Turn off LED connected to PORTB.0
    Pause 1000


    readbutton1:

    Pause 30
    Button bt1,0,40,0,B1,0,readbutton2
    Toggle LED1 ' Toggle LED if pressed

    readbutton2:
    Button button2,0,40,0,B2,0,readbutton1
    Toggle LED2 ' Toggle LED if pressed
    goto readbutton1

    If I have it return to main, then it blinks but the button checks are erratic. I am trying to get away from having a 555 timer in the circuit just to provide a blinking LED and was hoping something SIMPLE would work.
    Any advice would be greatly appreciated.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,588


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    Darrel's blinky led is what you need.

    Robert

  3. #3
    Join Date
    May 2015
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    Thank You Robert, I will give that a try

  4. #4
    Join Date
    May 2015
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    Hello Robert,

    When compiling the Blinky code I get these ASM errors, using PBP3 (MPLABX IDE) with PIC16f628. Any ideas on the errors?

    Name:  Untitled.png
Views: 676
Size:  12.6 KB

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    as the error message suggests , add these lines to your code

    wsave VAR BYTE $70 SYSTEM ' location for W if in bank0
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2

  6. #6
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    I've never used the Button command before but here's something simple to try.
    You'll probably need to modify your readbutton routines so it returns to the Main loop after testing for button activity.

    Code:
    x VAR BYTE
    
    main:
    High LED5 ' Turn on LED connected to PORTB.0
    
    FOR x = 0 TO 250  ' Loop here for 1 second while monitoring
      PAUSE 4
      GOSUB readbutton1
      GOSUB readbutton2
    NEXT x
    
    Low LED5 ' Turn off LED connected to PORTB.0
    
    FOR x = 0 TO 250  ' Loop here for 1 second while monitoring
      PAUSE 4
      GOSUB readbutton1
      GOSUB readbutton2
    NEXT x
    
    GOTO main
    
    
    readbutton1:
      Button bt1,0,40,0,B1,0,readbutton2      ' main instead of redabutton2?
      Toggle LED1 ' Toggle LED if pressed
    RETURN
    
    readbutton2:
      Button button2,0,40,0,B2,0,readbutton1   ' main instead of redabutton1?
      Toggle LED2 ' Toggle LED if pressed
    RETURN
    
    END
    Louie

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    just read the "DT interrupts" file comments header....

    explanation is there !

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  8. #8
    Join Date
    May 2015
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    Richard, thanks for pointing out what was clearly staring me in the face. I will also give LinkMTech version a try. I really appreciate the help.

    Thanks,
    Don

  9. #9
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default The best broth is made in the oldest pot

    I sometimes like to use "old fashion" systems like "autonomous" blinking leds like, i.e., these ones here; there are many others - just google around.

    So when you need blinking led, just set the respective PORT and do what ever you need to and when done, reset the PORT ;-)

    No interrupts, no subroutines, just two lines of code.....
    Roger

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: The best broth is made in the oldest pot

    But if you do it the software way, you can be sure that te program is running and did not crash.

    Ioannis

  11. #11
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    You're right Ioannis
    Roger

  12. #12
    Join Date
    May 2015
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    OK, I finally had some time to get back to it. However the code compiles fine but I don't get any output on B1. If anyone can point me to what Im missing please do. I am using a 16f628. Attached is the PBP3 code that complies. Thank You in advance.

    wsave VAR BYTE $70 SYSTEM
    LED1 VAR PORTB.1


    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts



    CMCON = 7
    TRISB = 0
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON = $31 ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    Main:
    PAUSE 1
    GOTO Main

    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    @ INT_RETURN

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: LED Blinking while main does something else

    If anyone can point me to what Im missing please do.
    no. 1 putting code in code tags
    notice how all the necessary indenting is now lost

    Code:
    wsave VAR BYTE $70 SYSTEM
     LED1 VAR PORTB.1
    
    
     INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
     INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    
    
    
     CMCON = 7
     TRISB = 0
     ASM
     INT_LIST macro ; IntSource, Label, Type, ResetFlag?
     INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
     endm
     INT_CREATE ; Creates the interrupt processor
     ENDASM
    
     T1CON = $31 ; Prescaler = 8, TMR1ON
     @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    
     Main:
     PAUSE 1
     GOTO Main
    
     '---[TMR1 - interrupt handler]--------------------------------------------------
     ToggleLED1:
     TOGGLE LED1 
     @ INT_RETURN
    no 2. posting complete code

    the "configuration word/s" are a vital part of pic code , having to speculate makes diagnosis a hit and miss affair

    no 3. posting a sketch/description of your setup
    led1 is on what pin? , what resistor? . is mclr high ? , what vcc ? , xtal /ext clock/intosc ?

Similar Threads

  1. Blinking LED will not Blink
    By andybarrett1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 24th September 2014, 22:20
  2. PIC16F819 LED not blinking
    By ronbowalker in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 1st December 2009, 03:04
  3. blinking LED
    By kindows in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 31st July 2009, 17:08
  4. PIC18f452 blinking led ?
    By iugmoh in forum General
    Replies: 5
    Last Post: - 7th March 2008, 15:12
  5. Why is my LED not blinking?
    By Gary Goddard in forum General
    Replies: 14
    Last Post: - 1st January 2007, 21:23

Members who have read this thread : 1

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