EECE.3170: Microprocessor Systems Design I Spring 2016

Similar documents
EECE.3170: Microprocessor Systems Design I Summer 2017

Chapter 11: Interrupt On Change

Figure 1: Pushbutton without Pull-up.

Laboratory Exercise 5 - Analog to Digital Conversion

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

Embedded Systems Programming and Architectures

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

The University of Texas at Arlington Lecture 5

Lecture (04) PIC16F84A (3)

Flow Charts and Assembler Programs

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

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

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

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

PIC 16F84A programming (II)

ECE Test #1: Name

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

Application Note - PIC Source Code v1.1.doc

16.317: Microprocessor-Based Systems I Spring 2012

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Assembly Language Instructions

Introduction to PIC Programming

D:\PICstuff\PartCounter\PartCounter.asm

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

Introduction to PIC Programming

Binary Outputs and Timing

C:\IDE\Brooke-16F88-LED\Brooke-16F88_LED.asm

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

16.317: Microprocessor Systems Design I Fall Exam 3 December 15, Name: ID #:

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Introduction to PIC Programming

ECE Homework #3

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

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

Introduction to PIC Programming

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

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

LCD. Configuration and Programming

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

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

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

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

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

Arithmetic,logic Instruction and Programs

SOLUTIONS!! DO NOT DISTRIBUTE!!

Week1. EEE305 Microcontroller Key Points

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

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

16.317: Microprocessor-Based Systems I Summer 2012

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Microchip 18F4550 Interface, Signal conditioning, USB, USB- RS-232, 16x2 LCD Interface

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

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

Experiment 7:The USART

Chapter 3: Further Microcontrollers

Embedded System Design

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

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

THE UNIVERSITY OF THE WEST INDIES

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)

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Micro II and Embedded 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.

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Introduction to PIC Programming

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

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

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

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

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

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

Performance & Applications

EEE111A/B Microprocessors

MPLAB -ICD USER S GUIDE

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Instuction set

Relay. bit4 bit5 bit6 bit7

Laboratory: Introduction to Mechatronics

Application Note MLX90614 SMBus implementation in PIC MCU

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

ME 6405 Introduction to Mechatronics

Physics 335 Intro to MicroControllers and the PIC Microcontroller

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

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

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

Experiment 9: Using HI-TECH C Compiler in MPLAB

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

MICROPROCESSORS A (17.383) Fall Lecture Outline

Team 8: Robert Blake Craig Goliber Alanna Ocampo

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

CONNECT TO THE PIC. A Simple Development Board

Discrete Logic Replacement A Keypad Controller for Bi-directional Key Matrix

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

16.317: Microprocessor Systems Design I Fall 2015

DISCONTINUED. SPI Communication with AMT bit Absolute Encoder

Transcription:

EECE.3170: Microprocessor Systems Design I Spring 2016 Lecture 31: Key Questions April 20, 2016 1. (Review) Explain how interrupts can be set up and managed in the PIC microcontrollers. 1

EECE.3170: Microprocessor Systems Design I Spring 2016 M. Geiger Lecture 31: Key Questions 2. (Review) Explain the operation of the programs used to rotate the LEDs using interrupts (interrupt.asm and interrupt.c). 2

EECE.3170: Microprocessor Systems Design I Spring 2016 M. Geiger Lecture 31: Key Questions 3. Explain how the analog to digital converter module is configured in PIC microcontrollers. 3

EECE.3170: Microprocessor Systems Design I Spring 2016 M. Geiger Lecture 31: Key Questions 4. Explain the operation of the programs used to test the ADC (a2d.asm and a2d.c). 5. Explain the programs that use the ADC result to vary the speed of rotation (vs_rotate.asm and vs_rotate.c). 4

C:\Users\Michael_Geiger\Documents\courses\16...\PICkit3_Starter_Kit\src\pic16\assy\04 A2D\a2d.asm Lesson 4 "Analog to Digital" This shows how to read the A2D converter and display the High order parts on the 4 bit LED display. The pot on the Low Pin Count Demo board varies the voltage coming in on in A0. The A2D is referenced to the same Vdd as the device, which is nominally is 5V. The A2D returns the ratio of the voltage on Pin RA0 to 5V. The A2D has a resolution of 10 bits, with 1024 representing 5V and 0 representing 0V. The top four MSbs of the ADC are mirrored onto the LEDs. Rotate the potentiometer to change the display. PIC: 16F1829 Assembler: MPASM v5.43 IDE: MPLABX v1.10 Board: PICkit 3 Low Pin Count Demo Board Date: 6.1.2012 See Low Pin Count Demo Board User's Guide for Lesson Information 1 #include <p16f1829.inc> CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF) CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF) errorlevel 302 supress the 'not in bank0' warning LATC Bit#: 7 6 5 4 3 2 1 0 LED: DS4 DS3 DS2 DS1 ORG 0 start of code at address 0x0000 Start: Setup main init banksel OSCCON bank1 movlw b'00111000' set cpu clock speed movwf OSCCON move contents of the working register into OSCCON Configure the ADC/Potentimator already in bank1 bsf TRISA, 4 Potentimator is connected to RA4...set as input movlw b'00001101' select RA4 as source of ADC and enable the module (carefull, this is actually AN3) movwf ADCON0 movlw b'00010000' left justified Fosc/8 speed vref is Vdd movwf ADCON1 banksel ANSELA bank3 bsf ANSELA, 4 analog for ADC Configure the LEDs banksel TRISC bank1 clrf TRISC make all of PORTC an output banksel LATC select the bank where LATC is movlw b'00001000' start the rotation by setting DS1 ON movwf LATC write contents of the working register to the latch

