Binary Outputs and Timing

Similar documents
Flow Charts and Assembler Programs

ECE Homework #3

The University of Texas at Arlington Lecture 5

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

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

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

Input/Output Ports and Interfacing

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

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.

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

Embedded System Design

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

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

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

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

Figure 1: Pushbutton without Pull-up.

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

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

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

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

D:\PICstuff\PartCounter\PartCounter.asm

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

Chapter 3: Further Microcontrollers

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

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

Laboratory Exercise 5 - Analog to Digital Conversion

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

PIC 16F84A programming (II)

Arithmetic,logic Instruction and Programs

Lecture (04) PIC16F84A (3)

Laboratory Exercise 7 - Extended I/O & Parallel Processing

CONNECT TO THE PIC. A Simple Development Board

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

Assembly Language Instructions

More Fun with Timer Interrupts

Chapter 5 Sections 1 6 Dr. Iyad Jafar

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Physics 335 Intro to MicroControllers and the PIC Microcontroller

PIC Discussion. By Eng. Tamar Jomaa

Application Note - PIC Source Code v1.1.doc

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

ME 515 Mechatronics. A microprocessor

Learning Objectives:

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

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

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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)

Embedded Systems Programming and Architectures

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

PIC Microcontroller Trainer

EECE.3170: Microprocessor Systems Design I Spring 2016

EEE111A/B Microprocessors

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

Week1. EEE305 Microcontroller Key Points

Experiment 7:The USART

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

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

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

Performance & Applications

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Introduction to PIC Programming

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

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

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

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

ﻢﯿﺣﺮﻟا ﻦﻤﺣﺮﻟا ﷲا ﻢﺴﺑ

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

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

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

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

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

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

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

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

SOLUTIONS!! DO NOT DISTRIBUTE!!

CREATING FIRST PROJECT in mikropascal PRO for PIC32

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

;=============================================================== ;RAM locations in Access bank, uninitialized UDATA_ACS

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

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

EECE.3170: Microprocessor Systems Design I Summer 2017

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Section 30. In-Circuit Serial Programming (ICSP )

PICDEM-1 USER S GUIDE

Microcontroller Overview

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

Chapter 11: Interrupt On Change

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

ELCT 912: Advanced Embedded Systems

Timer1 Capture Mode:

Introduction to PIC Programming

ME 6405 Introduction to Mechatronics

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

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

Transcription:

Binary Outputs and Timing Each of the I/O pins on a PIC can be inputs or ourputs As an input, the pin is high impedance (meaning it is passive and draws very little current). If you apply 0V to that pin, it is read as logic 0, 5V is logic 1 As an output, the pin is active. It will try to force the output pin to 0V (logic 0) or 5V (logic 1) A PIC chip has its limits: it is limited to sourcing or sinking 25mA (max). Note: To run these programs, make sure the default in MPLAB is decimal. Check this by going to Project - Build Options - Project MPASM: Decimal 1 September 20, 2016

Problem: Connect an 8-Ohm speaker to your PIC board. Solution: You can't connect an 8-Ohm speaker directly: it draws more than 25mA at 5V I = 5V 8Ω = 625mA (Actually, you can connect an 8-ohm speaker to an I/O pin. It tends to burn out that I/O pin, however.) To limit the current, add a resistor in series: R total = 5V 25mA = 200Ω Problem: Make noise with the speaker Solution: You can't connect a speaker to a constant (DC) source: all that does is push the cone out. To make noise, you need to move the cone back and forth to create pressure waves (i.e. sound). From the PIC's standpoint, you need to output a square wave on RC0: the frequency of the square wave is the frequency of the should you hear. From before, if you want to play the note C4 (261Hz), you need to output a square wave with a frequency of 261Hz on RC0: # Clocks = 10,000,000 2xHz At 261Hz # Clocks = 19,157 Ideally, there should be 19,157 clocks between each time you toggle RC0. 2 September 20, 2016

