PIC Discussion By Eng. Tamar Jomaa

Similar documents
Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

CENG-336 Introduction to Embedded Systems Development. Timers

ME 6405 Introduction to Mechatronics

Embedded System Design

PIC Discussion By Eng. Tamar Jomaa

EEE111A/B Microprocessors

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

These 3 registers contain enable, priority,

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features:

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

Learning Objectives:

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

Micro-Controller: PIC16C74 < Part 5: Interrupt >

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Laboratory 9. Programming a PIC Microcontroller - Part I

Lecture (04) PIC16F84A (3)

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

PIC 16F84A programming (II)

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

Microprocessors B (17.384) Spring Lecture Outline

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

Chapter 11: Interrupt On Change

EE 361L Digital Systems and Computer Design Laboratory

PIC16F84A. 18-pin Enhanced Flash/EEPROM 8-Bit Microcontroller. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet:

Assembly Language Instructions

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Using Timers of Microchip PIC18F Microcontrollers

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

ELCT 912: Advanced Embedded Systems

ECE 354 Introduction to Lab 2. February 23 rd, 2003

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

8051 Microcontroller Interrupts

Interrupts. Embedded Systems Interfacing. 08 September 2011

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

D:\PICstuff\PartCounter\PartCounter.asm

Performance & Applications

8051 Microcontroller

Introduction to Embedded Systems

DERTS Design Requirements (1): Microcontroller Architecture & Programming

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

PIC16F8X PIC16F8X. 18-pin Flash/EEPROM 8-Bit Microcontrollers

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver

The University of Texas at Arlington Lecture 21_Review

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Interrupts (II) Lecturer: Sri Parameswaran Notes by: Annie Guo

Microprocessors & Interfacing

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Embedded Systems and Software

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

CHAPTER 11 INTERRUPTS PROGRAMMING

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Week1. EEE305 Microcontroller Key Points

Embedded Systems Lab 2 - Introduction to interrupts

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Chapter 2 Sections 1 8 Dr. Iyad Jafar

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Lecture (03) PIC16F84 (2)

AGH University of Science and Technology Cracow Department of Electronics

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

Section 16. Basic Sychronous Serial Port (BSSP)

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

PIC Microcontroller Introduction

ME 515 Mechatronics. A microprocessor

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

Lecture-55 System Interface:

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Description of the Simulator

Micro II and Embedded Systems

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

PIC Discussion. By Eng. Tamar Jomaa

CPEG300 Embedded System Design. Lecture 6 Interrupt System

Lecture (04) PIC 16F84A programming I

Documentation Design File Formats

Timer1 Capture Mode:

Timers and Counters. LISHA/UFSC Prof. Dr. Antônio Augusto Fröhlich Fauze Valério Polpeta Lucas Francisco Wanner.

Section 28. WDT and SLEEP Mode

Introduction to PIC Programming

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Capture Mode of Pic18F252

Signature: 1. (10 points) Basic Microcontroller Concepts

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

AGH University of Science and Technology Cracow Department of Electronics

HT8 UL60730 Safety Library -- Program Counter Register Test

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

C Language Programming, Interrupts and Timer Hardware

PIC16F870/ /40-Pin, 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram. Microcontroller Core Features:

Transcription:

PIC Discussion By Eng. Tamar Jomaa 1

Write assembly language instructions to clear the general purpose registers of PIC16F84A microcontroller (don t write the whole program) 2

Islamic university Electrical engineering PIC course Chapter#2 Programming Microcontroller Using Assembly Language 3

Outlines for part#2: 2.4 Delay 2.5 Interrupts 2.6 TMR 4

2.4 Delay In this section we will learn how building delays. A delay is a mechanism that keeps the processor from executing a part of its program for a specific amount of time. Methods for creating these delays are: "NOP" Delay : A simple delay can be achieved by throwing in a few instructions that don't do anything useful except waste machine cycles. Basic Loop Delay: The next example show how to make delay for 41 cycles. 5