C:\Users\Michael_Geiger\Documents\courses\16...\PICkit3_Starter_Kit\src\pic16\assy\04 A2D\a2d.asm MainLoop: Start the ADC nop requried ADC delay of 8uS => (1/(Fosc/4)) = (1/(500KHz/4)) = 8uS banksel ADCON0 bsf ADCON0, GO start the ADC btfsc ADCON0, GO this bit will be cleared when the conversion is complete goto $ 1 keep checking the above line until GO bit is clear 2 Grab Results and write to the LEDs swapf ADRESH, w Get the top 4 MSbs (remember that the ADC result is LEFT justified!) banksel LATC movwf LATC move into the LEDs bra MainLoop end end code

C:\Users\Michael_Geiger\Documents\courses\16...\docs\PICkit3_Starter_Kit\src\pic16\c\04 A2D\a2d.c / Lesson 4 "Analog to Digital" This shows how to read the A2D converter and display the High order parts on the 4 bit LED display. The pot on the Low Pin Count Demo board varies the voltage coming in on in A0. The A2D is referenced to the same Vdd as the device, which is nominally is 5V. The A2D returns the ratio of the voltage on Pin RA0 to 5V. The A2D has a resolution of 10 bits, with 1023 representing 5V and 0 representing 0V. The top four MSbs of the ADC are mirrored onto the LEDs. Rotate the potentiometer to change the display. PIC: 16F1829 Compiler: XC8 v1.00 IDE: MPLABX v1.10 Board: PICkit 3 Low Pin Count Demo Board Date: 6.1.2012 See Low Pin Count Demo Board User's Guide for Lesson Information / 1 #include <htc.h> #define _XTAL_FREQ 500000 //PIC hardware mapping //Used by the XC8 delay_ms(x) macro //config bits that are part specific for the PIC16F1829 CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF) CONFIG(WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF) / LATC Bit#: 7 6 5 4 3 2 1 0 LED: DS4 DS3 DS2 DS1 / void main(void) { OSCCON = 0b00111000 TRISC = 0 TRISAbits.TRISA4 = 1 ANSELAbits.ANSA4 = 1 ADCON0 = 0b00001101 (AN3) ADCON1 = 0b00010000 while (1) { delay_us(5) GO = 1 while (GO) continue LATC = (ADRESH >> 4) } //500KHz clock speed //all LED pins are outputs //setup ADC //Potentiamtor is connected to RA4...set as input //analog //select RA4 as source of ADC and enable the module //left justified FOSC/8 speed Vref is Vdd //wait for ADC charging cap to settle //wait for conversion to be finished //grab the top 4 MSbs }

C:\Users\Michael_Geiger\Documents\courses\16...\src\pic16\assy\05 VS Rotate\vs_rotate.asm Lesson 5 "Variable Speed Rotate" This lesson combines all of the previous lessons to produce a variable speed rotating LED display that is proportional to the ADC value. The ADC value and LED rotate speed are inversely proportional to each other. Rotate the POT counterclockwise to see the LEDs shift faster. PIC: 16F1829 Assembler: MPASM v5.43 IDE: MPLABX v1.10 Board: PICkit 3 Low Pin Count Demo Board Date: 6.1.2012 See Low Pin Count Demo Board User's Guide for Lesson Information 1 #include <p16f1829.inc> CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF) CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF) errorlevel 302 cblock 0x70 Delay1 Delay2 endc supress the 'not in bank0' warning shared memory location that is accessible from all banks Define two file registers for the delay loop in shared memory LATC Bit#: 7 6 5 4 3 2 1 0 LED: DS4 DS3 DS2 DS1 ORG 0 start of code Start: Setup main init banksel OSCCON bank1 movlw b'00111000' set cpu clock speed movwf OSCCON move contents of the working register into OSCCON Configure the ADC/Potentimator already in bank1 bsf TRISA, 4 Potentimator is connected to RA4...set as input movlw b'00001101' select RA4 as source of ADC and enable the module (carefull, this is actually AN3) movwf ADCON0 movlw b'00010000' left justified Fosc/8 speed vref is Vdd movwf ADCON1 banksel ANSELA bank3 bsf ANSELA, 4 analog for ADC Configure the LEDs banksel TRISC bank1 clrf TRISC make all of PORTC an output banksel LATC bank2 movlw b'00001000' start the rotation by setting DS4 ON movwf LATC write contents of the working register to the latch MainLoop: call A2d get the ADC result top 8 MSbs are now in the working register (Wreg) movwf Delay2 move ADC result into the outer delay loop

