Need Help with pic 10f200 Timer

Status
Not open for further replies.

jsreis

Newbie level 3
Joined
Jun 29, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
41
Hello, I am new to pic microcontroller and need help.

I need to control a led AT GPIO,0 when a push button is pressed once the led will turn on and stay on for 90 minutes and then turn off waiting for the button be pressed again. but in between that time if I push the button for 2 sec will turn off led.
I try using delay rotine for 90 minutes and work fine but the problem is while the delay rotine was runing if I press the button for 2 sec nothing happen. so I have to use the TMR0 register and doing that I can't get long time delays.
please help me how I have to do.
here is some of my code.
Thanks,

SetUp
movwf OSCCAL ; update register with factory cal value
movlw b'10000111' ;10000111
;-0------, weak pullups ON
;--0-----, set TMR0
;---0----, set TOSE rising edge
;----0---, set PSA presacler as Timer0
;-----111, set presacale to 256
option ;increments at every 256us
movlw b'00001000' ;GPIO Register GPO,GP3
tris GPIO ;GP3 input, all others outputs
clrf GPIO ;make outputs LOW


Start

call Delay1 ;20mS debounce delay
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto Start ;loop
call beep1 ;40mS beep
bsf GPIO,0 ;activate backlight
call Delay2

clrf cnt_65ms
Timer_90
clrf TMR0
; clrf cnt_65ms

w_tmr0
btfss GPIO,3
goto power_dw
movf TMR0,w
xorlw .255
btfss STATUS,Z
goto w_tmr0
incf cnt_65ms,f
movlw .955
xorwf cnt_65ms,w
btfss STATUS,Z
goto Timer_90

movlw .125
subwf cnt_65ms,w
btfss STATUS,C
call beep1
bcf GPIO,0
call beep1
; btfss GPIO,3
goto SetUp


power_dw ;look at sw if pushed more than 2sec turn off backlight
call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-2
call Delay2 ;delay 1 second
; call Delay2 ;delay 1 second
btfsc GPIO,3 ;Is Sw LOW? - pushed
goto $-5
bcf GPIO,0 ;de-activate Backlight LED
call beep2 ;40mS beeps
call Delay2
call Delay2
nop
goto SetUp


;******************************************************************
; subroutines *
;******************************************************************

beep2 call beep1 ; 40mS beep
call Delay1 ; 20mS delay

beep1 movlw .40
movwf temp
goto $+1
decfsz DelA,1
goto $-2
movlw b'00000100' ;spkr pin
xorwf GPIO,F ;spkr bit will toggle
decfsz temp,1
goto $-6
retlw 00

Delay1 movlw .20 ; 20mS delay
movwf temp
goto $+1
decfsz DelA,1
goto $-2
decfsz temp,1
goto $-4
retlw 00


Delay2 movlw .50 ;1 Second delay
movwf DelB
call Delay1
decfsz DelB,1
goto $-2
retlw 00

END ; end of program
 



Hi,

With the code you have posted being incomplete it cannot be compiled and also there are errors.

The line movlw .955 is not valid, a register can only contain a value from 0 to 0xFF = decimal 0 to 255, so you need to use 2 registers for that whole action.
 


ok I understand now my question can I generate a 90 minutes timer with this Pic 10f200? if so can you help me to do the timer routine.

I did try using the delay routine for 90 minutes but using the delay i have a problem if I push the button for 2 sec nothing happens because while in that delay the processor does not respond. if that is possible please let me now.
thanks.
 

Hi,

Thought you had solved it ..

I have just run your code in a simulator and it seems to work ok and shut off only if the switch is pressed for 2 seconds, under 2 seconds and it keeps running the main timer .

Have just changed the .995 to .95 to make it a valid time period , and more suitable to test things with.

You will need to use 2 registers to count .995, perhaps easier to count up and compare rather than preload and count down ?
Also added the rest of the code at the beginning to set up things properly.

Code:
;**********************************************************************

	list      p=10F200            ; list directive to define processor
	#include <p10F200.inc>        ; processor specific variable definitions

	__CONFIG   _MCLRE_OFF & _CP_OFF & _WDT_OFF   ; mcle is off because you use GPIO3

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file. 
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS
temp 	 	EQU     0x10        ;example variable definition
cnt_65ms	equ 0x11
DelA		equ 0x12
DelB		equ 0x13


;**********************************************************************
	ORG     0xFF             ; processor reset vector

; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.

	ORG     0x000             ; coding begins here




SetUp
		movwf OSCCAL ; update register with factory cal value 
		movlw b'10000111' ;10000111 
		;-0------, weak pullups ON
		;--0-----, set TMR0
		;---0----, set TOSE rising edge
		;----0---, set PSA presacler as Timer0
		;-----111, set presacale to 256 
		option ;increments at every 256us
		movlw b'00001000' ;GPIO Register GPO,GP3
		tris GPIO ;GP3 input, all others outputs
		clrf GPIO ;make outputs LOW
		
		
Start
		
		call Delay1 ;20mS debounce delay
		btfsc GPIO,3 ;Is Sw LOW? - pushed
		goto	Start ;loop
		call beep1 ;40mS beep
		bsf	 GPIO,0 ;activate backlight
		call	Delay2
		
		clrf	cnt_65ms
Timer_90
		clrf	TMR0
		;	clrf	cnt_65ms
w_tmr0
		btfss	GPIO,3
		goto	 power_dw
		movf	 TMR0,w
		xorlw	 .255
		btfss	 STATUS,Z
		goto	 w_tmr0
		incf	 cnt_65ms,f
		movlw .95
		xorwf	 cnt_65ms,w
		btfss	 STATUS,Z
		goto	 Timer_90
		
		movlw	.125
		subwf	cnt_65ms,w
		btfss	STATUS,C
		call	beep1
		bcf	 GPIO,0
		call	beep1
		;	btfss	GPIO,3
		goto	SetUp
		
		
power_dw	 ;look at sw if pushed more than 2sec turn off backlight
		call	Delay2	 ;delay 1 second
		btfsc GPIO,3 ;Is Sw LOW? - pushed
		goto	$-2
		call	Delay2	 ;delay 1 second
		;	 call	Delay2	 ;delay 1 second
		btfsc GPIO,3 ;Is Sw LOW? - pushed
		goto	$-5
		bcf	 GPIO,0 ;de-activate Backlight LED
		call beep2 ;40mS beeps
		call	Delay2
		call	Delay2
		nop
		goto	SetUp
		
		
		;************************************************* *****************
		; subroutines *
		;************************************************* *****************
		
beep2 call beep1 ; 40mS beep
		call	Delay1 ; 20mS delay
		
beep1 movlw .40 
		movwf	temp
		goto	$+1
		decfsz	DelA,1
		goto	$-2
		movlw b'00000100' ;spkr pin
		xorwf GPIO,F ;spkr bit will toggle
		decfsz	temp,1	
		goto	$-6	
		retlw 00
		
Delay1	movlw .20 ; 20mS delay 
		movwf	temp	
		goto	$+1
		decfsz	DelA,1
		goto	$-2	
		decfsz	temp,1
		goto	$-4	
		retlw 00 
		
		
Delay2 movlw	.50	 ;1 Second delay
		movwf	DelB
		call	Delay1
		decfsz	DelB,1
		goto	$-2
		retlw	00 
		
		END ; end of program
 

Attachments

  • 000018.jpg
    37.1 KB · Views: 113

Hi, I get it running I am using a delay routine and inside the routine I look for the pushbutton if pressed call power down.
Thanks for your help.




 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…