|
|
#1 | |
|
PIC16F84 ASM Delay program
For an assignment at college, I have to write an ASM program for the PIC16F84 microcontroller which:
Quote:
Code:
; Written by SAMUEL SAINT-PETTERSEN
; Date 19-04-2006
; File saved delay.asm
; Device PIC16F84
; Oscillator XT (4 MHz)
;
; Function Output number 2h to port B,
; delay for 0.5 second and then output
; 3h to port B.
;
; ------------------------EQUATES--------------------------
portb EQU 0x06 ; portb equates to 0x06
counter EQU 0x01 ; countera equates to 0x01
; ---------------------------------------------------------
ORG 0x00 ; origin is 0x00
start clrw ; reset W register
movlw 0x02 ; move 2h into W
tris portb ; copy W tristate, portb outputs
clrw ; reset W register
movlw 0x05 ; move 5h into W
delay movwf counter ; move 5h into countera
goto decrm ; loop to decrm
decrm decfsz counter, 1 ; decrement countera if > 0
goto delay ; loop to delay and loop if so
clrw ; reset W register
movlw 0x03 ; move 3h into W
tris portb ; copy w trisate, portb outputs
goto start ; loop back to start
end ; end the program
__________________
Sam's Py |
||
|
|
|
|
|
#2 |
|
I don't think you program is correct. The way it is now, I think it'll just loop forever, because you're always overwriting the value in counter with whatever is in W (I'm guessing 5h) at the beginning of the loop. Try putting the decremented value in W instead of placing it back into counter.
Also, with a 4MHz clock, you'll need 0.5 million non-branching instructions (each taking 4 clock cycles or 1 microsecond to execute) to get a 0.5 second delay. You need to count to way more than 5 .
__________________
"I'm an engineer, not a normal person." -Dilbert |
|
|
|
|
|
|
#3 |
|
Re: PIC16F84 ASM Delay program
edit: nevermind... I can't read
|
|
|
|
|
|
|
#4 | |
|
Re: PIC16F84 ASM Delay program
Quote:
So if a microsecond is 10^-6 of a second?
__________________
Sam's Py |
||
|
|
|
|
|
#5 |
|
Re: PIC16F84 ASM Delay program
1 microsecond is 10e-6 seconds. As it is now, your loop has 4 instructions:
Code:
delay movwf counter
goto decrm
decrm decfsz counter, 1
goto delay
__________________
"I'm an engineer, not a normal person." -Dilbert |
|
|
|
|
|
|
#7 |
|
Re: PIC16F84 ASM Delay program
No problem. You should really take a look at the datasheet for the PIC if you haven't already, especially the chapter about the instruction set.
__________________
"I'm an engineer, not a normal person." -Dilbert |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|