Академический Документы
Профессиональный Документы
Культура Документы
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
decfsz COUNT2,1
goto LoopOFF
goto Begin_LED