ECE Homework #3

Similar documents
Flow Charts and Assembler Programs

Binary Outputs and Timing

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

ECE Test #1: Name

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

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

The University of Texas at Arlington Lecture 5

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

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

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

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

PIC 16F84A programming (II)

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

Arithmetic,logic Instruction and Programs

Lecture (04) PIC16F84A (3)

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

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

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

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

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.

Input/Output Ports and Interfacing

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

Application Note - PIC Source Code v1.1.doc

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

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

Embedded System Design

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

Laboratory Exercise 5 - Analog to Digital Conversion

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

D:\PICstuff\PartCounter\PartCounter.asm

PIC Discussion. By Eng. Tamar Jomaa

Figure 1: Pushbutton without Pull-up.

Assembly Language Instructions

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

EEE111A/B Microprocessors

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

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

CONNECT TO THE PIC. A Simple Development Board

SOLUTIONS!! DO NOT DISTRIBUTE!!

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

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

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Inverted Pendulum Microprocessor and FPGA Manual Sheldon Logan July 3, 2006

16.317: Microprocessor-Based Systems I Summer 2012

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

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

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

Chapter 3: Further Microcontrollers

Embedded Systems Programming and Architectures

The University of Texas at Arlington Lecture 3

EECE.3170: Microprocessor Systems Design I Spring 2016

MICROPROCESSORS A (17.383) Fall Lecture Outline

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

The University of Texas at Arlington Lecture 7

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

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

Laboratory Exercise 7 - Extended I/O & Parallel Processing

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)

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

Experiment 7:The USART

16.317: Microprocessor-Based Systems I Spring 2012

Section 30. In-Circuit Serial Programming (ICSP )

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

MPASM 5.46 AT89C2051_PROGRAMMER.ASM :21:50 PAGE 1 VALUE

Professor E. Ambikairajah UNSW Sydney


SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

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

THE UNIVERSITY OF THE WEST INDIES

Tutorial for PICMON18 Debug Monitor

Chapter 11: Interrupt On Change

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

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

ME 515 Mechatronics. A microprocessor

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

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

Week1. EEE305 Microcontroller Key Points

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

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

EE 367 Introduction to Microprocessors Homework 6

LPTCOM. Bruce Misner Lakehead University h d3 RD2 pin 21. RD3 pin h d4. RD4 pin 27 RD5 pin h d5. RD6 pin 29 RD7 pin H d6

CREATING FIRST PROJECT in mikropascal PRO for PIC32

Chapter 5 Sections 1 6 Dr. Iyad Jafar

PIC Dev 14 Surface Mount PCB Assembly and Test Lab 1

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

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

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

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

PIC Dev 14 Through hole PCB Assembly and Test Lab 1

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

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Microcontroller Overview

LED Knight Rider. Yanbu College of Applied Technology. Project Description

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

Learning Objectives:

MPLAB -ICD USER S GUIDE

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

Transcription:

ECE 376 - Homework #3 Flow Charts, Binary Inputs, Binary Outputs (LEDs). Due Monday, January 29th The temperature sensor in your lab kits has the temperature-resistance relationship of R = 1000 exp 3965 3965 T 298 Ω where T is the temperature in degrees Kelvin (C + 273) 1) Design a circuit which outputs 0V when the temperature is below 0C when the temperature is above 0C At 0C, R = 3381Ω Assume a voltage divider with a 3300 Ohm resistor. Then V = R R+3300 As temperature goes up... = 2.5306V R goes down Vin goes down Vout goes up Connect the divider to the - input Connect 2.4306V to the + input 3300 2.5306V MCP602 Y R Vin 0V 0V 2.53V Hot 0C Cold

2) Design a circuit with hysteresis which outputs 0V when the temperature goes below 0C and when the temperature goes above 5C Assume a voltage divider with a 3300 Ohm resistor like problem #1 At 0C R = 3381 Ohms Vin = 2.5306V Vout goes low At 5C R = 2604 Ohms Vin = 2.205 Vout goes high As Vin goes low, Vout goes high. Connect the voltage divider to the - input The gain you need is gain = V out V in gain = 0V 2.5306V 2.205 = 15.38 When the output is 0V, you switch at 2.205. Set the + input to 2.205 153k 3300 Vin 2.20V 10k Y Vout R 10k Vin 0V 0V 2.20V 2.53V 153k hot 5C 0C cold

The characteristics for a piranha RGB LED is Red: Vf = 1.8V @ 20mA 10,000 mcd @ 20mA Green: Vf = 3.0V @ 20mA 10,000 mcd @ 20mA Blue: Vf = 3.0V @ 20mA 10,000 mcd @ 20mA 3) Design a circuit so that the PIC can turn on and off each LED at 20mA. Assign the I/O pins to: RC0: Red RC1: Green RC2: Blue Red Green Blue R r = 1.8V 20mA = 160Ω R g = 3.0V 20mA = 100Ω R b = 3.0V 20mA = 100Ω RC2 RC1 RC0 anode Rb Rg Rr cathode 3.0V 3.0V 1.8V blue green red Piranah Package common cathode + cathode + 3.0V - + blue 3.0V green 1.8V - + - red anode Rb Rg Rr RC2 RC1 RC0 Piranah Package common anode

