using 12f629 tmr0 delay

Status
Not open for further replies.

krytenrobot

New Member
i am trying to create a 1sec delay using the timer0 in the 12f629, by pre loading it with 131 and when it counts up it will overflow to zero so i can test the status z, after 125 counts that will be 4msec.
(131+125= 256 ,overflow to zero)

i have set the prescaler to 1/32 tmr0.
internal osc 4mhz

is this possible with this pic or not, i am used to using the 16f84

here is my asm file>>
;blink12F629.asm
;This program will blink a LED at 1hz connected to pin 7
;17-8-2010 D nelson


list p=12F629
include "p12f629.inc"

__CONFIG _CP_OFF & _MCLRE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _CPD_OFF &_PWRTE_OFF
errorlevel -302 ;ignore Bank warnings

;**********************************************************************
;Equates
;*************************************************************************

fileA equ 20h
fileB equ 21h
fileC equ 22h
pin7 equ 0
pin6 equ 1
pin5 equ 2
pin4 equ 3
pin3 equ 4
pin2 equ 5

Start org 0x0
nop
nop
nop
nop
nop



Setup bsf STATUS,RP0 ; swap banks
movlw b'10000100' ;prescaler tmro 1/32 pullups disabled
movwf OPTION_REG
movlw b'00101110' ;set i/o pins gp4 and gp0 as outputs
movwf TRISIO
movlw b'00000111' ;turn off comparitor
movwf CMCON
call 0x3ff ; calibrate oscillator
movwf OSCCAL
bcf STATUS,RP0
clrf GPIO
movlw d'0'
movwf INTCON ; disable all interupts
goto Main



Del1 movlw d'250' ;preload with 250// 4msec x 250=1sec
movwf fileA
Del2
movlw d'131';preload with 131
movwf TMR0
Wait movf TMR0,1
btfss STATUS,Z; has tmr0 overflowed to zero/ 32usec x 125=4msec?
goto Wait ; no do it again
Dela decfsz fileA,1 ; yes so reduce counter by 1
goto Del2

return

Main
bsf GPIO,pin7
call Del1
bcf GPIO,pin7
call Del1
goto Main

org 3ff
retlw 0x60

END
 
Code:
;--------------------------------
PS	=1:64
TMR0	=156
156X64	=9984uS
;--------------------------------
Wait_TMR0	movf	TMR0,W
		btfss	STATUS,Z
		goto	Wait_TMR0
		movlw	.100
		movwf	TMR0
		nop
		;			; add 16uS delay here
		;
		decfsz	Counter,F	; count 10mS X 100
		goto	Wait_TMR0
		movlw	.100
		movwf	Counter
		movlw	b'000000001'	; Toggle GP0
		xorwf	GPIO,F
		goto	Wait_TMR0
 
Here is a simple 1 second flasher for GPIO 4

Code:
[SIZE=2][FONT=Trebuchet MS]          
            list        p=12F629
            radix     dec
            include  "p12f629.inc"
            
                        
                        
            __CONFIG         _MCLRE_OFF & _CP_OFF & _WDT_ON & _INTRC_OSC_NOCLKOUT  ;Internal osc.
 
 
 
;************************************
;Beginning of program
;************************************
            org       0x00
            bsf        status, rp0        ;bank 1             
            bcf        TRISIO,4           ;GP4 output                   
            bcf        status, rp0        ;bank 0 
             movlw   07h                  ;turn off Comparator 
             movwf   CMCON            ;must be placed in bank 0 
             movlw  b'00010000'       ;to toggle GP4
            xorwf    GPIO,f
            call       _1Sec
            goto      $-3                   
                        
_1Sec    goto      $+1
            goto      $+1
            goto      $+1
            goto      $+1                   
            decfsz   D1,1
            goto      _1Sec
            decfsz   D2,1
            goto      _1Sec                
            retlw     00                                 
                        
            END
[/FONT][/SIZE]
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…