Tutorial 02 - Assembler Delay Inside Delay (LO3 & LO4)
Tutorial 02 - Assembler Delay Inside Delay (LO3 & LO4)
Assume that two LED’s are connected to PIC16F877A or MSP430 port 2 pin 1 and 2, all the
other pins are connected to some external sensors and actuators. Write the assembly code (with
comments) to blink LED’s one after the other. LED’s should be continuously blinked with a
delay. You are requested to write a delay subroutine that contains one delay loop inside another
delay loop i.e. if you have a delay loop with 0xFF, you should run this loop for 0xFF times using
another delay loop. There is a switch connected to port 2 pin 3, blink process should stop when
this switch is closed.
Please note that, you are not allowed to distract the operation of the other pins and ports of the
microcontroller.
Solution
; PIC16F877A Configuration Bit Settings
; Assembly source line config statements
; CONFIG
CONFIG FOSC = EXTRC ; Oscillator Selection bits (RC oscillator)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled)
CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG BOREN = OFF ; Brown-out Reset Enable bit (BOR disabled)
CONFIG LVP = OFF ; Low-Voltage (Single-Supply) In-Circuit Serial Programming
Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
CONFIG CPD = OFF ; Data EEPROM Memory Code Protection bit (Data EEPROM
code protection off)
CONFIG WRT = OFF ; Flash Program Memory Write Enable bits (Write
protection off; all program memory may be written to by EECON control)
CONFIG CP = OFF ; Flash Program Memory Code Protection bit (Code
protection off)
;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN
;---------end initialising-------------
BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1
MOVLW 0X05
MOVWF delay1
MOVWF delay2
;Initialising
MAIN:
BSF PORTB, 0
call delay_start
BCF PORTB, 0
call delay_start
goto MAIN
delay_start:
DECFSZ delay1
goto delay_start
MOVLW 0XFF
MOVWF delay1
DECFSZ delay2
goto delay_start
MOVLW 0XFF
MOVWF delay2
return
END start