Lecture (04) PIC16F84A (3)

Similar documents
PIC 16F84A programming (II)

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Assembly Language Instructions

Instuction set

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

EEE111A/B Microprocessors

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

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

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

SOLUTIONS!! DO NOT DISTRIBUTE!!

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

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

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Chapter 13. PIC Family Microcontroller

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

DERTS Design Requirements (1): Microcontroller Architecture & Programming

D:\PICstuff\PartCounter\PartCounter.asm

PIC Discussion. By Eng. Tamar Jomaa

16.317: Microprocessor-Based Systems I Summer 2012

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

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

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

Week1. EEE305 Microcontroller Key Points

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

ECE Test #1: Name

PIC16C63A/65B/73B/74B

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Micro II and Embedded Systems

16.317: Microprocessor-Based Systems I Spring 2012

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

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

Learning Objectives:

PIC16F84A 7.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Application Note - PIC Source Code v1.1.doc

Section 31. Instruction Set

Embedded System Design

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

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

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

Chapter 3: Further Microcontrollers

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

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.

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

Section 4. Architecture

PTK8756B 8 Bit Micro-controller Data Sheet

Fortune. Semiconductor Corporation 富晶半導體股份有限公司. 8-bit MCU with 1k program ROM, 64-byte RAM, 1 R2F module and 3 13 LCD driver. TD Rev. 1.

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

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

S w e d i s h c r. w e e b l y. c o m j a l i l a h m e l i v e. c o m Page 1

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

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

CONNECT TO THE PIC. A Simple Development Board

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

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

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

Arithmetic,logic Instruction and Programs

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

TM57PA20/ TM57PA40. 8 Bit Microcontroller. User Manual. Tenx reserves the right to change or discontinue this product without notice.

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

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver

ME 6405 Introduction to Mechatronics

ALU and Arithmetic Operations

ABOV SEMICONDUCTOR 8-BIT SINGLE-CHIP MICROCONTROLLERS MC71PD506. USER S MANUAL (Ver. 1.0)

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Performance & Applications

16.317: Microprocessor-Based Systems I Fall 2012

Semester 1. Module Code: EEE305J1. Module Title: MICROCONTROLLER SYSTEMS

PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

Introduction to PICL and PICLab

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Chapter 11: Interrupt On Change

4.5.1) The Label Field ) The Mnemonic Field. 4.5) Assembly Language Program Structure A PIC18 ALP consists of 3 type of statements:

16.317: Microprocessor Systems Design I Fall 2015

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

Flow Charts and Assembler Programs

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS 2008/9. Semester One

Appendix D: Source Codes. PDF created with pdffactory Pro trial version

The University of Texas at Arlington Lecture 5

PART TWO LISTING 8 PROGRAM TK3TUT8 MOVF PORTA,W ANDLW B ADDWF COUNT,F MOVF COUNT,W MOVWF PORTB GOTO LOOP

RISC8 Core Page 1. RISC8 Core. Version 1.0. Written by Tom Coonan

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

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

Lesson 4 Fun with W and F

President Alan VK6ZWZ Acting Sec. Don VK6HK Vice President Terry VK6ZLT Treasurer Ces VK6AO

Mod-5: PIC 18 Introduction 1. Module 5

Chapter 2 Sections 1 8 Dr. Iyad Jafar

16.317: Microprocessor Systems Design I Spring 2015

Model Answer Microcontrollers. MCQ Problems Total Q1 Q2

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

PIN DESCRIPTION Name I/O Description VDD P VSS P 5V Power from USB cable Ground RC6M O X1 I Test/OTP mode clock in Internal clock output (6MHz) VPP I

Controller Provides Display of Monitored Process Deviation

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Transcription:

Lecture (04) PIC16F84A (3) By: Dr. Ahmed ElShafee ١ Central Processing Unit Central processing unit (CPU) is the brain of a microcontroller responsible for finding and fetching the right instruction which needs to be executed, decoding that instruction, finally its execution. Arithmetic logic unit is responsible for performing operations of adding, subtracting, moving, and logic operations, and shifting ٢

