You are on page 1of 6

Page 1 of 6

Department of Electrical Engineering

LAB WORK - 06
Microprocessor Based System
Spring/Fall/Summer 20__
Student Name SID Marks

Marks Distribution:
CLO_1
Tasks Total Marks
Marks Obtained
Timer Assembly Code. 3
Task Proteus simulation. 2
Home Assignment. 2
Hardware Working. 3
Total Marks 10

CLASS ID: __________________

DATE: ______________________

Signature of Faculty/Lab Engineer: ___________________________________________

Remarks: ________________________________________________________________
Microprocessor Based System Instructor:
College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 2 of 6

BASIC THEORY CLO_1


In this Lab session we would get familiarize with Hardware of Timer and its program. For this
Lab, we would use TIMER 0 and its Interrupt Subroutine.

Timer0 Module
The Timer0 module has the following features:
• Software selectable as an 8-bit or 16-bit timer/counter.
• Readable and writable.
• Dedicated 8-bit software programmable prescaler.
• Clock source selectable to be external or internal.
• Interrupt-on-overflow from FFh to 00h in 8-bit mode and FFFFh to 0000h in 16-bit
mode.
• Edge selection for external clock.

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 3 of 6

Setting up T0:

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 4 of 6

Enabling internal Timer0 overflow interrupt

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 5 of 6

OBJECTIVE #1
Make a program to toggle PORTB using the MAIN LOOP and toggle PORTC using the
Timer 0 Overflow Interrupt.

Example Code:
LIST P=PIC18F452, F=INHX32, N=0, ST=OFF, R=HEX ; INCLUDE CONTROLLER
TYPE
#include P18F452.INC ; INCLUDE CONTROLLER FILE
; FUSE BIT SETTINGS

CONFIG OSC = HS, OSCS = OFF ; HS=HIGH OSCILATOR


CONFIG WDT = OFF ; WATCH DOG TIMER OFF
CONFIG PWRT = ON, BOR = OFF ; POWER UP TIMER ON
; BROWN OUT RESET VOLTAGE
OFF
CONFIG DEBUG = OFF, LVP = OFF, STVR = OFF ; DEBUG OFF
; LOW VOLTAGEPROGRAMMING
OFF

ORG 0000H ; STARTING ADDRESS

GOTO INITIALIZE ; bypass interrupt vector table


;----------------------------------------------------------------------------------------------------------------------------
ORG 0008H ; interrupt vector
BTFSS INTCON, TMR0IF ; Timer0 interrupt scan
RETFIE ; No, return to initialize
GOTO ISR ; Yes, go to Timer0 ISR
;----------------------------------------------------------------------------------------------------------------------------
; ----------------------------------- Initialize Timer0 and keeping CPU busy---------------------------------------
ORG 00100H
INITIALIZE
CLRF TRISB ; Setting PORTB as output port
CLRF TRISC ; Setting PORTC as output port
MOVLW B’00001000’ ; Timer0, 16-bit
; No prescaler, internal; CLK
MOVWF T0CON ; load T0CON register
MOVLW 0xFF ; FFH to high byte
MOVWF TMR0H ; load Timer0 high byte
MOVLW 0x00 ; 00H to low byte
MOVWF TMR0L ; load Timer0 low byte
BCF INTCON, TMR0IF ; clear Timer interrupt flag bit
BSF T0CON, TMR0ON ; start Timer0TMR2_Prescale
BSF INTCON, TMR0IE ; enable Timer0 interrupt
BSF INTCON, GIE ; enable interrupt globally
;----------------------------------------------------------------------------------------------------------------------------

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk
Page 6 of 6

MAIN

MOVLW 0X00 ; move 0x00 to literal register


MOVWF PORTB ; load PORTB
CALL DELAY_1S ; delay of 1 sec
MOVLW 0XFF ; move 0xFF to literal register
MOVWF PORTB ; load PORTB
CALL DELAY_1S ; delay of 1 sec
GOTO MAIN ; go to main
;----------------------------------------------------------------------------------------------------------------------------
ISR ; Interrupt Service Routine
ORG 200H;
MOVLW 0xFF ; FFH to high byte
MOVWF TMR0H ; load Timer0 high byte
MOVLW 0x00 ; F2H to low byte
MOVWF TMR0L ; F2H to low byte

MOVLW 0X00 ; move 0x00 to literal register


MOVWF PORTC ; load PORTB
MOVLW 0XFF ; move 0xFF to literal register
MOVWF PORTC ; load PORTB
BCF INTCON, TMR0IF ; clear Timer0 interrupt flag bit
BSF T0CON, TMR0ON ; start Timer0TMR2_Prescale
RETFIE ; return from interrupt
;----------------------------------------------------------------------------------------------------------------------------
#INCLUDE <DELAY_20MHZ.asm> ; include delay file
END ; end program

Home Assignment: CLO_2


1- Find the timer's clock frequency and its period for various PIC18-based systems, with
the following crystal frequencies. Assume that no prescaler is used.
(a) 10 MHz (b) 16MHz (c) 4 MHz
2- Write a program that creates a square wave of 50% duty cycle (with equal portions high and
low) on the RB0. Timer0 is used to generate the time delay.
Submission Details:
• Lab manual
• Print of code in assembly language.
• Proteus simulation circuit bitmap image (print screen and sniping tool’s images are not
acceptable)
• Code simulate on trainer kit.

Microprocessor Based System Instructor:


College of Engineering Ashar Ali Qureshi
PAF-Karachi Institute of Economics & Technology asharali.qureshi@pafkiet.edu.pk

You might also like