Using The PIC I/O Ports



Similar documents
Section 9. I/O Ports

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

Section 14. Compare/Capture/PWM (CCP)

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

PIC Programming in Assembly. (

Section 19. Voltage Reference

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

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

Section 28. In-Circuit Serial Programming (ICSP )

I 2 C Master Mode Overview and Use of the PICmicro MSSP I 2 C Interface with a 24xx01x EEPROM

MACHINE ARCHITECTURE & LANGUAGE

How To Program A Microcontroller With Memory On A Microchip Microcontroller

Using Altera MAX Series as Microcontroller I/O Expanders

An Introduction to MPLAB Integrated Development Environment

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Microprocessor & Assembly Language

PART B QUESTIONS AND ANSWERS UNIT I

Analog-to-Digital Converters

Computer Organization and Components

Lecture N -1- PHYS Microcontrollers

PIC in Practice. A Project-Based Approach. D. W. Smith

Section 29. Instruction Set

Lecture-3 MEMORY: Development of Memory:

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Measuring Resistance Using Digital I/O

Switch board datasheet EB

CAN bus board. EB018

8031AH 8051AH 8032AH 8052AH NMOS SINGLE-CHIP 8-BIT MICROCONTROLLERS

c0003 A Simple PIC Application CHAPTER 3

Eliminate Risk of Contention and Data Corruption in RS-485 Communications

Computer organization

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

Introduction to PIC Programming

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Section bit A/D Converter

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Serial Communications

Embedded C Programming

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

8051 hardware summary

Section 8. Interrupts

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

(Refer Slide Time: 00:01:16 min)

How to design and implement firmware for embedded systems

Chapter 13. PIC Family Microcontroller

Using Xbee in Serial Communication

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

PIC16F8X. 18-pin Flash/EEPROM 8-Bit Microcontrollers. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

MICROPROCESSOR AND MICROCOMPUTER BASICS

AN727. Credit Card Reader Using a PIC12C509 DATA ENCODING INTRODUCTION FIGURE 1: POSITION OF ISO TRACKS 1, 2 AND 3. Andrew M Errington

Memory organization. Memory blocks: Program memory (flash-type) 16 kword (32 kbyte) (instruction 16 bit wide) Data RAM 1536 byte (1.

Introduction to Arduino

SIMPLE EPROM PROGRAMMER. EPROM Programmer Design. Hardware

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Section bit A/D Converter

2.0 Command and Data Handling Subsystem

DS1621 Digital Thermometer and Thermostat

S7 for Windows S7-300/400

Using the HT46R46 I/O Ports to Implement Half-Duplex SPI Communication

Building A RISC Microcontroller in an FPGA

1. The demonstration code is sending garbage to my terminal program. What are the recommended settings?

Chapter 2 Logic Gates and Introduction to Computer Architecture

10-bit Σ ADC from a PIC16F84

MICROPROCESSOR. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Test Driven Development of Embedded Systems Using Existing Software Test Infrastructure

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

8254 PROGRAMMABLE INTERVAL TIMER

Am186ER/Am188ER AMD Continues 16-bit Innovation

The Design of Mobile Control Car Security System

Definitions and Documents

Chapter 2: OS Overview

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Technical Note. Initialization Sequence for DDR SDRAM. Introduction. Initializing DDR SDRAM

FEATURES DESCRIPTION. PT6321 Fluorescent Display Tube Controller Driver

Application Note, V2.2.1, July 2003 AP OCDS Level 1 JTAG Connector. 16-Bit & 32-Bit Microcontrollers. AI Microcontrollers. Never stop thinking.

A New Paradigm for Synchronous State Machine Design in Verilog

The I2C Bus. NXP Semiconductors: UM10204 I2C-bus specification and user manual HAW - Arduino 1

Programmable State-Variable Filter Design For a Feedback Systems Web-Based Laboratory

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

GETTING STARTED WITH PROGRAMMABLE LOGIC DEVICES, THE 16V8 AND 20V8

Cellphone Based Device Control With Voice Acknowledgement

HANDLING SUSPEND MODE ON A USB MOUSE

Construction and Application of a Computer Based Interface Card

Interrupts. 1.Maskable interrupt request can be ignored or delayed by the microprocessor and used in telephone

Let s put together a Manual Processor

OpenSPARC T1 Processor

DS1621 Digital Thermometer and Thermostat

Getting Started with PIC24F/PIC24H Programming and Interfacing in C

GLOLAB Universal Telephone Hold

EMBEDDED SYSTEMS PROGRAMMING WITH THE PIC16F877

Microtronics technologies Mobile:

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

Lecture 18: Common Emitter Amplifier. Maximum Efficiency of Class A Amplifiers. Transformer Coupled Loads.

Timer A (0 and 1) and PWM EE3376

Transcription:

EE2801 -- Lecture 22 Using The PIC I/O Ports EE2801-L22P01

The Variety Of Available IO Ports The PIC 16F874 microcontroller has five different IO ports, accounting for thirty three of the processors forty pins! The ports are defined as: Port A: 6 bit wide bi-directional port. Most of the pins double as analog input pins. The exception is RA4, which doubles as an input for one of the internal timers. Port B: Port C: Port D: Port E: 8 bit wide bi-directional port. These are primarily general-purpose IO pins. One special feature is that these pins also contain an internal pull-up resistor that is useful to save components in some designs. (Like the keypad on the development board!) These pins can also be used to receive hardware interrupts. 8 bit wide bi-directional port. These pins also may be configured to support the serial IO functions of the microcontroller. 8 bit wide bi-directional port. These pins can be configured to act as an microprocessor-style data bus, but are most commonly used as simple digital IO. 3 bit wide bi-directional port. This port is also a general-purpose digital IO port, but it may be configured to control Port D when that port is being used as a microprocessor-style bus. EE2801-L22P02

Port D - Simple, Straightahead Digital IO A block diagram of Port D is shown below. Notice that this is actually a complicated piece of logic. Also notice that there are several control signals that must be used to setup the port to operate the way we intend: To/from the processor s data bus Active on write Data Bus WR PORT D CK Q I/O pin Data Latch D Q Active on TRIS write Active on TRIS read WR TRIS CK TRIS Latch RD TRIS Q Schmitt Trigger Input Buffer D There are eight of these circuits, one for each IO pin. EN EN Active on read RD PORT EE2801-L22P03

The TRIS, Or Tri-State Enable Registers From the block diagram of the IO port, we see that writing a 0 into the TRIS latch for Port D (TRISD) will enable the active low buffer that is attached to the output pin. This means that anything written into the data latch will be seen on the IO Pin. That same data also goes through another buffer and appears at the input of the read latch. If we write a 1 into the TRISD latch, the output buffer is turned off, and nothing will be output from the IO pin. In this case, anything present on the input pin can be read by the processor. It s interesting to note that there is a path in the block diagram that allows the TRIS Latch to be read, but there is no path that allows the TRIS Latch to drive the IO pin. Each bit of the port has a bit in the TRIS register associated with it, so each IO bit can be assigned to be an input or an output. It would even be possible to do both under program control! At some point in the program pins can be output and at another some or all of them can be reassigned! This provides a very flexible way to IO. EE2801-L22P04

An Example Of Setting Up An Output Pin The following program goes through the process of setting up a subset of Port D pins as outputs, that also implies that the rest are set up as inputs (why?). After setting up the port, I write an FFh to it, meaning that all of the output latches will contain 1s. What is the expected result when I execute this? include p16f877.inc org 0x000 ; Start program at address 000 nop ; Required for debugger ; Initialize the tri-state register to make alternating ins and outs. ; Start bsf STATUS,RP0 ; Go to BANK 1 by setting bcf STATUS,RP1 ; RP1, RP0 = 01. movlw 0xAA ; W = 1010 1010. movwf TRISD ; Set Port D for In, Out, etc. ; Now, write an FF to the outptu port. bcf STATUS,RP0 ; Go back to bank 0! movlw 0xFF ; W = FFh. movwf PORTD ; Write to Port D. Here goto Here End EE2801-L22P05

Think Carefully About What We Just Did! Let s make a minor modification to our program and now read the content of Port D. The we ll read again after setting the TRISD register to FFh. How do we explain this behavior? include p16f877.inc org 0x000 ; Start program at address 000 nop ; Required for debugger ; Initialize the tri-state register to make alternating ins and outs. ; Start bsf STATUS,RP0 ; Go to BANK 1 by setting bcf STATUS,RP1 ; RP1, RP0 = 01. movlw 0xAA ; W = 1010 1010. movwf TRISD ; Set Port D for In, Out, etc. ; Now, write an FF to the outptu port. bcf STATUS,RP0 ; Go back to bank 0! movlw 0xFF ; W = FFh. movwf PORTD ; Write to Port D. movf PORTD,W ; Get D into W. bsf STATUS, RP0 ; Go to Bank 1. clrf TRISD ; Set everything to output. bcf STATUS, RP0 ; Return to Bank 0. movf PORTD,W ; Get D into W. Here goto Here End EE2801-L22P06