Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

Similar documents
Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

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

EE 361L Digital Systems and Computer Design Laboratory

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

Table of Contents COMPANY PROFILE 1-1 SECTION 1. INTRODUCTION 1-1

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

PIC Microcontroller Introduction

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

n/a PIC12F629-I/P (RC) n/a PIC12F629-I/SN (RC) n/a PIC12F675-I/P (RC) n/a PIC12F675-I/SN MICROCONTROLLER (RC)

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

Lecture (03) PIC16F84 (2)

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

Lecture (04) PIC 16F84A programming I

PIC-P67J60 development board Users Manual

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

Section 4. Architecture

Future PICmicro Microcontroller Products Guide 2000

MicroProcessor. MicroProcessor. MicroProcessor. MicroProcessor

PIC 16F84A programming (II)

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

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

Embedded System Design

JX-12. JX-12 : PIC12F6xx/PIC16F630/676 Project board 1

PIC18FXX2 Data Sheet. High Performance, Enhanced FLASH Microcontrollers with 10-Bit A/D Microchip Technology Inc. Advance Information DS39564A

Embedded Systems Programming and Architectures

University of Hawaii EE 361L MPLab Quick Tutorial and Project 2.1 Last updated September 1, 2011

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.

PIC18FXX2 Data Sheet. High Performance, Enhanced FLASH Microcontrollers with 10-Bit A/D Microchip Technology Inc. DS39564B

Development Hardware. Target Board and In-circuit Debugger

AX-12. PIC12F675 microcontroller Activity board

ELCT 912: Advanced Embedded Systems

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

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

MOD-ZIGBEE-PIR sensor development board USER S MANUAL All boards produced by Olimex LTD are ROHS compliant

Capacitive Touch Remote Control Reference Design User s Guide

PIC-LCD-3310 development board Users Manual

Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

Microcontroller Overview

Target Board PIC877-TB - Reference Manual

ME 515 Mechatronics. A microprocessor

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

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

DERTS Design Requirements (1): Microcontroller Architecture & Programming

PIC-I/O Multifunction I/O Controller

CHAPTER 1 - World of microcontrollers

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

ELCT706 MicroLab Session #4 UART Usage for Bluetooth connection PC - PIC

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

Speed Control of a DC Motor using Digital Control

ME 6405 Introduction to Mechatronics

Introduction to Arduino. Wilson Wingston Sharon

Enhanced FLASH Microcontrollers with Single Phase Induction Motor Control Kernel. I/O Pins. 10-bit A/D (ch) EEPROM

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

Lecture (02) PIC16F84 (I)

PIC16F5X Data Sheet. Flash-Based, 8-Bit CMOS Microcontroller Series

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

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

ET-PIC 24 WEB-V1. o Central Processing Unit (CPU) o System. o nanowatt Power Managed Modes. o Analog Features

CN310 Microprocessor Systems Design

PIC18CXX2. High Performance Microcontrollers with 10-bit A/D. High Performance RISC CPU: Pin Diagrams PIC18C4X2. Analog Features: Peripheral Features:

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

#pragma config Usage. #pragma config Settings. #pragma config <setting>=<named value>

PIC-IO development board User's Manual

Breeze Board. Type A. User Manual.

Section 28. WDT and SLEEP Mode

Laboratory 9. Programming a PIC Microcontroller - Part I

PIC16C432 OTP 8-Bit CMOS MCU with LIN bus Transceiver

PIC16F5X Data Sheet. Flash-Based, 8-Bit CMOS Microcontroller Series Microchip Technology Inc. DS41213D

PIC18CXX2 Data Sheet. High Performance Microcontrollers with 10-bit A/D Microchip Technology Inc. DS39026C

PIC16F5X Data Sheet. Flash-Based, 8-Bit CMOS Microcontrollers Microchip Technology Inc. Preliminary DS41213B

PIC-MAXI-WEB development board Users Manual

PIC16C Pin, 8-Bit CMOS Microcontroller. Device included in this Data Sheet: Special Microcontroller Features: High-Performance RISC CPU:

Breeze Board. Type B. User Manual.

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

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

THE LAB WORKSHOP MODELS ON MICROCHIP s PIC MICROCONTROLLERS IN EET PROGRAM

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

EEPROM Memory Programming Specification

PIC18CXX2. High-Performance Microcontrollers with 10-Bit A/D * * High Performance RISC CPU: Pin Diagrams PIC18C4X2.

EXPERIMENT 5. Oven Temperature Control Using Open loop and Closed Loop Methods

Section 21. Addressable USART

PIC-MICRO-WEB development board User's manual

RFID: Read and Display V2010. Version 1.1. Sept Cytron Technologies Sdn. Bhd.

PIC16F8X 18-pin Flash/EEPROM 8-Bit Microcontrollers

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

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