In instructions with two operands, ordinarily one operand is in work register (W register), and the other is one of the registers (GPR, SFR ) or a constant. In instructions with one operand, is either W register or one of the registers. Execution of some instructions affects status bits, which depends on the result itself ALU can affect values of Carry (C), Digit Carry (DC), and Zero (Z) bits in STATUS register. ٣ Memory organization PIC16F84 has two separate memory blocks, one for data and the other for program Program memory 1024 locations with 14 bits width where locations zero and four are reserved for reset and interrupt vector. ٤

Data memory consists of EEPROM and RAM memories EEPROM memory consists of 64 eight bit locations RAM memory for data occupies space on a memory map from location 0x0C to 0x4F which comes to 68 locations. Locations of RAM memory are also called GPR registers which is an abbreviation for General Purpose Registers. ٥ GPR registers can be accessed regardless of which bank is selected at the moment. SFR registers first 12 locations in banks 0 and 1 are registers of specialized function assigned with certain blocks of the microcontroller. ٦

Working with Memory Banks Memory Banks Selecting one of the banks is done via RP0 bit in STATUS register. Example: bcf STATUS, RP0 Instruction BCF clears bit RP0 (RP0=0) in STATUS register and thus sets up bank 0. bsf STATUS, RP0 Instruction BSF sets the bit RP0 (RP0=1) in STATUS register ٧ and thus sets up bank1. Let's assume that we have selected bank 0 at the beginning of the program, and that we now want to write to certain register located in bank 1, say TRISB. Although we specified the name of the register TRISB, data will be actually stored to a bank 0 register at the appropriate address, which is PORTB in our example. Bcf STATUS, RP0 ;Select memory bank 0 Bsf STATUS, RP0 ;Select memory bank 1 ٨

Locations 0Ch 4Fh are general purpose registers (GPR) which are used as RAM memory. When locations 8Ch CFh in Bank 1 are accessed, we actually access the exact same locations in Bank 0. In other words, whenever you wish to access one of the GPR registers, there is no need to worry about which ٩ bank we are in! Program Counter Program counter (PC) is a 13 bit register that contains the address of the instruction being executed 5 bit register PCLATH for the five higher bits of the address, and the 8 bit register PCL for the lower 8 bits of the address. ١٠

STATUS Register bits 6:5 RP1:RP0 (Register Bank Select bits) 01 = first bank 00 = zero bank bit 4 TO Time out ; Watchdog overflow. 1 = overflow did not occur 0 = overflow did occur ١١ bit 3 PD (Power down bit) 1 = after supply has been turned on 0 = executing SLEEP instruction bit 2 Z (Zero bit) Indication of a zero result This bit is set when the result of an executed arithmetic bit 1 DC (Digit Carry) DC Transfer Bit affected by operations of addition, subtraction. 1 = transfer occurred on the fourth bit according to the order of the result 0 = transfer did not occur ١٢

bit 0 C (Carry) Transfer Bit that is affected by operations of addition, subtraction and shifting. 1 = transfer occurred from the highest resulting bit 0 = transfer did not occur ١٣ TRISB, PORTB, TRISA, and PORTA To change function of port to the following directions O O I O O O I I You need to write the following literal to TRIS register =0x23 0 0 1 0 0 0 1 1 ١٤

Assembly programming Compiler directives (MPLAP.X) Variables Values assignment Arithmetic operations Logic operations Loops Conditioning Branches Other instructions ١٥ Compiler directives LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_ON & _WDT_OFF & _CP_OFF ١٦

Variables As mentioned before PIC16F84 has three types of registers (memory) 1. W working register 2. SFR: Bank 00: 00h 0bh Bank 01: 80h 8bh ١٧ 2.1 Programmer can access SFR directly using its address (after selecting targeted bank) 0x00, 0x01,.., 0x0b 0x80, 0x81,, 0x8b 2.2 Programmer can assign name for SFR address INDF equ 0x00 PCL equ 0x02 STATUS equ 0x03 FSR equ 0x04 PCLATH equ 0x0A ١٨

