EECE.3170 Microprocessor Systems Design I

Slides:



Advertisements
Similar presentations
Instruction formats for the PIC series. ROM encoding Instructions are encoded in binary in ROM. The instructions are fixed format, each occupying 14 bits.
Advertisements

Control structures Hot to translate high level control structures to assembler.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
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.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 29: Microcontroller intro.
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Two’s Complement Number wheel for 4 bit numbers
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
EEE237 Introduction to Microprocessors Week x. SFRs.
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.
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Chapter 5 Building Assembler Programs The aims of this chapter are to introduce: how to visualise a program, and represent it diagrammatically; how to.
Department of Electronic & Electrical Engineering Lecture 4. ➢ Loops ➢ Delays ➢ Conditional instructions ➢ Simple clock example.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
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.
Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes.
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Lecture – 5 Assembly Language Programming
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
Counters & Time Delays.
Microprocessor Systems Design I
Interrupts, Counter and Timers
Microprocessor Systems Design I
16.317: Microprocessor System Design I
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.2160 ECE Application Programming
Md. Atiqur Rahman Ahad PIC18… Ch. 3.1 Md. Atiqur Rahman Ahad
EECE.2160 ECE Application Programming
EECE.3170 Microprocessor Systems Design I
Presentation transcript:

EECE.3170 Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2016 Lecture 27: PIC assembly programming (continued)

Microprocessors I: Lecture 27 Lecture outline Announcements/reminders HW 7 posted; due 11/28 Visit my office (Perry 118A) to check out a PICkit for HW 8 Contact me if you don’t have a group Today’s lecture: sample programming sequences Delay loop State machine 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 4/24/2019 A Delay Subroutine ; *********************************************************************************** ; TenMs subroutine and its call inserts a delay of exactly ten milliseconds ; into the execution of code. ; It assumes a 4 MHz crystal clock. One instruction cycle = 4 * Tosc. ; TenMsH equ 13 ; Initial value of TenMs Subroutine's counter ; TenMsL equ 250 ; COUNTH and COUNTL are two variables TenMs nop ; one cycle movlw TenMsH ; Initialize COUNT movwf COUNTH movlw TenMsL movwf COUNTL Ten_1 decfsz COUNTL,F ; Inner loop goto Ten_1 decfsz COUNTH,F ; Outer loop goto Ten_1 return 4/24/2019 Microprocessors I: Lecture 27 Chapter 9

Delay subroutine questions What factors determine amount of delay? Clock period (1/frequency) Clock cycles per instruction Number of instructions in loop Initial values of counter (COUNTL/COUNTH) TenMsH/TenMsL: constants used to initialize counter What’s downside of using loop for delay? Processor does nothing but wait Under what conditions does this function decrement the upper byte (COUNTH)? When COUNTL == 0 First decfsz skips goto Second decfsz changes COUNTH 4/24/2019 Microprocessors I: Lecture 27

Delay subroutine questions (cont.) Under what conditions does function return? COUNTL == COUNTH == 0 How many times does each instruction execute? Everything before Ten_1 label: 1 time First decfsz/goto pair: depends on loop iteration First iteration: decfsz  250 times, goto  249 times goto skipped in last iteration All others: decfsz  256 times, goto  255 times Start by decrementing 0x00  0xFF (255) Second decfsz/goto pair: decfsz 13 times, goto 12 times return instruction: 1 time 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 Blinking LED example Assume three LEDs (Green, Yellow, Red) are attached to Port D bit 0, 1 and 2. Write a program for the PIC16F874 that toggles the three LEDs every half second in sequence: green, yellow, red, green, …. For this example, assume that the system clock is 4MHz. 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 Top Level Flowchart Initialize: Initialize port D, initialize the counter for 500ms. Blink: Toggle the LED in sequence, green, yellow, red, green, …. Which LED to be toggled is determined by the previous state. Wait for 500ms: Keep the LED on for 500ms and then toggle the next one. 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 Strategy to “Blink” The LEDs are toggled in sequence - green, yellow, red, green, yellow, red… Let’s look at the lower three bits of PORTD 001=green, 010=yellow, 100=red The next LED to be toggled is determined by the current LED. 001->010->100->001->… 4/24/2019 Microprocessors I: Lecture 27

Inefficient “Blink” Subroutine btfsc PORTD, 0 ; is it Green? goto toggle1 ; yes, goto toggle1 btfsc PORTD, 1 ; else is it Yellow? goto toggle2 ; yes, goto toggle2 ;toggle0 bcf PORTD, 2 ; otherwise, must be red, change to green bsf PORTD, 0 ; 100->001 return toggle1 bcf PORTD, 0 ; change from green to yellow bsf PORTD, 1 ; 001->010 toggle2 bcf PORTD, 1 ; change from yellow to red bsf PORTD, 2 ; 010->100 4/24/2019 Microprocessors I: Lecture 27

Inefficient “Blink” Subroutine Questions Under what conditions will this function jump to “toggle1”? Lowest bit of PORTD = 1 (001, 011, 111) Under what conditions will this function jump to “toggle2”? Lowest bit of PORTD = 0; second bit = 1 (010, 110) If function gets into error state, how does it take to recover to valid state (only 1 bit == 1)? Depends on error state—1 or 2 function calls Is there another way to toggle bits when changing state? What logical operation lets you toggle bits? XOR (1s in positions to change; 0s elsewhere) 4/24/2019 Microprocessors I: Lecture 27

Another way to code “Blink” ---- Table Use movf PORTD, W ; Copy present state of LEDs into W andlw B'00000111' ; and keep only LED bits addwf PCL,F ; Change PC with PCLATH and offset in W retlw B'00000001' ; (000 -> 001) reinitialize to green retlw B'00000011' ; (001 -> 010) green to yellow retlw B'00000110' ; (010 -> 100) yellow to red retlw B'00000010' ; (011 -> 001) reinitialize to green retlw B'00000101' ; (100 -> 001) red to green retlw B'00000100' ; (101 -> 001) reinitialize to green retlw B'00000111' ; (110 -> 001) reinitialize to green retlw B'00000110' ; (111 -> 001) reinitialize to green In calling program call BlinkTable ; get bits to change into W xorwf PORTD, F ; toggle them into PORTD 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 Table Use Questions What do the first two instructions do? Isolate lowest 3 bits of PORTD Ensure value in W is between 0-7 What does the addwf instruction do? Adding to PCL  effectively goto instruction Value in W = offset from addwf instruction If W = 0, add 0 to PCL  “jumps” to next instruction If W = 1, add 1 to PCL  “jumps” 1 extra instruction … If W = 7, add 7 to PCL  “jumps” 7 extra instructions Why do we need 8 retlw instructions? 8 possible values for lowest bits of PORTD 8 possible states—3 valid ones (001, 010, 100) and 5 error states 4/24/2019 Microprocessors I: Lecture 27

Table Use Questions (continued) How is each return value used? Bit mask used in xorwf instruction Accomplishes appropriate state transition Valid states go through desired pattern 001 XOR 011 = 010 010 XOR 110 = 100 100 XOR 101 = 001 All error states transition back to 001 Why are upper 5 bits of return values = 0? May have other devices hooked up to port—don’t want to change state of those devices 0 XOR 0 = 0; 1 XOR 0 = 1  XOR with 0 doesn’t change bit 4/24/2019 Microprocessors I: Lecture 27

Microprocessors I: Lecture 27 Final notes Next time: PICkit intro Reminders HW 7 posted; due 11/28 Visit my office (Perry 118A) to check out a PICkit for HW 8 Contact me if you don’t have a group 4/24/2019 Microprocessors I: Lecture 27