PICmicro MCU Multiprogrammer EB Technical datasheet

HI-TIDE Release Notes for Version 3.13

Introduction to Mechatronics and the Mechatronic Design Center Microchip Technology Incorporated. All Rights Reserved. 1

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

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

PICmicro MCU multiprogrammer

Laboratory Exercise 7 - Extended I/O & Parallel Processing

Laboratory: Introduction to Mechatronics

CENG-336 Introduction to Embedded Systems Development. Timers

PIC16C Pin, 8-Bit CMOS Microcontroller. Device included in this Data Sheet: Special Microcontroller Features: High-Performance RISC CPU:

Section 30. In-Circuit Serial Programming (ICSP )

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

Transcription:

8. Microcontroller Textbook Programming Robot Controllers, Myke Predko, McGraw Hill. Reference PIC Robotics: A Beginner's Guide to Robotics Projects Using the PIC Micro, John Iovine, McGraw Hill. Embedded C Programming and the Microchip PIC, Richard H. Barnet, Delmar Learning. PIC Microcontroller: An Introduction to Software & Hardware Interfacing, Han-Way Huang, Delmar Learning. MCU 2 / page Page

Microchip PICmicroMicrocontroller MCU 2 / page 2 Page 2

Microchip PICmicroMicrocontroller Also known as PIC Advantages: Easy to find parts from numerous distributors Many version of PIC function, size, package, I/O Free IDE tools e.g. MPLAB Free C compiler mikroelektronika mikroc (limited to 2K program) HI-TECH PICC Lite(limited to 6F84 and 6F627) Microchip / BurnonMPLAB C8 (time limited) MCU 2 / page 3 Page 3

PIC Experimental Board MCU 2 / page 4 Page 4

Basic Circuit Requirements Stable +5V supply Reset line input (MCLR) Clock Internal Resistor/capacitor (RC) Crystal oscillator MCU 2 / page 5 Page 5

Pin assignment PIC 6F627 MCU 2 / page 6 PIC6F62X PINOUT DESCRIPTION RA/AN RA Bi-directional I/O port AN Analog comparator input RA/AN RA Bi-directional I/O port AN Analog comparator input RA2/AN2/VREF RA2 Bi-directional I/O port AN2 Analog comparator input VREF AN VREF output RA3/AN3/CMP RA3 Bi-directional I/O port AN3 Analog comparator input CMP Comparator output RA4/TCKI/CMP2 RA4 Bi-directional I/O port TCKI Timer clock input CMP2 OD Comparator 2 output RA5/MCLR/VPP RA5 Input port MCLR Master clear VPP Programming voltage input. When configured as MCLR, this pin isan active low RESET to the device. Voltage on MCLR/VPP must not exceed VDD during normal device operation. RA6/OSC2/CLKOUT RA6 Bi-directional I/O port OSC2 XTAL Oscillator crystal output. Connects to crystal or resonator in Crystal Oscillator mode. CLKOUT In ER/INTRC mode, OSC2 pin can output CLKOUT, which has /4 thefrequency of OSC RA7/OSC/CLKIN RA7 Bi-directional I/O port OSC XTAL Oscillator crystal input CLKIN External clock source input. ER biasing pin. RB/INT RB Bi-directional I/O port. INT External interrupt. RB/RX/DT RB Bi-directional I/O port. RX USART receive pin DT Synchronous data I/O. RB2/TX/CK RB2 Bi-directional I/O port. TX USART transmit pin CK Synchronous clock I/O. RB3/CCP RB3 Bi-directional I/O port. CCP Capture/Compare/PWM I/O RB4/PGM RB4 Bi-directional I/O port. PGM Low voltage programming input pin. RB5 RB5 Bi-directional I/O port. RB6/TOSO/TCKI/PGC RB6 Bi-directional I/O port. TOSO XTAL Timer oscillator output. TCKI ST Timer clock input. PGC ST ICSP Programming Clock. RB7/TOSI/PGD RB7 Bi-directional I/O port. TOSI XTAL Timer oscillator input. Wake-up from SLEEP on pin change. PGD ST CMOS ICSP Data I/O Page 6

Block Diagram MCU 2 / page 7 Block diagram The PIC6F62X devices contain an 8-bit ALU and working register. The ALU is a general purpose arithmetic unit. It performs arithmetic and Boolean functions between data in the working register and any register file. Depending on the instruction executed, the ALU may affect the values of the Carry (C), Digit Carry (DC), and Zero (Z) bits in the STATUS register. The C and DC bits operate as a Borrow and Digit Borrow out bit, respectively, bit in subtraction. Two types of data memory are provided on the PIC6F62X devices. Non-volatile EEPROM data memory is provided for long term storage of data such as calibration values, lookup table data, and any other data which may require periodic updating in the field. This data is not lost when power is removed. The other data memory provided is regular RAM data memory. Regular RAM data memory is provided for temporary storage of data during normal operation. It is lost when power is removed. Page 7

