Hello,
I am running the simple program from here (I included the code at the end for convinience):
I would like to doublecheck if my logic is correct.
In the following:
delay clrf tmr0 ; clear TMR0, start counting again btfss tmr0, 0 ; if bit 0 = 1 goto again ; no, then check again btfss tmr0, 1 ; if bit 1 = 1 goto again ; no, then check again btfss tmr0, 2 ; if bit 2 = 1 goto again ; no, then check again btfss tmr0, 3 ; if bit 3 = 1 goto again ; no, then check again btfss tmr0, 4 ; if bit 4 = 1 goto again ; no, then check again btfss tmr0, 5 ; if bit 5 = 1 goto again ; no, then check again btfss tmr0, 6 ; if bit 6 = 1 goto again ; no, then check again btfss tmr0, 7 ; if bit 7 = 1 goto again ; no, then check again return ; else exit delay
- It the following correct? tmr0, 0 is true after 1 clock cycle tmr0, 1 - 3 tmr0, 2 - 7 tmr0, 3 - 15 tmr0, 4 - 31 tmr0, 5 - 63 tmr0, 6 - 127 tmr0, 7 - 255
- If I want the delay to last 5 clock cycles (for example) - do I need to do the following? I tried running delay loop twice, and the delay was indeed 2xdelay, but haven't tried the following yet.
delay1 clrf tmr0 ; clear TMR0, start counting again btfss tmr0, 0 ; if bit 0 = 1 goto again ; no, then check again btfss tmr0, 1 ; if bit 1 = 1 goto again ; no, then check again return ; else exit delay
delay2 clrf tmr0 ; clear TMR0, start counting again btfss tmr0, 0 ; if bit 0 = 1 goto again ; no, then check again return ; else exit delay
delay3 clrf tmr0 ; clear TMR0, start counting again btfss tmr0, 0 ; if bit 0 = 1 goto again ; no, then check again return ; else exit delay
- When doing question 1, shouldn't we account for the time it takes to excecute an instruction (I guess we assume it takes 1 clock cycle to excecute 'btfss' and 0 clock cycles to excecute 'goto' instruction?
- With PIC16F84A, TMR0 runs at 1/4 of crystal oscillator's speed and then you need to use OPTION register to divide frequency (multiply time) by 1/2(2), 1/4(4), etc. I could not run at 1/2(2), but all other prescaler options worked fine. Any ideas why?
- Going back to the previous question (q.4), I would like to have higher frequency to have better resolution. I looked up on digikey's website, and it looks like the highest I can have with PDIP package is
Thanks, Vitaliy
--------------------------------------------------------------------------------------------- Clock.asm
; FILE: Clock.asm ; AUTH: (Your name here) ; DATE: (date) ; DESC: 1.0 - Internal timer, blink LED every 32.8 msec ; NOTE: Tested on PIC16F84-04/P. ; 4 MHz crystal yields 1 MHz internal clock frequency. ; "option" is set to divide internal clock by 256. ; This results in 1 MHz/256 = 3906.25 Hz or 256 usec. ; tmr0 bits 0 through 7 (255 decimal) is checked, thus yielding ; 255*256 usec = 65.28 msec delay loop ; REFs: Easy Pic'n p. 113
list p=16F84 radix hex
;---------------------------------------------------------------------- ; cpu equates (memory map) portB equ 0x06 ; (p. 10 defines port address) tmr0 equ 0x01 ;----------------------------------------------------------------------
org 0x000 start clrwdt ; clear watchdog timer movlw b'11010111' ; assign prescaler, internal clock ; and divide by 256 see p. 106 option movlw 0x00 ; set w = 0 tris portB ; port B is output clrf portB ; port B all low go bsf portB, 0 ; RB0 = 1, thus LED on p. 28 call delay call delay bcf portB, 0 ; RB0 = 0, thus LED off call delay call delay goto go ; repeat forever
delay clrf tmr0 ; clear TMR0, start counting again btfss tmr0, 0 ; if bit 0 = 1 goto again ; no, then check again btfss tmr0, 1 ; if bit 1 = 1 goto again ; no, then check again btfss tmr0, 2 ; if bit 2 = 1 goto again ; no, then check again btfss tmr0, 3 ; if bit 3 = 1 goto again ; no, then check again btfss tmr0, 4 ; if bit 4 = 1 goto again ; no, then check again btfss tmr0, 5 ; if bit 5 = 1 goto again ; no, then check again btfss tmr0, 6 ; if bit 6 = 1 goto again ; no, then check again btfss tmr0, 7 ; if bit 7 = 1 goto again ; no, then check again return ; else exit delay
end ;---------------------------------------------------------------------- ; at burn time, select: ; memory uprotected ; watchdog timer disabled ; standard crystal (4 MHz) ; power-up timer on