Programming 8-bit PIC Microcontrollers in C Martin Bates Elsevier 2008.

Slides:



Advertisements
Similar presentations
Parul Polytechnic Institute
Advertisements

MC68HC11 System Overview. System block diagram (A8 version)
Chapter 2 HARDWARE SUMMARY
Processor System Architecture
Microcontroller – PIC – 4 PIC types PIC architecture
Introduction of Holtek HT-46 series MCU
1-1 Microprocessor Engineering Microprocessor Systems Microcontrollers Infineon 16-bit Processor Family  specifically 167CS microcontroller C Programming.
HT46 A/D Type MCU Series Data Memory (Byte) Program Memory HT46R22 (OTP) HT46C22 (Mask) 2Kx Kx16 4Kx HT46R23 (OTP) HT46C23 (Mask) HT46R24.
Railway Foundation Electronic, Electrical and Processor Engineering.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 29: Microcontroller intro.
Microcontroller Architecture— PIC18F Family
Railway Foundation Electronic, Electrical and Processor Engineering.
Microcontroller Architecture PIC18F Family
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Micro controllers A self-contained system in which a processor, support, memory, and input/output (I/O) are all contained in a single package.
PIC microcontrollers. PIC microcontrollers come in a wide range of packages from small chips with only 8 pins and 512 words of memory all the way up to.
ECE/CS-352: Embedded Microcontroller Systems Embedded Microcontroller Systems.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Khaled A. Al-Utaibi  Intel Peripheral Controller Chips  Basic Description of the 8255  Pin Configuration of the 8255  Block Diagram.
Dr. Rabie A. Ramadan Al-Azhar University Lecture 6
1 SERIAL PORT INTERFACE FOR MICROCONTROLLER EMBEDDED INTO INTEGRATED POWER METER Mr. Borisav Jovanović, Prof.dr Predrag Petković, Prof.dr. Milunka Damnjanović,
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Embedded System Design Laboratory October 4, 2002Stanford University - EE281 Lecture #3#1 Lecture #3 Outline Announcements AVR Processor Resources –UART.
Prepared by Eng. Musa Alyaman1 Chapter Seven Chapter Seven PIC16F87x.
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
INTRODUCTION TO PIC MICROCONTROLLER. Overview and Features The term PIC stands for Peripheral Interface Controller. Microchip Technology, USA. Basically.
DsPIC30F4011 Fall DIP Switches  The upper four switches of SW1 are used to enable LEDs connected to PORTB/C, PORTA/D, PORTE and PORTF. For example,
S4525A Peripherals & Enhanced FLASH 1 © 1999 Microchip Technology Incorporated. All Rights Reserved. S4525A Peripherals & Enhanced FLASH 1 Peripherals.
CIT 673 Created by Suriyong1 Micro controller hardware architechture.
Presented by Sadhish Prabhu
Lecture 7: Overview Microprocessors / microcontrollers.
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Components of a typical full-featured microcontroller.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
CEng3361/18 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2007 Recitation 01.
Criteria for choosing a microcontroller A microcontroller must meet the task at hand efficiency and cost effectively. Speed. What is highest speed of.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER
CORDLESS MOUSE FEATURES BY TV REMOTE USING PIC MICROCONTROLLER
Introduction to Microcontroller Technology
Embedded Microcontroller Systems
Embedded Systems Programming
PROGRAMMABLE LOGIC CONTROLLERS SINGLE CHIP COMPUTER
Embedded Microcontroller Systems
Microcontroller Applications
Microprocessor Systems Design I
UNIT – Microcontroller.
Microprocessor Systems Design I
Project Title EVM IN PIC Under the Guidance of Submitted by.
Atmega32 Serial Programming Basics
The Arduino Microcontroller: Atmel AVR Atmega 328
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Introduction to Microprocessors and Microcontrollers
Interfacing Memory Interfacing.
Introducing the PIC Mid-Range Family and the 16F84A
AVR – ATmega103(ATMEL) Architecture & Summary
EECE.3170 Microprocessor Systems Design I
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
Presentation transcript:

Programming 8-bit PIC Microcontrollers in C Martin Bates Elsevier 2008