; --- Piano0.asm ---- ; This program toggles RC0 at 261 Hz (note C4) #include <p18f4620.inc> ; Variables CNT0 EQU 1 CNT1 EQU 2 ; Program Loop: org 0x800 call Init call Toggle call Wait goto Loop ; --- Subroutines --- Init: clrf TRISA clrf TRISB clrf TRISC clrf TRISD clrf TRISE movlw 15 movwf ADCON1 ;PORTA is output ;PORTB is output ;PORTC is output ;PORTD is output ;PORTE is output ;everyone is binary Toggle: btg PORTC,0 Wait: movlw 19 movlw 100 Note the following: 3 September 20, 2016

The wait routine (Wait) is a little off. It should wait 19,157 clocks. It actually waits # Clocks = ( 10*100 + 5 ) * 19 + 5 = 19,100 (0.29% low) Pin RC0 is always outputing a square wave. It's kind of annoying. On the oscilloscope, you can check the frequency: Signal on RC0 for 260.7Hz ( loop time = 19,157 clocks = 1.9157ms ) One Key Piano: Suppose instead you want to play this note only when you press RB0. One way to do this is to check if RB0 is pressed: If RB0 = 1 (button pressed), toggle RC0 Otherwise, leave RC0 alone This results in a square wave appearing on RC0 only when RB0 is pressed. A slight change in this code is that you can pass variables to subroutines through the W register. Instead of the wait loop always waiting 1911us, it waits 100us times whatever number is passed in W (19 in this case). 4 September 20, 2016

; This program toggles RC0 at 261 Hz (note C4) #include <p18f4620.inc> ; Variables CNT0 EQU 1 CNT1 EQU 2 ; Program Loop: org 0x800 call Init btfsc PORTB,0 call Toggle call Wait goto Loop ( same as before ) Note that if RB0 is not pressed, it skips over the toggle command. 4-Key Piano: Finally, design a 4-key piano: Whan you press RB0..RB3, the note should be: RB0: 261 Hz (C4) RB1: 293 Hz (D4) RB2: 329 Hz (E4) RB3: 349 Hz (F4) There are several ways to do this. One way is to use four wait loops: one for each frequency. If you get fancy, you can also write a single wait loop and adjust the period - but why get too fancy. The number of clocks to wait is # Clocks = 10,000,000 2xHz The clocks for each wait loop are then: Hz 261 293 329 349 # Clocks (ideal) 19,157.09 17,064.85 15,197.57 14,326.65 A 239 243 253 239 B 8 7 6 6 # Clocks (actual) 19,165 17,050 15,215 14,375 5 September 20, 2016

Note: The actual number of clocks is # Clocks = ( 10*A + 5 ) *B + 5 ; --- Piano2.asm ---- ; This program plays notes C4 / D4 / E4 / F4 #include <p18f4620.inc> ; Variables CNT0 EQU 1 CNT1 EQU 2 ; Program org 0x800 call Init Loop: movf PORTB,W btfss STATUS,Z call Toggle btfsc call PORTB,0 Wait_C4 no Start Initialize Ports Any Button yes toggle RC0 btfsc call btfsc call btfsc call goto PORTB,1 Wait_D4 PORTB,2 Wait_E4 PORTB,3 Wait_F4 Loop Button? RB0 RB1 RB2 RB3 Wait (C4) Wait (D4) Wait (E4) Wait (F4) ; --- Subroutines --- Init: clrf TRISA clrf TRISB clrf TRISC clrf TRISD clrf TRISE movlw 15 movwf ADCON1 ;PORTA is output ;PORTB is output ;PORTC is output ;PORTD is output ;PORTE is output ;everyone is binary Toggle: btg PORTC,0 Wait_C4: movlw 8 movlw 239 ; Wait 19,157 clocks 6 September 20, 2016

Wait_D4: movlw 7 movlw 243 ; Wait 17,064 clocks Wait_E4: movlw 6 movlw 253 ; Wait 15,197 clocks 7 September 20, 2016

Wait_F4: movlw 6 movlw 239 ; Wait 14,326 clocks Signal on RC0 for 293Hz ( 17,064 clocks / loop = 1.7064ms ) 8 September 20, 2016

Signal on RC0 for 329Hz ( 15,197 clocks = 1.5197ms) Signal on RC0 for 349Hz ( 14,326 clocks / cycle = 1.4326ms) 9 September 20, 2016