0% found this document useful (0 votes)
13 views3 pages

Tutorial 02 - Assembler Delay Inside Delay (LO3 & LO4)

The document provides assembly code for blinking two LEDs connected to a PIC16F877A or MSP430 microcontroller, with a delay subroutine that includes nested delay loops. The blinking process is controlled by a switch that stops the blinking when closed, while ensuring that other pins and ports remain unaffected. Configuration settings for the microcontroller are also included to set up the necessary parameters for operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Tutorial 02 - Assembler Delay Inside Delay (LO3 & LO4)

The document provides assembly code for blinking two LEDs connected to a PIC16F877A or MSP430 microcontroller, with a delay subroutine that includes nested delay loops. The blinking process is controlled by a switch that stops the blinking when closed, while ensuring that other pins and ports remain unaffected. Configuration settings for the microcontroller are also included to set up the necessary parameters for operation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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)

// config statements should precede project file includes.


#include <xc.inc>

;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN

delay1 equ 0x20


delay2 equ 0x21

PSECT CODE, DELTA=2

;---------end initialising-------------

BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1

;MOVLW 0x06 ; Configure all pins as digital


;MOVWF ADCON1 ; set all pins as digital inputs

CLRF TRISB ; Set RA<3:0> as inputs

BCF STATUS, 5 ; Bank0


MOVLW 0X00
CLRF PORTB

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

You might also like