Programmer can refer to Bits within registers Z equ 0x02 C equ 0x00 IRP equ 0x07 2.3 Programmer include processor.inc file include "p16f84.inc File path C:\Program Files (x86)\microchip\mplabx\mpasmx ١٩ W EQU H'0000' F EQU H'0001' ;-----Bank0------------------ INDF EQU H'0000' TMR0 EQU H'0001' PCL EQU H'0002' STATUS EQU H'0003' FSR EQU H'0004' PORTA EQU H'0005' PORTB EQU H'0006' EEDATA EQU H'0008' EEADR EQU H'0009' PCLATH EQU H'000A' INTCON EQU H'000B ;-----Bank1------------------ OPTION_REG EQU H'0081' TRISA EQU H'0085' TRISB EQU H'0086' EECON1 EQU H'0088' EECON2 EQU H'0089 ٢٠ ;----- STATUS Bits --------------------------- C EQU H'0000' DC EQU H'0001' Z EQU H'0002' NOT_PD EQU H'0003' NOT_TO EQU H'0004' IRP EQU H'0007' RP0 EQU H'0005' RP1 EQU H'0006' ;----- PORTA Bits --------------------------- RA0 EQU H'0000' RA1 EQU H'0001' RA2 EQU H'0002' RA3 EQU H'0003' RA4 EQU H'0004' ;----- PORTB Bits ----------------------- RB0 EQU H'0000' RB1 EQU H'0001' RB2 EQU H'0002' RB3 EQU H'0003' RB4 EQU H'0004' RB5 EQU H'0005' RB6 EQU H'0006' RB7 EQU H'0007'

;----- OPTION_REG Bits ------------------------ PSA EQU H'0003' T0SE EQU H'0004' T0CS EQU H'0005' INTEDG EQU H'0006' NOT_RBPU EQU H'0007' PS0 EQU H'0000' PS1 EQU H'0001' PS2 EQU H'0002' ;----- TRISA Bits ---------------------------------- TRISA0 EQU H'0000' TRISA1 EQU H'0001' TRISA2 EQU H'0002' TRISA3 EQU H'0003' TRISA4 EQU H'0004' ;----- TRISB Bits ----------------------------------- TRISB0 EQU H'0000' TRISB1 EQU H'0001' TRISB2 EQU H'0002' TRISB3 EQU H'0003' TRISB4 EQU H'0004' TRISB5 EQU H'0005' TRISB6 EQU H'0006' TRISB7 EQU H'0007' ٢١ 3. GPR Bank 00: 0ch 4fh Bank 01: 8ch cfh 3.1 Programmer can access GFR directly using its address (after selecting targeted bank) 3.2 Programmer can assign name for GPR address ٢٢ num1 equ 0x0c num2 equ 0x0d n equ 0x0e x equ 0x0f temperature equ 0x1A

Values assignment 1 MOVLW k Write constant in W register 2 MOVWF f Copy W to f 3 MOVF f,d Copy f to d (d=0 des w, d=1; des f itdelf) 4 CLRW Write 0 in W 5 CLRF f Write 0 in f 6 BCF f,b Reset bit b in f 7 BSF f,b Set bit b in f MOVLW H'00' BSF STATUS,RP0 MOVWF TRISB BCF STATUS,RP0 MOVF 0X0C,W ٢٣ Arithmetic operations 8 ADDLW k Add W to a constant 9 SUBLW k Subtract W from a constant 10 ADDWF f,d Add W to f 11 SUBWF f,d Subtract W from f 12 INCF f,d Increment f 13 DECF f,d Decrement f ٢٤ Addlw H 12 Sublw D 12 Addwf b 11110000,f addwf b 11110000,1 Subwf b 00001111,w subwf b 00001111,0 Incf PORTB,f Decf PORTB,f

Logic operations 14 ANDLW k Logic AND W with constant 15 IORLW k Logic OR W with constant 16 XORLW k Logic exclusive OR W with constant 17 ANDWF f,d Logic AND W with f 18 IORWF f,d Logic OR W with f 19 XORWF f,d Logic exclusive OR W with f 20 RLF f,d Rotate f to the left through CARRY 21 RRF f,d Rotate f to the right through CARRY 22COMF f,d Complement f 23SWAPF f,d Copy the nibbles from f to d crosswise ٢٥ Loops 24 INCFSZ f Increment f, skip if f =0 25 DECFSZ f Decrement f, skip if f = 0 MOVLW D'04' MOVWF 0x0c loop......... decfsz 0x0c goto loop ٢٦

