0% found this document useful (0 votes)
227 views7 pages

Lecture 06 - Assembly Language Code Example For Ports Writing

This document discusses an assembly language example that blinks an LED connected to port A pin 0 of a PIC microcontroller. It describes the registers involved - PORTA, TRISA, ADCON1, and STATUS. The source code initializes these registers, then enters a loop that turns the LED on and off periodically by writing 1s and 0s to PORTA. The on and off times are set by a variable called Duration. The code uses inner and outer delay loops to control the timing. MpLab IDE is mentioned as a development system for embedded applications that allows target selection, editing, assembling, debugging and output generation.

Uploaded by

Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
227 views7 pages

Lecture 06 - Assembly Language Code Example For Ports Writing

This document discusses an assembly language example that blinks an LED connected to port A pin 0 of a PIC microcontroller. It describes the registers involved - PORTA, TRISA, ADCON1, and STATUS. The source code initializes these registers, then enters a loop that turns the LED on and off periodically by writing 1s and 0s to PORTA. The on and off times are set by a variable called Duration. The code uses inner and outer delay loops to control the timing. MpLab IDE is mentioned as a development system for embedded applications that allows target selection, editing, assembling, debugging and output generation.

Uploaded by

Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assembly Language – Writing to

the Ports
Lecture No. 6
Example 1 – Writing to the Ports
• This Example Code in Assembly Language is Aimed at Switching On
and Off an LED Periodically
• On and Off Time is Fixed, termed as ‘Duration’
• The LED is Connected to Pin ‘0’ of Port A
• Since Port A is Multi Purpose Port – Need Special Handling
Background
• Registers of Interest
• PORTA – LSB PIN used to Control the LED
• TRISA – Control PORT A as Input or Output
• ADCON1 – To make PORTA as Digital I / O Port
• STATUS – Bank Bits Status
Example 1 - The Source Code
List p=16f877A ; list directive to define processor main
BANKSEL TRISA ;Select Bank 1
#include <p16f877A.inc> ; processor specific variable
MOVLW b'00000111'
definitions MOVWF ADCON1
MOVLW b'00000000'
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & MOVWF TRISA
_PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON &
_CPD_OFF & _DEBUG_ON BANKSEL PORTA ;Select Bank 0
MOVWF PORTA ;Clear PORT A
Begin_LED
ORG 0x000 ; processor reset vector
movlw Duration
nop movwf COUNT1 ; Delay Count1
goto main ; go to beginning of program movwf COUNT2 ; Delay Count2

#define Duration 0XFF LED_ON MOVLW 0x01


MOVWF PORTA ; Switch ON LED 1
COUNT1 equ 0x20
LoopON decfsz COUNT1,1 ;Inner Delay Loop
COUNT2 equ 0x21
goto LoopON
PORTA equ 0x05 movlw Duration
TRISA equ 0x85 movwf COUNT1 ; Reset Inner Delay Loop
ADCON1 equ 0x9F decfsz COUNT2,1 ; Outer Delay Loop
goto LoopON
movlw Duration
movwf COUNT2 ; Reset Outer Delay Loop
Example 1 - The Source Code
LED_OFF MOVLW 0x02
MOVWF PORTB ; Switch OFF LEDs

LoopOFF decfsz COUNT1,1


goto LoopOFF
movlw Duration
movwf COUNT1 ; Delay Count1

decfsz COUNT2,1
goto LoopOFF

goto Begin_LED

END ; directive 'end of program'


Assembler Input / Output Files
MpLab IDE
• Microcontroller remains the Heart of Embedded Systems
• Developing Embedded System Comprises:
• Selection of Hardware (Microcontroller)
• Firmware / Software running in Microcontroller
• We Need
• A development system for embedded controllers applications
• MpLab contains All Desired Components
• Target Selection
• Editor
• Assembler / Compiler
• Debugger
• Output Generations

You might also like