This presentation contains illustrations from the book ‘Programming 8-bit PIC Microcontrollers in C’ Part 1 Microcontroller Systems describes in detail the internal architecture and interfaces available in the PIC 16F887A, a typical PIC chip, as well as outlining the main features of the development system Part 2 C Programming Essentials provides simple example programs for the microcontroller which show the basic principles of C programming, and interfacing to basic I/O devices Part 3 C Peripheral Interfaces provides example programs for operating PIC chips with a full range of peripherals, using timers and interrupts

MICROCONTROLLER SYSTEMS Part 1 MICROCONTROLLER SYSTEMS

Figure 1.1 Elements of a digital controller CPU Central Processing Unit Input Peripherals Output ROM Read Only Memory RAM Read & Write Program download User input User output The microcontroller contains all these elements in one chip

Figure 1.2 16F877 pin-out The microcontroller pins have multiple functions

Arithmetic & Logic Unit Figure 1.3 PIC 16F877 MCU Block diagram Flash ROM Program Memory 8192 x 14 bits 0000 – 1FFF Instruction Register MCU control lines Program Counter (13 bits) Stack 13 bits x 8 levels RAM File Registers 368 X 8 bits 000-1FF Data Bus (8 bits) File Select Register Working (W) File Address Literal Op-code Instructions Address Arithmetic & Logic Unit Ports, Timers ADC, Serial I/O Status bits Timing control EEPROM 256 bytes Clock Reset Port A B C D E Program address Instruction Decode & CPU control Status (Flag) Shows the main parts of the chip in simplified form

Table 1.1 PIC16F877 simplified file register map   Table 1.1 PIC16F877 simplified file register map Bank 0 (000 – 07F) Bank 1 (080 – 0FF) Bank 2 (100-180) Bank 3(180-1FF)   Address Register 000h Indirect 080h 100h 180h 001h Timer0 081h Option 101h 181h 002h PC Low 082h 102h 182h 003h Status Reg 083h 103h 183h 004h File Select 084h 104h 184h 005h Port A data 085h PortA direction 105h - 185h 006h Port B data 086h PortB direction 106h 186h 007h Port C data 087h PortC direction 107h 187h 008h Port D data 088h PortD direction 108h 188h 009h Port E data 089h PortE direction 109h 189h 00Ah PC High 08Ah 10Ah 18Ah 00Bh Interrupt Control 08Bh 10Bh 18Bh 00Ch to 01Fh  20 Peripheral Control Registers 08Ch 09Fh  10Ch 10Fh  4 Peripheral  18Ch 18Fh  110h 16Fh 96 General Purpose  190h 1EFh  96 General  020h 06Fh  80 General  0A0h 0EFh  070h 07Fh  16 Common Access GPRs  0F0h 0FFh Accesses 70h – 7Fh 170h 17Fh  Accesses  1F0h 1FFh  

Table 1.2 PIC microcontroller types   MCU Pins Data word (bits) Program memory (bytes) Typical Instruction Set Speed MIPS Comment 10FXXX = 6 8 <= 512 33 x 12 bits <= 2 Low pin count, small form factor, cheap No EEPROM, none low power, assembler program 12FXXX = 8 <= 2 KB 12 / 14 bits <= 5 EEPROM, 10-bit ADC, some low power, assembler 16FXXX <= 64 <= 14 KB 35 x 14 bits Mid-range, UART, I2C, SPI many low power, C or assembler program 18FXXXX <= 100 <= 128 KB 75 x 16 bits <= 16 High range, CAN, USB J series 3V supply, C program 24FXXXX 16 76 x 24 bits = 16 Power range, 3V supply, no EEPROM, data RAM < 8 KB, C program

Figure 1.4 I/O pin operation CPU Data Bus Output Current Driver Data Latch Direction Tri-state Enable Input Write data bit Read data bit Write TRIS bit Analogue input multiplexer The pin can be set for input or output data transfer

Figure 1.5 General Timer Operation Binary Counter Pre-scaler (clock divide) Post-scaler (output divide) Timer Overflow/ Timeout (Interrupt) Flag Clock Source Select Instruction Clock External Pulse Capture register Compare register Capture signal Match flag A binary counter is used as a timer when driven from the clock

The ADC converts an analog input into a binary code Figure 1.6 ADC operation ANx Analogue to Digital Converter Vref+ Input volts 0-Vf Reference volts, Vf 8-bit or 16-bit integer result Setup ADC Read ADC The ADC converts an analog input into a binary code

Figure 1.7 Comparator operation Vc+ Vc- Compartor status bit Vc+ > Vc- The comparator simply sets a bit if one input is higher than the other