Example#1: 2.4 Delay 1 1 1x1 1x9+2 Will be evaluated one cycle Will be evaluated one cycle Take one cycle but it repeat 1 times Decrease from 9 to 1 take one cycle repeat 9 times. When decrease from 1 to a skip will be happen, so take 2 cycles. Take 2 cycles repeat 9 times Total delay = (1+1+1x1+1x9+2+2x9)cycle= 41 cycle Note: 1cycle=4Tosc=4x(1/Fosc)=4/(4MHz)=1µsec. so total delay=41µsec 6

2.4 Delay Example#2 :is a simple example consist of connecting a led to RB, then turning on/off this led in a flasher way: 7 Outer loop Inner loop 1 W PORTB 1 XORWF PORTB, F Delay 1 1 W PORTB XORWF PORTB, F

2.4 Delay 1 1 1x255 1x255 1x255 1x255x255 (1x254+2)x255 254x255x2 1x254+2 2x254 2 Note: ODH register will decrease from 255 to then it goes out from LOOP. Then the OCH register will decrease by 1 then the ODH register will full again in then begin decrease and so on The inner loop will repeat 255x255, but the outer loop will repeat only 255. 8

2.4 Delay Total delay =[1+1+1x255+1x255+1x255+1x255x255+(1 x254+2)x255+254x255x2+1x254x2+2x254 +2]x(4/(4MHz))=.26sec Important note: This method of delay is not sufficient especially at long delay so we learn another method by using TMR. 9

Example#3: 2.4 Delay Write a PIC subroutine in assembly language to give a fixed delay of 2us. Assume that a 4MHz oscillator is being used. 1 1 1X(K-1) 2 2X(K-1) 2 Total delay= 1+1+(K-1)+2+2X(K- 1)+2=3K+3 Cycles (3K+3)µsec=2µsec K=65 1

2.5 Interrupts Interrupts are a mechanism of a microcontroller which enables it to respond to some events at the moment they occur, regardless of what microcontroller is doing at the time. This is a very important part, because it provides connection between a microcontroller and environment which surrounds it. Generally, each interrupt changes the program flow, interrupts it and after executing an interrupt subprogram (interrupt routine) it continues from that same point on. 11

2.5 Interrupts Sources of interrupt: In the PIC16F84A, there are four sources of interrupt: Internal interrupt Termination of writing data to EEPROM. TMR interrupt caused by timer overflow. External interrupt Interrupt during alteration on RB4, RB5, RB6 and RB7 pins of port B. External interrupt from RB/INT pin of microcontroller. 12

2.5 Interrupts Registers used with interrupt: 1. Control interrupt register (INTCON) at Bh address. 2. Option register at 81h address. 3. Control EEPROM register (EECON 1) at 88h address. The most important register is (INTCON), so you can see the datasheet to know more about this register. 13

2.5 Interrupts flags 14

2.5 Interrupts 15

2.5 Interrupts 16

2.5 Interrupts The bellow Figure shows the most important interrupt register INTCON, which controls the usage and selection of interrupt sources in the PIC16F84A. 17

2.5 Interrupts We can use the bits of INTCON register to make interrupt as follow: 1) First we set GIE bit which must be enabled for any interrupt. 2) Second we enable one of this bits( TIE,EEIE, RBIE,INTE) as we like to use the interrupt: If we use external interrupt, we set INTE to 1. If we use TMR interrupt, we set TIE to 1. If we use RB interrupt, we set RBIE to 1. If we use EEPROM interrupt, we set EEIE 1. 3) When interrupt occurred, the one of flag bits (INTF, RBIF, TOIF) is set physically so it must be cleared in software. 18

2.5 Interrupts Keeping the contents of important registers: An important part of the interrupt process is the stack. Its basic role is to keep the value of program counter after a jump from the main program to an address of a subprogram. In order for a program to know how to go back to the point where it started from, it has to return the value of a program counter from a stack. When moving from a program to a subprogram, program counter is being pushed onto a stack. 19

