;tmr0 test - Nigel Goodwin 2004
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0
call Initialise
Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
nop ;the nop's make up the time taken by the goto
nop ;giving a square wave output
movlw d'115'
call Delay16 ;this waits for a while!
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
movlw d'115'
call Delay16
goto Loop ;go back and do it again
Initialise
bsf STATUS,RP0 ;select page 1
movlw B'00000010' ;fosc/256 --> TMR0
movwf OPTION_REG ; /
bcf STATUS,RP0 ;select page 0
clrf TMR0
bcf INTCON,T0IF ;clear flag
bcf INTCON,T0IE ;enable mask
return
;delay16 waits for approx 16.4mSecs using TMR0 interrupts
;fosc speed is 4Mhz.
Delay16
movwf TMR0 ;set tmr0 from W
CheckAgain
btfss INTCON,T0IF ;timer overflowed?
goto CheckAgain ;no check again
bcf INTCON,T0IF ;clear flag
return
end