;------------------------------------------------- ;Program: MODdelay.ASM ;Update: 24 August 2002 ;Initial: 17 October 1991 ; ;By: Dr. Marcus O. Durham, PhD, PE ; Tulsa, OK, USA ; mod@superb.org ; www.ThewayCorp.com ;Copyright (c)1991, 2002. All rights reserved ; ;Purpose: ; A routine to show delay using instruction ; execution time. ; ; The LED on P3.5 is flashed 3 times. ; ;Processor: 8031 family ;PROM: 8k (2000H) onboard ;Crystal: 11.059 MHz ;Baud: 9600 ;Handshake: not used at this speed ;Assembler: Intel ASM51 ;################################################# ; ; ASSIGNMENTS ; ;################################################# ;BANK 0, USE W/ MATH & LOOP ;R3 EQU 03H ;loop 2, math ;R2 EQU 02H ;loop, destination size,mat ;------------------------------------------------- ;PORT USE P35 EQU 0B5H ;power led ;################################################# ; ; PROGRAM ; ;################################################# START: ;------------------------------------------------- ; When processor is reset, program control comes ; here. Jump to the first executable address ; after all interrupts reserved locations. ORG 00H LJMP INITIAL ;************************************************* ; ; INITIAL & MAIN ; ;************************************************* ORG 0070H ;Addres past reserve ;------------------------------------------------- INITIAL: ;------------------------------------------------- ; ; The procedure initializes all common routines. ; It directs traffic for initiation messages. ;------------------------------------------------- MAIN: ;------------------------------------------------- ; ; The main procedure directs traffic. ; The main orchestrates execution of the ; subroutines. ; ; The procedures are for a scoreboard (SB). ;PROCESS LCALL P35DONE ;flash P35 MAN9: SJMP MAN9 ;Repeat ;************************************************* ; ; DELAY & PORT 35 ; ;************************************************* ; ; Delay routine using NOPS and a nested loop. ; Registers R2 & R3 are used for counting loops. ; ; Count the machine cycles for each instruction. ; NOP = 1 ; MOV = 1 ; DJNZ = 2 ; LCALL= 2 ; RET = 2 ; ; The time for each loop is calculated ; MOV = 1 ; NOP = 1*count ; DJNZ = 2*count ; inside = (incount *2) + 1 ; outside= [(inside + 2)outcout] + 1 ; Plus = 4 for call ; ; Each machine cycle requires time to execute. ; This is based on the oscillator frequency. ; Time= (sec/11.059E6 cycle)(12 period/mach cy) ; = 1.08509 E-6 sec ; ;------------------------------------------------- DELAY: ;------------------------------------------------- ; ; Delay routine using NOPS and a nested loop. ; Registers R2 & R3 are used for this. MOV R3,#00H ;Outer loop counter ZDEL1: MOV R2,#00H ;Nested loop counter ZDEL2: NOP ;Delay DJNZ R2,ZDEL2 ;Nested loop, 256 x DJNZ R3,ZDEL1 ;Outer loop, 256 x RET ;Return to call ;------------------------------------------------- P35DONE: ;------------------------------------------------- ; ; Flash P3.5 when the download is complete. The ; lamp should turn on-off-on. It then remains on. CPL P3.5 LCALL DELAY CPL P3.5 LCALL DELAY CPL P3.5 RET ;************************************************* END ;Program end