2.5 Interrupts When executing instructions such as RETURN, RETLW or RETFIE which were executed at the end of a subprogram, program counter was taken from a stack so that program could continue from where it stopped before the interrupt. These operations of placing on and taking off from a program counter stack are called PUSH and POP. The step of push and pop is performed because the contents of the most important registers may change during the interrupt. The most important registers we must keep is the work register and status register and this is done by storing the work register in any bank and storing the status register in bank. 2

2.5 Interrupts After writing the main body of the interrupt and we can restore the status register then restore the W register. 21

2.5 Interrupts The following example shows how to use the external interrupt to turn on a led connected to RB2 when a pushbutton connected RB (External interrupt source) is pressed 22

2.5 Interrupts 23

2.5 Interrupts 24

problem#1: using external interrupt INT to implement a counter to counts from to 1111 at falling edge input. 25

problem#2: using external interrupt INT to implement a counter to counts from 1111 to at RISING edge input 26

2.6 TMR Timer is an internal 8bit register that increments automatically with every PIC instruction cycle until the count over flows timer capacity. This takes place when the timer count goes from xff to x. At that time,the timer restarts the count. The timer has the following characteristics: A timer register that is readable and writeable by software. Can be powered by an external or internal clock. Timing edge for external clock can be selected. 8-bit software programmable prescaler. Interrupt capability. Can be used as a timer or as a counter. 27

2.6 TMR Two register are used for control timer: 1) INTCON register: is used in timer mode to enable timer interrupt as showed in pervious section. 2) OPTION register: is used for control timer operation as select mode, postescaler for timer or WDT timer,select the value of prescaler and counter work in fall edge or high edge. 28

2.6 TMR Select mode:to choose timer work on timer mode or counter mode, we use bit5(tcs). If it is set,timer take external clock ( work as counter). Else it take internal clock & work as timer. Select edge: If trigger TMR was enabled with impulses from a RA4/TCKI pin, bit 4(TSE) would determine whether it would be on the rising or falling edge of a signal. 1= Falling edge = Rising edge Prescale: To select prescale for a WDT timer or for TMR we use bit3 (PSA): 1=prescaler is assigned to WDT. =prescaler is assigned to free timer TMR The counter prescaler consists of the three low-order bits in the OPTION register. These bits allow selecting eight possible values that serve as advisor for the counter rate.when the prescaler is disabled, the counter rate is one-fourth the processor s clock speed.if the prescaler is set to the maximum value (255) then one of 255 clock. Signals actually reach the timer. 29

2.6 TMR Table below shows the prescaler settings and their action on the rate of thetimer module and the Watchdog Timer: 3

Delay with TIMER: 2.6 TMR A general formula for calculating the number of timer beats per second is as follows : T =C/(4*P*R) Where T: is the number of clock beats per second C :is the system clock speed in Hz P: is value stored in the prescaler R: is the number of iterations counted in thetmr register. The range of both P and R in this formula is 1 to 256. Example how to make delay with timer: 31

Counter mode: 2.6 TMR The PIC16F84A can be programmed so hat portra4/tcki is used to count events or pulses by initializing the Timer module as a counter. Without interrupts, the process requires the following preparatory steps: Port-A, line4, (RA4/TCKI) is defined for input. The Timer register (TMR) is cleared. The OPTION register bits PSA and PS:PS2 are initialized if the prescaler is to be used. The OPTION register bit TSE is set so as to increment the count on the high-to-low transition of the port pin if the port source is active low.otherwise the bit is cleared. The OPTION register bit TCS is set to select action on the RA4/TCKI pin. 32

2.6 TMR The following example is using TMR as a counter to count from to 99 as shown in Figure: 33

34

2.6 TMR problem#1: using interrupt technique with tmr to implement 15 usec delay 35

Homework: Using interrupt technique with tmr to implement 15 msec delay Delivery date: next discussion lecture. 36

Be free to ask any question 37