coding pic16f84 questions

Thread Starter

eddy123456

Joined Feb 4, 2008
7
Hi guys,

Ive started programming and experimenting with pic16f84 using WIZC and i have a lot of question related to TMR0.

This is an example code for a timer from : http://www.boondog.com/tutorials/pic16F84/pic16f84.html#Timing


; FILE: timer1_0.asm - WORKS!
; AUTH: P.Oh
; DATE: 1.0 - 04/14/02 16:00
; DESC: 1.0 - Internal timer, blink LED every 32.8 msec
; NOTE: Tested on PIC16F84-04/P.
; Page numbers in code are in Easy Pic'n book.
; 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 bit 7 (128 decimal) is checked, thus yielding
; 128*256 usec = 32.8 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)
count equ 0x0c
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
bcf portB, 0 ; RB0 = 0, thus LED off
call delay
goto go ; repeat forever

delay clrf tmr0 ; clear TMR0, start counting
again btfss tmr0, 7 ; if bit 7 = 1
goto again ; no, then check again
return ; else exit delay

end
;----------------------------------------------------------------------
; at blast time, select:
; memory uprotected
; watchdog timer disabled
; standard crystal (4 MHz)
; power-up timer on





My code base on the tutorial :


portA equ 0x05
portB equ 0x06 ; (p. 10 defines port address)
count equ 0x0c
tmr0 equ 0x01


org 0x0000
Start bsf STATUS,RP0
movlw 0xd7 ; assign prescaler, internal clock
movwf OPTION_REG ; and divide by 256
movlw 0x00 ; set w = 0
movwf TRISB
movlw 0xff
movwf TRISA
bcf STATUS,RP0
clrf portB ; port B all low
clrf portA ; port A all low
go btfss portA,0 ;check RA0 = 1;
bsf portB,0 ; RB0 = 1, thus LED
call delay
bcf portB,0 ; RB0 = 0, thus LED off
call delay
goto go ; repeat forever

delay clrf tmr0 ; clear TMR0, start counting
again btfss tmr0, 7 ; if bit 7 = 1
goto again ; no, then check again
return ; else exit delay

end





I modified the codes so that flashing LED at portB will only happen if PortA is on. Ive decide to change most of the tutorial codes because im not familar with "option" or "tris portB" (its not what ive learned through tutorials stuff and the data sheet of PIC18f64).Here are my questions:

1) I am bit confused about the flow of the codes after it has check if RA0=1. I know that it should start the "delay" subroutine.but whats up with "again"? It is okay to assume that routines(again) can be included in subroutines(which is called in this case delay)?

delay clrf tmr0 ; clear TMR0, start counting
again btfss tmr0, 7 ; if bit 7 = 1
goto again ; no, then check again
return ; else exit delay



2) I use a Wave Analyser in WIZ-C to check the timings of the of inputs and outputs. Once RA0 (sticky switch) is turned on, RB0(LED0)wil be turned on first and then off at an intervals of 32mS. I found out that theres a lag of 39.095mS from at the instant RA0 is turned on and At the instant RB0 is turned on. From what i understand instruction cycle should be 4/(clock input,Hz) so why it is not suppose to be 100 micro seconds?

go btfss portA,0 ;check RA0 = 1;
bsf portB,0



3) Sometimes i get confused by the values of variable(say either 0/1 for portA, or 11111101 portA).

4) Ive come across codes such as this in some elaborate timer dependant codings;
btfss STATUS,C or btfss STATUS,Z
Apart from the name(C=carry bit and Z=Zero bit). I dont understand how they work.Can someone explain to me how to use them?
 
Top