Configuration Register Give the application developer flexibility in how the PIC are used in application. If register are not set correctly, PIC will not run properly. Register is written when the PIC is being programmed. Register content is accessed in PIC bootup process to select the hardware options required for application. MCU 2 / page 8 Configuration register define for: [details refer to textbook Table3-5] Code / data protection (CP / CPD) -normally set OFF Low voltage programming (LVP) -normally set disable Brown-out detect (BODEN) -normally set enable Reset parameters (MCLR) use _MCLR as reset pin Power-up timer -normally set enable Watchdog timer (WDT) -normally set disable Oscillator mode used (FOSC-2) normally set HS (high speed) For mikroc, default setting is: Oscillator mode = HS WDT = disable LVP = disable Page 8

Input/Output (I/O) Registers TRISx(where x = A or B) To control the input/output of the I/O pin Register load with, I/O pin set as input Register load with, I/O pin set as output e.g. TRISA.F = will set port A pin (i.e. RA) as input TRISB.F7 = will set port B pin 7 (i.e. RB7) as output PORTx(where x = A or B) Directly store data sending out or received from I/O pin e.g. PORTA.F = will send high to port A pin (RA) temp = PORTB.F3 will assign data received from port B pin3 (RB3) to temp MCU 2 / page 9 I/O convention for mikroc and PICC-Lite: mikroc TRISA TRISA.F PORTB PORTB.F PICC-Lite TRISA TRISA PORTB or RB PORTB. or PORTB or RB Page 9

Input/Output Registers How to make RB2 I/O pin a digital output and drive a high value? TRISB.F2 = ; // RB2 set as output pin PORTB.F2 = ; // RB2 drives a high value out How to make RA I/O pin a digital output and drive a low value? TRISA.F = ; // RA set as output pin PORTA.F = ; // RA drives a low value out How to make RA7 I/O pin a digital input and receive a data? TRIS.F = ; // RA7 set as input pin temp = PORT.F ; // Receive from RA7 and assign to temp MCU 2 / page Page

Input/Output Registers How to drive entire Port B to high values? TRISB = ; PORTB = xff; How to make RA I/O pin digital inputs and store the received data to temp? TRISA = x ; temp = ; MCU 2 / page Page

