0% found this document useful (1 vote)
125 views

LAB-02 Write The Source Code in MPLAB Assembler For Glowing LED On Port B in A Sequence Such As: Time Led1 Led2 Led3 Led4

The code sequences the blinking of 4 LEDs (LED1-LED4) on Port B over 6 seconds by turning each one on for 1 second in sequence and then repeating the pattern. It uses timers, delay subroutines, and a GOTO statement to sequence through turning on each LED individually with a 1 second delay between changes before repeating the cycle.

Uploaded by

Eysha qureshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
125 views

LAB-02 Write The Source Code in MPLAB Assembler For Glowing LED On Port B in A Sequence Such As: Time Led1 Led2 Led3 Led4

The code sequences the blinking of 4 LEDs (LED1-LED4) on Port B over 6 seconds by turning each one on for 1 second in sequence and then repeating the pattern. It uses timers, delay subroutines, and a GOTO statement to sequence through turning on each LED individually with a 1 second delay between changes before repeating the cycle.

Uploaded by

Eysha qureshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

LAB-02

Write the source code in MPLAB assembler for glowing LED on Port B in a sequence such as:

Time Led1 Led2 Led3 Led4

0 ON OFF OFF OFF

Is OFF ON OFF OFF

2s OFF OFF ON OFF

3s OFF OFF OFF ON

4s ON ON ON ON

5s OFF OFF OFF OFF

6s GOTO 1st step and repeat the sequence

CODE
; OSILLATOR 4MHZ

;Equate Section

TMR0 EQU 1

STATUS EQU 3

PORTA EQU 5

PORTB EQU 6

PORTC EQU 7

PORTD EQU 8

PORTE EQU 9

TRISA EQU 85H


TRISB EQU 86H

TRISC EQU 87H

TRISD EQU 88H

TRISE EQU 89H

OPTION_REG EQU 81H

ZEROBIT EQU 2

count1 EQU 20H

count2 EQU 21H

COUNT3 EQU 22H

;**********************************

LIST P=16F877A

ORG 0

GOTO START

__CONFIG H'3F72'

;*****DELAY ROUTINES************

;1S DELAY

DELAY CLRF TMR0


LOOP MOVF TMR0,W

SUBLW .255

BTFSS STATUS,ZEROBIT

GOTO LOOP

RETLW 0

DELAY_1S MOVLW .15

MOVWF COUNT3

LP CALL DELAY

DECFSZ COUNT3

GOTO LP

RETLW 0

DELAY_HS MOVLW .8

MOVWF COUNT3

LP1 CALL DELAY

DECFSZ COUNT3

GOTO LP1

RETLW 0

;****************************

delay movlw .255

movwf count1
movlw .255

movwf count2

a decfsz count1,1

goto a

decfsz count2,1

goto a

RETLW 0

;CONFIGURATION SECTION

START

BANKSEL TRISD

MOVLW B'00000000'

MOVWF TRISD

MOVLW B'00000000'

MOVWF TRISC
MOVLW B'00000111'

MOVWF OPTION_REG

BANKSEL PORTD

CLRF PORTC

CLRF PORTD

;PROGRAM STARTS NOW

call delay

BEGIN MOVLW .1

MOVWF PORTD

CALL DELAY_1S

MOVLW .2

MOVWF PORTD

CALL DELAY_1S

MOVLW .4

MOVWF PORTD

CALL DELAY_1S

MOVLW .8

MOVWF PORTD

CALL DELAY_1S

MOVLW .15

MOVWF PORTD
CALL DELAY_1S

MOVLW .0

MOVWF PORTD

CALL DELAY_1S

GOTO BEGIN

END
ISIS diagram:
3D LAYOUT :
Ares layout diagram:

You might also like