C:\Users\Michael_Geiger\Documents\courses\16...\src\pic16\assy\05 VS Rotate\vs_rotate.asm call CheckIfZero if ADC result is zero, load in a value of '1' or else the delay loop will decrement starting at 255 call DelayLoop delay the next LED from turning ON call Rotate rotate the LEDs 2 bra MainLoop do this forever CheckIfZero: movlw d'0' load wreg with '0' xorwf Delay2, w XOR wreg with the ADC result and save in wreg btfss STATUS, Z if the ADC result is NOT '0', then simply return to MainLoop return return to MainLoop movlw d'1' ADC result IS '0'. Load delay routine with a '1' to avoid decrementing a rollover value of 255 movwf Delay2 move it into the delay location in shared memory (RAM) return return to MainLoop A2d: Start the ADC nop requried ADC delay of 8uS => (1/(Fosc/4)) = (1/(500KHz/4)) = 8uS banksel ADCON0 bsf ADCON0, GO start the ADC btfsc ADCON0, GO this bit will be cleared when the conversion is complete goto $ 1 keep checking the above line until GO bit is clear movf ADRESH, w Get the top 8 MSbs (remember that the ADC result is LEFT justified!) return DelayLoop: Delay amount is determined by the value of the ADC decfsz Delay1,f will always be decrementing 255 here goto DelayLoop The Inner loop takes 3 instructions per loop 255 loops (required delay) decfsz Delay2,f The outer loop takes and additional 3 instructions per lap X loops (X = top 8 MSbs from ADC conversion) goto DelayLoop return Rotate: banksel LATC change to Bank2 lsrf LATC logical shift right btfsc STATUS,C did the bit rotate into the carry? bsf LATC,3 yes, put it into bit 3. return end end code

C:\Users\Michael_Geiger\Documents\courses\16...\src\pic16\c\05 VS Rotate\vs_rotate.c / Lesson 5 "Variable Speed Rotate" This lesson combines all of the previous lessons to produce a variable speed rotating LED display that is proportional to the ADC value. The ADC value and LED rotate speed are inversely proportional to each other. Rotate the POT counterclockwise to see the LEDs shift faster. PIC: 16F1829 Compiler: XC8 v1.00 IDE: MPLABX v1.10 Board: PICkit 3 Low Pin Count Demo Board Date: 6.1.2012 See Low Pin Count Demo Board User's Guide for Lesson Information / 1 #include <htc.h> #define _XTAL_FREQ 500000 //PIC hardware mapping //Used by the XC8 delay_ms(x) macro //config bits that are part specific for the PIC16F1829 CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF) CONFIG(WRT_OFF & PLLEN_OFF & STVREN_OFF & LVP_OFF) / LATC Bit#: 7 6 5 4 3 2 1 0 LED: DS4 DS3 DS2 DS1 / unsigned char adc(void) //prototype void main(void) { unsigned char delay OSCCON = 0b00111000 TRISC = 0 LATC = 0 LATCbits.LATC3 = 1 TRISAbits.TRISA4 = 1 ANSELAbits.ANSA4 = 1 ADCON0 = 0b00001101 (AN3) ADCON1 = 0b00010000 while (1) { delay = adc() delay_ms(5) while (delay!= 0) delay_ms(2) each LATC >> = 1 if(statusbits.c) LATCbits.LATC3 = 1 } //500KHz clock speed //all LED pins are outputs //start sequence with DS4 lit //setup ADC //Potentiamtor is connected to RA4...set as input //analog //select RA4 as source of ADC and enable the module //left justified FOSC/8 speed Vref is Vdd //grab the top 8 MSbs //delay for AT LEAST 5ms //decrement the 8 MSbs of the ADC and dealy 2ms for //shift to the right by 1 to light up the next LED //when the last LED is lit, restart the pattern }

C:\Users\Michael_Geiger\Documents\courses\16...\src\pic16\c\05 VS Rotate\vs_rotate.c 2 unsigned char adc(void) { delay_us(5) GO = 1 while (GO) continue return ADRESH //wait for ADC charging cap to settle //wait for conversion to be finished //grab the top 8 MSbs }