Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●

Slides:



Advertisements
Similar presentations
Microprocessors Typical microprocessor controlled devices: Camera, mobile phone, stereo, mp3 player, electronic toys… High-level microprocessor controlled.
Advertisements

The 8051 Microcontroller and Embedded Systems
Embedded System Spring, 2011 Lecture 9: I/O Programming Eng. Wazen M. Shbair.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Railway Foundation Electronic, Electrical and Processor Engineering.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 26: PIC microcontroller intro.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
Microcontroller Architecture— PIC18F Family
Railway Foundation Electronic, Electrical and Processor Engineering.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Stacks and Subroutines ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
A Simple Two-Pass Assembler
Dr. Rabie A. Ramadan Al-Azhar University Lecture 6
I/O PORTS (Simplest Peripherals) PORT A: 6 bits wide (7th and 8th bit always read as 0) PORT B: 8 bits wide PORT C: 8 bits wide PORT D: 8 bits wide.
Programming and Problem Solving ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Microprocessor and Interfacing PIC Code Execution
George Mason University ECE 448 – FPGA and ASIC Design with VHDL Experiment 7 VHDL Modeling of Embedded Microprocessors and Microcontrollers.
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
Lecture 15 Today’s lecture MARIE programming Assembler
Embedded System Spring, 2011 Lecture 5: The PIC Microcontrollers Eng. Wazen M. Shbair.
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ●
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
Department of Electronic & Electrical Engineering Seven segment display Subroutines.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Serial Peripheral Interface SPI I2C (i-squared cee)
Department of Electronic & Electrical Engineering Lecture 2. PIC16F84A Architecture / Instructions Memory. Program/Data (Harvard) File Registers (Data).
1 EKT 225 MICROCONTROLLER I CHAPTER ASSEMBLY LANGUAGE PROGRAMMING.
Department of Electronic & Electrical Engineering Lecture 4. ➢ Loops ➢ Delays ➢ Conditional instructions ➢ Simple clock example.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ read/write and clock inputs Sequence of control signal combinations.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
Writing an Assembly-language program MIPS assembly language using MARS: MIPS Assembler and Runtime Simulator CS-2710 Dr. Mark L. Hornick 1.
Fundamentals of Computer Engineering
Prof. Ahmad Abu-El-Haija
Microprocessor Systems Design I
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Microprocessor Systems Design I
PIC 16F877.
Microprocessor Systems Design I
Chapter 7 LC-2 Assembly Language.
Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/
Assembler CASE Tool.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Chapter 1 Number System RGGP, Narwana.
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Chapter 6 Programming the basic computer
Some Assembly (Part 2) set.html.
Dr. Clincy Professor of CS
Presentation transcript:

Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ● call and retlw instructions ● lookup table ● Driving a 7seg display

Department of Electronic & Electrical Engineering Background reading Quintessential PIC. Chapter 11 has lots of (too much?) detail that we skip in the lecture.

Department of Electronic & Electrical Engineering Template Program #include P16F84A.INC __config _XT_OSC & _WDT_OFF & _PWRTE_ON ORG h'0' ; PROGRAM IN HERE END Useful constants Sets some hardware configuration bits Program starts at address 0 Tell assembler about the end of your program In the notes we often miss out some of this stuff comment

Department of Electronic & Electrical Engineering Input and output TRISA TRISB PORTA PORTB REGISTER BANKS STATUS REGISTER and RP0

Department of Electronic & Electrical Engineering

Input and output (from PIC16F84A sheet) PORTA is a 5-bit wide, bi-directional port. The corresponding data direction register is TRISA. Setting a TRISA bit will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISA bit will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin)

Department of Electronic & Electrical Engineering PORTA and TRISA (addressing)

RPO Selects the bank 7 bits from opcode Don't worry about this yet! Address Register Memory Map

Department of Electronic & Electrical Engineering MOVWF instruction. 7 bits for register address opcode operand

Department of Electronic & Electrical Engineering Registers and banks. There are only 7 bits in an instruction for addressing the registers but we really need 8 bits ! Solution: One of the bits in the STATUS is used as a bank select.

Department of Electronic & Electrical Engineering

Selecting a data bank To select a data bank we must set/clear RP0 in the STATUS register. BCF STATUS,RP0 ; CLEAR RP0  selects BANK 0 BSF STATUS,RP0 ; SET RP0  selects BANK 1

Department of Electronic & Electrical Engineering

Configuring PORTA (from data sheet) (start of program not shown)

Department of Electronic & Electrical Engineering Literal means the data (operand) is contained in the instruction. There is no instruction to move a literal directly to a file register. We need to use MOVLW first then move W to the register.

Department of Electronic & Electrical Engineering Note: STATUS RP0 etc are symbolic constants defined in PIC16F84A.INC for example RP0 has the value 5 0x0F is a hexadecimal constant All the following are equivalent in MAPLABX (mpasm.exe) 0x0F ; hexadecimal H'F' ; hexadecimal B' ' ; binary D'15' ; decimal 15

Department of Electronic & Electrical Engineering Example: copying data from portA to portB bsf STATUS,5 ;select bank 1 movlw B' ' ;set up port B as all outputs movwf TRISB movlw B' ' ;set up port A 0-3 as inputs movwf TRISA bcf STATUS,5 ;select bank 0 loop movfw PORTA ; input PORTA movwf PORTB ; output to PORTB goto loop ; loop forever end

Department of Electronic & Electrical Engineering Labels and goto. In the previous example loop is an label (not an instruction) it is just a marker (the assembler knows the address of the next instruction. GOTO label is an instruction that makes the program execution goto the instruction that follows the label.

Department of Electronic & Electrical Engineering Seven Segment LED Display

Department of Electronic & Electrical Engineering Seven Segment Display Internal Circuit Common Anode

Department of Electronic & Electrical Engineering Circuit for 7seg display

Department of Electronic & Electrical Engineering Binary  seven segment display ● We have 4 bits of input (hex number). ● We want to display the corresponding character on the 7seg display. ● Each segment can be represented by a bit of a binary number. ● The problem is to lookup the correct 7seg code for each 4bit number. ● This can be done using a lookup table.

Department of Electronic & Electrical Engineering Lookup table using programmed return. ; setup stuff here..... ; w contains the 4 bit number movl 4,w call conversion ; w now contains the 7 segment code ;....more stuff here ; convert 4bit number in w into a seven segment code. conversion: ; this is just a label for the assembler addwf PCL ; add w to the PC (jump) retlw B' ' ; 0 return 7 seg code. retlw B' ' ; 1 retlw B' ' ; 2 retlw B' ' ; 3 retlw B' ' ; 4

Department of Electronic & Electrical Engineering Demo Do a demo now Dr Leonard.... If there is time?