Workshop mikrocstartup and burn PIC LED flashing void main() { PORTB = ; TRISB = ; while() { PORTB = ~PORTB; Delay_ms(); MCU 2 / page 2 Page 2

Workshop 2 -PIC input and output void main() { PORTB = ; TRISB = ; CMCON = x7; /* enable digital I/O for PORTA */ TRISA.F = ; /* set RA as input */ while() { if (PORTA.F) PORTB = xff; else PORTB = ; Delay_ms(); /* set ms delay */ MCU 2 / page 3 Page 3

Page 4 Hong Kong Institute of Vocational Education Hong Kong Institute of Vocational Education MCU 2 / page 4 7-segment LED display 8 e 4 48 98 c 24 9e 2 value 9 8 7 6 5 4 3 2 dp g f e d c b a Char

Workshop 3 -PIC output to 7-segment display void main() { PORTB = ; TRISB = ; while() { PORTB = x2; /**/ Delay_ms(); PORTB = x9e; /**/ Delay_ms(); PORTB = x24; /*2*/ Delay_ms(); PORTB = xc; /*3*/ Delay_ms(); PORTB = x98; /*4*/ Delay_ms(); PORTB = x48; /*5*/ Delay_ms(); PORTB = x4; /*6*/ Delay_ms(); PORTB = xe; /*7*/ Delay_ms(); PORTB = x; /*8*/ Delay_ms(); PORTB = x8; /*9*/ Delay_ms(); MCU 2 / page 5 Page 5

Workshop 4 -PIC interactive I/O void main() { int seg7[] = {x2, x9e, x24, xc, x98, x48, x4, xe, x, x8; /* to 9*/ int index = ; /* for store the current display digit */ PORTB = seg7[]; TRISB = ; CMCON = x7; /* enable digital I/O for PORTA */ TRISA.F = ; TRISA.F = ; while () { if (PORTA.F = = ) /* when RA is pressed */ { index = index + ; if (index == ) index = ; PORTB = seg7[index]; Delay_ms(); MCU 2 / page 6 Page 6

Workshop 5 -PIC input decode void main() { int seg7[] = {x2, x9e, x24, xc, x98, x48, x4, xe, x, x8; /* to 9*/ int index = ; /* for store the current display digit */ PORTB = seg7[]; TRISB = ; CMCON = x7; /* enable digital I/O for PORTA */ TRISA.F = ; /* set all 4 inputs for PORTA */ TRISA.F = ; TRISA.F2 = ; TRISA.F3 = ; while () { index = ; if (PORTA.F == ) index = index + ; /* calculate weighting */ if (PORTA.F == ) index = index + 2; if (PORTA.F2 == ) index = index + 4; if (PORTA.F3 == ) index = index + 8; if (index > 9) /* Display to 9 */ index = ; PORTB = seg7[index]; Delay_ms(); MCU 2 / page 7 Page 7

Music Frequency Tone do re me fa so la ti Frequency 46.5 74.7 38.5 396.9 568 76 975.5 Period / 2 478 426 379 358 39 284 253 MCU 2 / page 8 Page 8

Workshop 6 -PIC output to speaker void main() { int i; PORTB = xff; TRISB = ; CMCON = x7; /* enable digital I/O for PORTA */ TRISA.F = ; TRISA.F = ; TRISA.F2 = ; TRISA.F3 = ; while () { if (PORTA.F == ) { for (i=; i<5; i++) { PORTB.F = ; Delay_us(478); /* do */ PORTB.F = ; Delay_us(478); MCU 2 / page 9 Page 9

Interrupt setting void main() { TRISB = x; /* RB as interrupt */ INTCON.GIE = ; /* enable global interrupt */ INTCON.INTE = ; /* enable RB/INT pin interrupt */ while() { void interrupt () { INTCON.INTE = ; /* disable interrupt avoid interrupt again */ if (INTCON.INTF) { /* check interrupt from RB */ INTCON.INTF = ; /* reset interrupt flag */ INTCON.INTE = ; /* enable interrupt again */ MCU 2 / page 2 Page 2

Workshop 7 -PIC interrupt void interrupt () { int i, j; INTCON.INTE = ; if (INTCON.INTF) { PORTB = x55; Delay_ms(); PORTB = xaa; Delay_ms(); PORTB = x55; Delay_ms(); PORTB = xaa; Delay_ms(); INTCON.INTF = ; /* reset interrupt flag */ PORTB = ; /* reset pattern */ INTCON.INTE = ; void main() { PORTB = ; TRISB = x; /* RB as interrupt */ INTCON.GIE = ; /* enable global interrupt */ INTCON.INTE = ; /* enable RB/INT pin interrupt */ while() { PORTB = ~PORTB; Delay_ms(); MCU 2 / page 2 Page 2

Baud Rate Generator In Asynchronous mode bit Baud Rate Generator controls the baud rate. Given the desired baud rate and Fosc, the nearest integer value for the SPBRG register can be calculated using the following formula: When BRGH =, SYNC =, Desired Baud rate = Fosc/ (64 (X + )) Fosc= 6 MHz, Desired Baud Rate = 96 96 = 6 / (64(X+ )) X = 25.42 Calculated Baud Rate = 6 / (64(25 + )) = 965 Error = (Calculated Baud Rate -Desired Baud Rate) / Desired Baud Rate = (965-96)/ 96 =.6% MCU 2 / page 22 Page 22

Workshop 8 -Serial Comm. void main() { unsigned char temp; OPTION_REG = xd; /* assign prescalar to TMR */ TMR = ; /* reset timer for start */ INTCON.TIE = ; /* enable timer interrupt */ INTCON.GIE = ; /* enable global interrupt */ SPBRG = 2; /* 5 : baud rate = 2 @ 4MHz */ /* 2 : baud rate = 48 */ TXSTA.TXEN = ; /* enable usart */ RCSTA.CREN = ; /* enable continuous receive*/ RCSTA.SPEN = ; /* serial port enable */ PIR.RCIF = ; /* clear receive flag */ while () { if (PIR.RCIF) { /* wait char received */ temp = RCREG; /* get char */ TXREG = temp -; /* modify char */ PIR.RCIF = ; /* clear flag */ MCU 2 / page 23 Page 23

L293 Motor Driver MCU 2 / page 24 Page 24

Workshop 9 -Motor control void main() { PORTB = ; TRISB.F5 = ; /* motor enable */ TRISB.F6 = ; /* motor direction */ TRISB.F7 = ; /* RB6, RB7 =, or, = no motion */ /*, one direction */ /*, other direction */ CMCON = x7; /* enable digital I/O for PORTA */ TRISA.F = ; TRISA.F = ; PORTB.F5 = ; /* enable motor */ while () { if (PORTA.F == ) { /* RA press */ PORTB.F6 = ; PORTB.F7 = ; Delay_ms(); if (PORTA.F == ) { /* RA press */ PORTB.F6 = ; PORTB.F7 = ; Delay_ms(); PORTB.F6 = ; PORTB.F7 = ; MCU 2 / page 25 Page 25