Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Start, Stop, Pause and Reset ...

Status
Not open for further replies.

patricktran

New Member
Hi everyone,
I ve done a code of running a timer 1 of pic 16f877 with 7 seg display of second, minutes... I am wondring how to implement 4 buttons of start, stop, pause and reset the timer.
This is what I think:

1. Start: I will turn the TMR1 on
Code:
       bsf T1CON, TMR1ON

2. Stop:
Code:
       bcf T1CON, TMR1ON

3. Reset: = Stop then Reset
Code:
       bcf T1CON, TMR1ON 
                ; then reload the preset values for TMR1: TMR1H and TMR1L

4. Pause: :?: I dont know :roll:

Can someone please help me out?
Thanks alot.
Patrick :)
 
4. Pause: I dont know

Pause that is save TMR1L and TMR1H to TEMPL and TEMPH. Stop the timer. If we get Start again, check out TEMPL and TEMPH, if TEMPL or TEMPH <> zero, load TEMPL and TEMPH to TMR1L and TMR1H and bsf TMR1ON. If get Start but TEMPL and TEMPH == 0 then load preset value as RESET.

To choose the status START, STOP, RESET, PAUSE, choose interrupt as portB changed, and check the relative bits.

everything will be clear.
 
If you just stop the timer then TMR1H and TMR1L will retain there values...That's all you have to do to pause ...
 
Oh, so
Pause = Stop timer Then start without loading the preset values
So I think we dont need to save the TIMR1L or TMR1H as when we stop, the values wont change. (therefore, we dont check if the values are equal to 0)

To choose the status START, STOP, RESET, PAUSE, choose interrupt as portB changed, and check the relative bits.
I dont quite get this idea. I am using portB for outputting the LEDs... Can I just use few push buttons in port A?

Thanks
 
Pause = Stop timer Then start without loading the preset values
So I think we dont need to save the TIMR1L or TMR1H as when we stop, the values wont change. (therefore, we dont check if the values are equal to 0)

Do as I said help you to use tmr1 for other tasks. It's the only difference. And as my experience, RAM is large enough, and whenever you don't use something, you save it into RAM, and re-read it when you need.

For example, if you use a polaroid 6500, you need to read the sensor everytime to press pause. You can make tmr1 free to use capture mode with another prescaler and another value. After that, you turn off capture mode when START is pressed, then continue to use tmr1 to wait.

I dont quite get this idea. I am using portB for outputting the LEDs... Can I just use few push buttons in port A?

Yes, you can use port A, but you need to scan portA for the change of buttons. That is if your program is quite long, you may lost the signal. If your program is short, everything is oki. Why don't you use portA to output leds, and using portb for buttons? It's the same, but you can use interrupt in this case, and that is the most rapid response.
 
Hi, thanks for ur reply. I tried to write a simple code implementing buttons with Buzzer. Nothing works !!!! Sadly... :(

Code:
title  "ledon - Turn on a LED when a Button is Pressed" 

    
   include "D:/p16F877.inc" 
   __config (_CP_OFF & _PWRTE_ON & _HS_OSC & _WDT_ON & _BODEN_ON & _LVP_OFF & _DEBUG_ON) 
   errorlevel -302  

;;;;;;;;Vectors  ;; 
   org   H'000' 
   goto   MainLine 


Initial 

   bcf      STATUS,RP0   ; 
   bcf      STATUS, RP1   ; Bank 0 selected 
   clrf     PORTC 
   clrf     PORTA
 
   bsf      STATUS,RP0   ; Bank 1 selected 
   movlw    b'11111110'  ; Port  C pin 0 Output to speaker
   movwf    TRISC 

   movlw    b'00000011'  ; Port  A pin 0,1 input to 2 buttons
   movwf    TRISA

   bcf      STATUS,RP0   ; Bank 0 selected 
   return 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

MainLine 
   call    Initial 

MainLoop 
    btfsc   PORTB,0     ; check Button 1, if it is not pushed, skip the next step 
    call    BEEP 
    btfsc   PORTB,1     ; check Button 2, if it is not pushed, skip the next step 
    call    NOBEEP 
    goto    MainLoop

BEEP
                BCF     STATUS, RP0        ; Bank0
                BSF     PORTC, 0           ; BEEP ON
                RETURN


NOBEEP
                BCF     STATUS, RP0        ; Bank0
                BCF     PORTC, 0           ; BEEP OFF
                RETURN
I feel very hard to get a signal from a button, even logically, it is simple, just HIGH and LOW only in a pin when button is pushed or not....
Please help
Thanks
 
Things that come to mind at first glance:
You've got the WDT on (config _WDT_ON) while there are'nt any CLRWDT lines in your code, eighter you don't use the WDT, or eighter you need to reset it some places in your program. Now while this shouldn't be the cause of nothing at all working, it is something you should change.

Then you've got _DEBUG_ON for the In circuit debugger. Are you using a in circuit debugger? if not, turn it off, it takes over some of the io pins.

Are you sure you've connected the buttons right this time ? How did you connect them exactly, can you post a scematic?

and secondly, did you connect the buzzer directly to the pic? if so, how much current does it require?

And, are you sure the pic runs? did you ever test a simple 'blink a led' program on it to see you've got everthing correctly setup and it actually runs ?
 
Oh thanks.
I did actually copy the line of configuration from somewhere else. I dont really understand all.
I deleted _DEBUG_ON, as it will take over some IO pins. I dont want it.
The push buttons and buzzer are connected directly to the PIC. I tested the PIC carefully, it works with an LED blinking simple. I dont know why I have problems with the port sensing, I mean the push button does not send a signal to the PIC. I doubt the program has something wrong then...
Pat :roll:
 
Status
Not open for further replies.

Latest threads

Back
Top