Figure 1.8 Parallel Slave Port operation Chip select Read Write EXTERNAL Data x 8 Interrupt INTERNAL The PSP allows an external data bus to be connected to the MCU

Table 1.3 Interrupts sources in the PIC 16F877 Interrupt Source Interrupt trigger event CCS C Interrupt label TIMERS Timer 0 Timer 0 register overflow INT_TIMER0 Timer 1 Timer 1 register overflow INT_TIMER1 CCP 1 Timer 1 capture or compare detected INT_CCP1 Timer 2 Timer 2 register overflow INT_TIMER2 CCP2 Timer 2 capture or compare detected INT_CCP2 PORTS RB0/INT pin Change on single pin RB0 INT_EXT Port B pins Change on any of four pins RB4 – RB7 INT_RB Parallel Slave Port Data received at PSP (write input active) INT_PSP Analog Converter A/D conversion completed INT_AD Analog Comparator Voltage compare true INT_COMP SERIAL UART Serial Port Received data available INT_RDA Transmit data buffer empty INT_TBE SPI Serial Port Data transfer completed (read or write) INT_SSP I2C Serial Port Interface activity detected Bus collision detected INT_BUSCOL MEMORY EEPROM Non-volatile data memory write complete INT_EEPROM

Figure 1.9 Timer Interrupt Process Program Execution 1 Start counter statement 2 Run Counter until overflow 5 Time-out Process (Interrupt Service Routine) 7 Continue 3 Timeout Interrupt 6 Return from 4 Jump to ISR Time-out forces the program to be suspended and the ISR executed

Line drivers convert the signal to a bipolar, higher voltage Figure 1.10 USART RS232 Signal PIC MCU TX1 Transmit RX1 Receive Ground HOST PC RX2 TX2 COM PORT Line Driver Interface +/- 12V Line drivers convert the signal to a bipolar, higher voltage

Figure 1.11 Typical USART RS232 signal Bit 2 3 Idle Start 1 4 5 6 7 Stop Time Bit period The data bits are timed from the falling edge of the start bit

Figure 1.12 SPI Connections Master Serial Data Out, SDO Serial Data In, SDI Serial Clock, SCK Slave Select SS1 Outputs SS2 SS3 Slave 1 SDO SDI SCK !SS Slave 2 SPI uses hardware slave selection and separate clock

Each data bit is transferred on the falling edge of the clock Figure 1.13 SPI Signals SDO/SDI 7 6 5 4 3 2 1 0 Data bits SCK Clock Each data bit is transferred on the falling edge of the clock

Slave selection uses addresses issued by the Master Figure 1.14 I2C Connections +5V Master Slave1 Slave2 etc SDA SCL Slave selection uses addresses issued by the Master

Data is strobed in using the master clock, and reception Figure 1.15 I2C Signals Start Acknowledge Address / Data bits SDA 7 6 5 4 3 2 1 0 SCL Data is strobed in using the master clock, and reception is acknowledged by the slave by taking the data line low

Listing 1.1 A simple C program /* OUTBYTE.C MPB 2-1-07 V1.0 */   #include "16F877A.h" // MCU select void main() // Main block { output_D(255); // Switch on outputs }   This minimal program outputs a binary code to Port D

Listing 1.2 Program hex file :1000000000308A0004280000840183131F30830518 :1000100083161F149F141F159F1107309C00880121 :08002000FF3083128800630029 :02400E00733FFE :00000001FF ;PIC16F877A   The machine code is downloaded as a binary file to the chip

Figure 1.16 Screenshot of MPLAB Project The C program is compiled and tested in simulation mode

Figure 1.17 PICkit2 demo system hardware Basic hardware for downloading the program to a test board

Figure 1.18 ICSP target board connections Application Board MCU Vpp/!MCLR Vdd Vss PGD PGC 1 2 3 4 5 ICSP Interface Reset 10k Vdd Vss Board +5V Supply Connections to the target chip for programming

Figure 1.19 PICkit2 programmer dialogue On-screen window for program downloading to target chip

Figure 1.20 Microchip ICD2 module ICD2 provides in-circuit debugging

Figure 1.21 ICD2 program and debug system Host PC MPLAB development system + C Compiler ICD2 interface PIC MCU Target System USB 6-WAY connector Block diagram of the ICD2 programming and in-circuit debugging system

Figure 1.22 ICD debugging windows User interface for in-circuit programming & debugging