The University of Texas at Arlington Lecture 5

Similar documents
Flow Charts and Assembler Programs

Binary Outputs and Timing

The University of Texas at Arlington Lecture 7

Input/Output Ports and Interfacing

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

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

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

ECE Test #1: Name

Arithmetic,logic Instruction and Programs

Lecture (04) PIC16F84A (3)

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.

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

Embedded System Design

ECE Homework #3

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

PIC 16F84A programming (II)

The University of Texas at Arlington Lecture 3

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

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

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

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

EECE.3170: Microprocessor Systems Design I Spring 2016

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

ME 6405 Introduction to Mechatronics

EEE111A/B Microprocessors

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

ME 515 Mechatronics. A microprocessor

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Micro II and Embedded Systems

EECE.3170: Microprocessor Systems Design I Summer 2017

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Lecture (04) PIC 16F84A programming I

DERTS Design Requirements (1): Microcontroller Architecture & Programming

PIC Discussion. By Eng. Tamar Jomaa


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

Lecture (03) PIC16F84 (2)

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)

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

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

Assembly Language Instructions

Week1. EEE305 Microcontroller Key Points

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

PIC16F8X. 8-Bit CMOS Flash/EEPROM Microcontrollers PIC16F8X PIC16CR8X. Pin Diagram. Devices Included in this Data Sheet:

CONNECT TO THE PIC. A Simple Development Board

Laboratory: Introduction to Mechatronics

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

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

Embedded Systems Programming and Architectures

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

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

Application Note - PIC Source Code v1.1.doc

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

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

Chapter 3: Further Microcontrollers

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

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

Input/Output Ports and Interfacing LCD & Seven Segment Display

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

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

D:\PICstuff\PartCounter\PartCounter.asm

Figure 1: Pushbutton without Pull-up.

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

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

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

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

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

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

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

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

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

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

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

Learning Objectives:

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

Laboratory Exercise 5 - Analog to Digital Conversion

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

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

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

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

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

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

MICROPROCESSORS A (17.383) Fall Lecture Outline

M PIC16F84A. 18-pinEnhanced FLASH/EEPROM 8-Bit Microcontroller. High Performance RISC CPU Features: Pin Diagrams. Peripheral Features:

Microcontrollers. Introduction to the PIC 8-bit Midrange Family. ECE Senior Design 15 February 2017

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

Simon. Final Project Report December 11, 2009 E155. Julia Karl and Kirsten McAfee

Performance & Applications

LCD. Configuration and Programming

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

PIC16C52. EPROM-Based 8-Bit CMOS Microcontroller PIC16C52. Pin Diagrams. Feature Highlights. High-Performance RISC CPU. Peripheral Features

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

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

Chapter 11: Interrupt On Change

Section 4. Architecture

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

THE UNIVERSITY OF THE WEST INDIES

SOLUTIONS!! DO NOT DISTRIBUTE!!

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

Transcription:

The University of Texas at Arlington Lecture 5 CSE 3442/5442

LCD Discussed in Chapter 12 RS, R/W, E Signals Are Used to Send/Receive Data on D0-D7 2

PIC PROGRAMMING IN C CHAPTER 7 Chapter 7 discusses the special C constructs or statements for using C with the PIC. We will continue to study the assembler instructions that help understand the PIC architecture but will do labs and programming in C. As we go through Chapter 4, accessing the I/O ports with assembler, we will discuss the related C statements for performing the same function in Chapter 7. 3

Chapter 4 PIC I/O PORT PROGRAMMING Ports are not only used for simple I/O, but also can be used for other functions such as ADC, timers, interrupts, and serial communication pins. Figure 4-1 shows the alternate functions for the PIC18F458 pins. 4

PIC18F458 Pin Diagram RA0-RA5 RB0-RB7 RA6 CSE 3442/4442 Lecture 3 5

Number of Individual Port Pins For example, for the PIC18F458, Port A has 7 pins; Ports B, C, and D each have 8 pins; and Port E has only 3 pins. Each port has three SFRs associated with it. -- PORTx, TRISx, and LATx (LATch). 6

Using PIC18F458 A-E Ports for Input/Output Each of the Ports A-E in the PIC18F458 can be used for input or output. The TRISx SFR is used solely for the purpose of making a given port an input or output port. To make a port an output, write Os to the TRISx register. Or, to output data to any of the pins of the Port B, first put Os into the TRISB register to make it an output port. Then send the data to the Port B SFR. 7