The following program turns your PIC into an multi-function flashlight: Requirements: Input: Buttons RB0.. RB5 Output: Piranha RGB LED connected to pins RC0..RC1 Relationship: When you press a button, the color changes to: RB0: All colors off RB1 Red RB2 Green RB3 Blue RB4 White (R, G, B all on) RB5: Random color "On" is defined as 20mA +/- 5mA. Analysis:

4) Write an assembler program to implement this LED flashlight #include <p18f4620.inc> COLOR equ 0 ; Start of code: org 0x800 clrf TRISA movlw 0xFF movwf TRISB clrf TRISC clrf TRISD clrf TRISE clrf COLOR movlw 0x0F movwf ADCON1 Main: movf COLOR, W btfsc PORTB,0 ; off movlw 0 btfsc PORTB,1 ; red movlw 1 btfsc PORTB,2 ; green movlw 2 btfsc PORTB,3 ; blue movlw 4 btfsc PORTB,4 ; white movlw 7 btfss PORTB,5 ; random goto Output Random: addlw 1 btfsc PORTB,5 goto Random andlw 0x07 Output: movwf COLOR movff COLOR, PORTC goto Main RB0 RB1 RB2 Start Initialize PORTC = Input PORTC = Output Recall Present Color Button Pressed? none Off Red Green Blue White Random Output Color to PORTC RB3 RB4 RB5 end Compilation Results: Loaded C:\Documents and Settings\Administrator\My Documents\ECE376\Assembler\Flashlight.cof. Debug build of project `C:\Documents and Settings\Administrator\My Documents\ECE376\Assembler\1234.mcp' succeeded. Language tool versions: MPASMWIN.exe v5.51, mplink.exe v4.49, mplib.exe v4.49 Preprocessor symbol ` DEBUG' is defined.mon Jan 22 07:00:47 2018 BUILD SUCCEEDED

If you look at the.lst file: LOC OBJECT CODE VALUE LINE SOURCE TEXT 00001 #include <p18f4620.inc> 00001 LIST 00002 00003 ;========================================================================== 00004 ; MPASM PIC18F4620 processor include 00005 ; 00006 ; (c) Copyright 1999-2013 Microchip Technology, All rights reserved 00007 ;========================================================================== 00008 01439 LIST 00002 00000000 00003 COLOR equ 0 00004 00005 ; Start of code: 00006 000800 00007 org 0x800 00008 000800 6A92 00009 clrf TRISA 000802 0EFF 00010 movlw 0xFF 000804 6E93 00011 movwf TRISB 000806 6A94 00012 clrf TRISC 000808 6A95 00013 clrf TRISD 00080A 6A96 00014 clrf TRISE 00080C 6A00 00015 clrf COLOR 00016 00080E 0E0F 00017 movlw 0x0F 000810 6EC1 00018 movwf ADCON1 00019 000812 00020 Main: 000812 5000 00021 movf COLOR, W 00022 000814 B081 00023 btfsc PORTB,0 000816 0E00 00024 movlw 0 000818 B281 00025 btfsc PORTB,1 00081A 0E01 00026 movlw 1 00081C B481 00027 btfsc PORTB,2 00081E 0E02 00028 movlw 2 000820 B681 00029 btfsc PORTB,3 000822 0E04 00030 movlw 4 000824 B881 00031 btfsc PORTB,4 000826 0E07 00032 movlw 7 000828 AA81 00033 btfss PORTB,5 00082A EF1C F004 00034 goto Output 00082E 00035 Random: 00082E 0F01 00036 addlw 1 000830 BA81 00037 btfsc PORTB,5 000832 EF17 F004 00038 goto Random 000836 0B07 00039 andlw 0x07 000838 00040 Output: 000838 6E00 00041 movwf COLOR 00083A C000 FF82 00042 movff COLOR, PORTC 00083E EF09 F004 00043 goto Main 00044 MPASM 5.51 FLASHLIGHT.ASM 1-22-2018 7:00:45 PAGE 2

If you look at the.hex file :020000040000FA :10080000926AFF0E936E946A956A966A006A0F0E5A :10081000C16E005081B0000E81B2010E81B4020E93 :1008200081B6040E81B8070E81AA1CEF04F0010FF7 :1008300081BA17EF04F0070B006E00C082FF09EFCA :0208400004F0C2 :00000001FF That's your program. It taks 29 lines of assembler to make a flashlight. Validation: 5) Compile and download your code to your PIC board. Collect data to verify that you met the requirements: The current through each color is 20mA +/- 5mA Each button changes the output color RB5 produces a 'random' color (i.e. a random number from 0 to 7 is output to PORTC when you release RB5)

6) For your resulting program... How long does it take your program to loop? (toggle a bit you're not using, such as RC4, in the main loop. Check on the oscilloscope how fast this bit is toggling). How many lines of assembler does it take to implement an LED flashlight?