Conditioning 26 BTFSC f,b Test bit b in f, skip next instruction if b = 0 27 BTFSS f,b Test bit b in f, skip next instruction b =1 check btfsc PORTA,RA0 goto press_active_low goto check press_active_low...... ٢٧ Branching 28 GOTO address Jump to address 29 CALL address Call a program 30 RETURN Return from a subprogram 31 RETLW Return from a subprogram with constant in W MOVLW h ff' MOVWF 0x0c loop call delay decfsz 0x0c goto loop ٢٨ delay nop nop nop return

Other instructions 32 NOP No operation 33 RETFIE Return from interrupt routine 34 CLRWDT Initialize watchdog timer 35 SLEEP Stand by mode ٢٩ Creating project ٣٠

٣١ ٣٢

٣٣ ٣٤

٣٥ ٣٦

٣٧ ٣٨

٣٩ Working with simulator ٤٠

٤١ ٤٢

٤٣ ٤٤

٤٥ ٤٦

٤٧ ٤٨

٤٩ Build delays DELAY MOVLW d'255' MOVWF 0x4f MOVWF 0x4E DELAY_loop2 DELAY_loop1 DECFSZ 0x4f goto DELAY_loop1 DECFSZ 0x4e goto DELAY_loop2 RETURN ٥٠

LedFlasher.asm LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_ON & _WDT_OFF & _CP_OFF ORG 0 GOTO start ORG 4 GOTO start start MOVLW H'00' BSF STATUS,RP0 MOVWF TRISB BCF STATUS,RP0 LOOP MOVLW B'00000000' MOVWF PORTB CALL DELAY MOVLW B'11111111' MOVWF PORTB CALL DELAY GOTO LOOP ٥١ PressControlledLedFlasher.asm LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_OFF & _WDT_OFF & _CP_OFF ORG 0 GOTO start ORG 4 GOTO start start BSF STATUS,RP0 MOVLW H'00' MOVWF TRISB MOVLW H'01' MOVWF TRISA BCF STATUS,RP0 LOOP MOVLW B'00000000' MOVWF PORTB CALL DELAY BTFSs PORTA,RA0 GOTO LOOP MOVLW B'11111111' MOVWF PORTB CALL DELAY GOTO LOOP ٥٢

PressControlledLedToggle.asm LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_FF & _WDT_OFF & _CP_OFF ORG 0 GOTO start ORG 4 GOTO start start BSF STATUS,RP0 MOVLW H'00' MOVWF TRISB MOVLW H'01' MOVWF TRISA BCF STATUS,RP0 MOVLW h'00' MOVWF 0X0C MOVLW B'00000000' ٥٣ MOVWF PORTB LOOP CALL DELAY BTFSS PORTA,RA0 GOTO LOOP COMF 0X0C,F MOVF 0X0C,W MOVWF PORTB GOTO LOOP LedChaser.asm LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_FF & _WDT_OFF & _CP_OFF ORG 0 GOTO start ORG 4 GOTO start start MOVLW H'00' BSF STATUS,RP0 MOVWF TRISB BCF STATUS,RP0 CALL DELAY MOVLW B'0000010' MOVWF PORTB CALL DELAY MOVLW B'0000100' MOVWF PORTB CALL DELAY MOVLW B'0001000' MOVWF PORTB GOTO LOOP LOOP CALL DELAY MOVLW B'00000001' MOVWF PORTB ٥٤

Reversible Chaser LIST P=16f84a include "p16f84a.inc" config _FOSC_XT & _PWRTE_OFF & _WDT_OFF & _CP_OFF ORG 0 goto start ORG 4 goto start start BSF STATUS,RP0 MOVLW 0X00 MOVWF TRISB MOVLW 0XFF MOVWF TRISA MOVLW 0X01 BCF STATUS,RP0 MOVWF PORTB ٥٥ LOOP1 MOVLW 0X07 MOVWF 0X0C LEFT RLF PORTB,W MOVWF PORTB call DELAY DECFSZ 0x0C,f GOTO LEFT MOVLW 0X07 MOVWF 0X0C RIGHT RRF PORTB,W MOVWF PORTB call DELAY DECFSZ 0x0C,f GOTO RIGHT GOTO LOOP1 DELAY MOVLW d'255' MOVWF 0x4f MOVWF 0x4E DELAY_loop2 DELAY_loop1 DECFSZ 0x4f goto DELAY_loop1 DECFSZ 0x4e goto DELAY_loop2 RETURN end ٥٦

Thanks,.. See you next week (ISA), ٥٧