Addresses of SFR, PORTx, TRISx (TRIState), and LATx (LATch). See Table 4-2 PORTA F80H PORTB F81H TRISA F92H 8

Recall in Lecture 3 - SFR Window in MPLAB Simulator 9

Example Using Port A as Input In order to make all the bits of Port A an input, TRISA must be programmed by writing 1 to all the bits. In the next slide code, Port A is configured first as an input port by writing all 1 s to register TRISA, and then data is received from Port A and saved in some RAM location of the filereg: 10

PORT A as Input MYREG EQU 0X20 ;Program location MOVLW B 11111111 ;All 1 s to WREG MOVWF TRISA ;Port A as input port (1 for In) MOVF PORTA,W ;move from filereg of Port A to WREG MOVWF MYREG ;save in filereg of MYREG 11

PORT B as Input In order to make all the bits of Port B an input, TRISB must be programmed by writing 1 to all the bits. In the following code, Port B is configured first as an input port by writing all 1 s to register TRISB, and then data is received from Port B and saved in some RAM location of the filereg: MYREG EQU OX25 ; save it here MOVLW B'llllllll' ;WREG = 11111111 (binary) MOVWF TRISB ; make Port B an input port (1 for In) MOVF PORTB,W ; move from filereg of Port B to WREG MOVWF MYREG ; save it in filereg 12

Using C to Set Port B as Input and Read Port B #include <P18F452.h> // #include <P18cxxx.h> ; adds all of the header files // needed for PIC18 family void main(void) { unsigned char mybyte; TRISB = 0xFF; port B as input mybyte = PORTB; read Port B ; and save in mybyte. 13

Dual role of Ports The PIC18 multiplexes an analog-to-digital converter through Port A to save I/O pins. The alternate functions of the pins for PortA are shown in Table 4-3. ADC is discussed in Chapter 13. Since many projects use an ADC, typically do not use Port A for simple I/O functions. The PICI8 multiplexes some other functions through Port B, C, and D to save pins. 14

Figure 4-1 PICF458 Pin Diagram 15

QuickFlash Board 16

Note: Bit 4 of Port A is Open Drain QuickFlash Board Note: Pull Up to resistor to VDD 17

Dual Role of Ports A&B 18

Dual Role of Ports C&D 19

Using Ports as Both Input & Output To use the pins of Ports as both input and output ports; each bit must be connected externally to the pin by enabling the bits of register TRISB. Due to timing issues, do not have two I/O operations one right after the other. The following code will read from PortC and send to Port B: 20

Reading from Port C and sending to Port B: CLRF TRISB ; Clear TRISB output port SETF TRIBC ; Set Port C input port L4 MOVF PORTC,W ;read from Port C NOP ; delay one instruction MOVWF PORTB ;send to Port B BRA L4 ;repeat 21

Pipeline Activity for Both Fetch and Execute 22

Pipeline for Read Followed by Write I/O 23

C Program to Read From B and Send to C (Example 7-10) 24

C Program to Read From C and Output to B or D (Example 7-11) 25

Outputting (Writing) 0 to a Pin in the PIC18 26

Outputting (Writing) 1 to a Pin in the PIC18 27

Inputting (Reading) 0 from a Pin in the PIC18 28

Inputting (Reading) 1 from a Pin in the PIC18 29

LATx Register Role in Reading a Port or Latch 30

Example of Interfacing PIC to LED/Switches on QuickFlash Potentiometer LED s Push Button Switch CSE 3442/4442 Lecture 6 31

Chapter 4 Working with I/O ports - C Program to Read From C and Output to B or D (Example 7-11) CSE 3442/4442 Lecture 6 32

Single-Bit Addressing Review Assembler Instructions Table 4-8 BSF, BCF, BTG BIT Set/Clear/Toggle BTFSC, BTFSS Bit test, skip if clear/set Single-Bit Addressing RA0, RA5..RA8, RB0..RB8 CSE 3442/4442 Lecture 6 33

Example 7-14 pp 263 CSE 3442/4442 Lecture 6 34

Assignment for Tuesday, September 10 Finish Reading Chapter 4 Read Chapter 12, pages 473-481 HW#2 Due Thursday September, 12. 35