0% found this document useful (0 votes)
21 views9 pages

Experiment No.3

The document describes an experiment to interface LEDs with a PIC microcontroller. The objectives are to create a program to control LEDs using a PIC microcontroller. The procedure involves using Proteus software to simulate the circuit with a PIC microcontroller, LED, and connections between them. An MPLABX code is written to turn the LED on and off. When run in Proteus, the LED is successfully controlled by the PIC microcontroller program.

Uploaded by

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

Experiment No.3

The document describes an experiment to interface LEDs with a PIC microcontroller. The objectives are to create a program to control LEDs using a PIC microcontroller. The procedure involves using Proteus software to simulate the circuit with a PIC microcontroller, LED, and connections between them. An MPLABX code is written to turn the LED on and off. When run in Proteus, the LED is successfully controlled by the PIC microcontroller program.

Uploaded by

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

Department of Bio-Medical Engineering

Faculty of Engineering & Applied Sciences


Riphah International University, Lahore, Pakistan

Program: B.Sc Bio Medical Engineering. Semester: V


Subject: EEL-311 Microprocessor and Interfacing Date: _______________

Experiment No 3: Interfacing LEDs with PIC microcontroller.


Objective:
 To create a program to interface LEDs with PIC microcontroller.

Name: …………………… SAP: …………….

Lab Performance Evaluation


No. Title Marks Obtained Marks
1 Ability to Conduct Experiment 05
2 Data Evaluation and Report 05
Total 10

Lab Report Evaluation

No. Title Marks Obtained Marks


1 Organization & Structure 05
2 Data Presentation and Calculations 05
Total 10

Remarks (if any): …………………………………..………………………

Name and Signature of Faculty: …………………………………………….


Introduction:
Interfacing an LED (Light Emitting Diode) with a PIC microcontroller is a common and
straightforward task. We can use a digital output pin of the PIC microcontroller to control the
LED. I mention the procedure on how i interface an LED with a PIC microcontroller.

Components Needed:
PC
Software (Proteus 8, MPLABX IDE 5.20v)

Procedure:
1. First step is to open the “Proteus” software then make a new project.

Figure 1

2. Then go to “component mode” and search for “pic18f458” and past it on Editing
Window.
Figure 2

3. Then again go to the component mode and search for “LED” and past it on the Editing
Window.

Figure 3

4. Then select the “generator mode” and select the “SINE” to get the sine wave and set 5 v
to operate the led and connect it on pin1 of IC.
Figure 4 Figure 5

5. Then connect the led anode with pin 33 and cathode with the ground.

Figure 6

6. Now open the MPLABX then make new file then write the code to oprate led on pin 33.
7. Ten run it. The code automatically generate hex file.
Figure 7

8. Now again open the Proteus.

9. Then select the pic18 and right click on the pic18 and click “ Edit Properties” then select
the hex file created in MPLABX.

Figure 8 Figure 9
10. Now run the “Editing Window” then we have the following results.

Figure 10 Figure 11

MPLABX Program :

;**************************
; *
; Files required: P18F458.INC *
; *
;**************************

LIST P=18F458, F=INHX32 ;directive to define processor and file format #include
<P18F458.INC> ;processor specific variable definitions

;**************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please
;see the .inc file for futher details on notation. Below are a few examples.
; Oscillator Selection:

CONFIG OSC = HS ;LP

;**************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.

UDATA

WREG_TEMP RES 1 ;variable in RAM for context saving


STATUS_TEMP RES 1 ;variable in RAM for context saving
BSR_TEMP RES 1 ;variable in RAM for context saving UDATA_ACS
EXAMPLE RES 1 ;example of a variable in access RAM

;**************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here DATA_EEPROM CODE
0xf00000
DE "Test Data",0,1,2,3,4,5

;**************************
;Reset vector
; This code will start executing when a reset occurs.

RESET_VECTOR CODE 0x0000

goto Main ;go to start of main code

;**************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

HI_INT_VECTOR CODE 0x0008

bra HighInt ;go to high priority interrupt routine

;**************************
;Low priority interrupt vector
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

LOW_INT_VECTORCODE 0x0018

bra LowInt ;go to low priority interrupt routine

;**************************
;High priority interrupt routine
; The high priority interrupt code is placed here.

CODE

HighInt:

; * high priority interrupt code goes here *

retfie FAST

;**************************
;Low priority interrupt routine
; The low priority interrupt code is placed here.
; This code can be removed if low priority interrupts are not used.

LowInt:

movff STATUS,STATUS_TEMP ;save STATUS register


movff WREG,WREG_TEMP ;save working register movff BSR,BSR_TEMP ;save
BSR register

; * low priority interrupt code goes here *

movff BSR_TEMP,BSR ;restore BSR register


movff WREG_TEMP,WREG ;restore working register movff STATUS_TEMP,STATUS
;restore STATUS register
retfie

;**************************
;Start of main program
; The main program code is placed here. Main:
COUNT equ 25H
MOVLW d'10' ; WREG = 10 (decimal) for counter MOVWF COUNT ; load the counter

MOVLW d'0' ;WREG = 0


clrf TRISB
AGAIN ADDLW d'3' ; add 03 to WREG (WREG = sum)
DECFSZ COUNT,F ; decrement counter, skip if count = 0 GOTO AGAIN ; repeat until count
becomes 0
MOVWF PORTB ; send sum to PORTB SFR CounterA equ 24H
CounterB equ 25H
clrf TRISB; movlw d'1' movwf PORTB

;**************************
;End of program

END

Conclusion:

You might also like