Professional Documents
Culture Documents
Please read through all the suggested reading before you come to lab.
SOFTWARES REQUIRED:
▪ MPLAB IDE or MPLABX IDE
▪ Proteus
---------------------------------------------------------------------------------------------------------------------
Pin Description:
PORTS:
40 pins of PIC18F452 are divided into 5 ports. Out of which, 34 pins are Input-
Output pins which can be configured for general Input or Output by setting registers
associated with them. Please refer to the pin-out diagram above for a clear idea about
location of these pins on the microcontroller.
Each port in PIC18F452 is associated with three Special Function Registers for I/O
operations.
▪ TRISX (8 bit)
▪ LATx (8 bit)
▪ PORTx (8 bit)
Example 2.1:
Write a program to blink an LED attached to pin RB7
1. Simulate it on MPLab-IDE simulator and Proteus ISIS™
2. Implement the circuit on a bread-board and program the microcontroller using
a programmer device.
Fig.2.2 shows the bare minimum for implementing the circuit on the bread-board.
▪ The Oscillator is used to provide clock to run the controller.
▪ The push button and the resistor R1 form the reset circuit to reset the
microcontroller.
▪ LED is connected to pin RB7 via a current limiting resistor R2.
Following is the sample code written in assembly for blinking the LED.
#include<P18f452.INC>
CONFIG WDT=OFF ; disable watchdog timer
MYREG EQU 12H ; Assigning name to register
ORG 0H
MOVLW 0H
MOVWF TRISB ; TRISB=00H makes the portB output
BACK MOVLW 80H
MOVWF PORTB ; Send logic 1 to pin RB7
CALL DELAY ; Call delay loop
MOVLW 00H
MOVWF PORTB ; Send logic 0 to pin RB7
CALL DELAY ; Call delay loop
GOTO BACK ; Go back to label: BACK
;--------------------------
ORG 300H ; Location of delay loop in ROM
DELAY MOVLW 0XFF
MOVWF MYREG
AGAIN NOP
NOP
NOP
DECF MYREG, F ; Decrement value in MYREG by 1
BNZ AGAIN ; Branch if not zero: to label AGAIN
RETURN ; Return to main program
END
Simulate the code on MPLab SIM and implement the circuit on Proteus by
loading the resultant .hex file.
2. Double click on the microcontroller and load the hex file to the controller, and
set the clock frequency to 20MHz.
Connect the PIC18F452with the PicKit3 as shown in Figure 2.4. PicKit3 can
power the controller, so there is no actual need to power the controller externally.
Task 2.1:
Bonus Task:
Blink the LEDs in a sequence (from 1 to 8) in a loop