Lecture (04) PIC 16F84A programming I

Similar documents
Lecture (03) PIC16F84 (2)

PIC 16F84A programming (II)

DERTS Design Requirements (1): Microcontroller Architecture & Programming

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

Lecture (02) PIC16F84 (I)

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

Model Answer Microcontrollers. MCQ Problems Total Q1 Q2

Q1 Q2 Q3 Q4 Q5 Q6 Total /7.5 /5 /10 /5 /7.5 /5 /40

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

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

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

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

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

Laboratory 10. Programming a PIC Microcontroller - Part II

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

EE 361L Digital Systems and Computer Design Laboratory

EasyPIC5 Development System

Microcontroller Overview

Input/Output Ports and Interfacing

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

ME 515 Mechatronics. A microprocessor

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

PIC Microcontroller Introduction

Lecture (04) PIC16F84A (3)

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

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

Laboratory 9. Programming a PIC Microcontroller - Part I

ELCT708 MicroLab Session #1 Introduction to Embedded Systems and Microcontrollers. Eng. Salma Hesham

MicroProcessor. MicroProcessor. MicroProcessor. MicroProcessor

The University of Texas at Arlington Lecture 5

CHAPTER 1. Introduction to Microcontrollers. Introduction

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

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

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

DEV-1 HamStack Development Board

Breeze Board. Type A. User Manual.

Chapter 2 Sections 1 8 Dr. Iyad Jafar

ME 6405 Introduction to Mechatronics

Laboratory Exercise 7 - Extended I/O & Parallel Processing

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

PIC 28 Pin Board Documentation. Update Version 5.0

Section 30. In-Circuit Serial Programming (ICSP )

AKKON USB CONTROLLER BOARD

Laboratory: Introduction to Mechatronics

Lecture (01) Introducing Embedded Systems and the Microcontrollers By: Dr. Ahmed ElShafee

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

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

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Storage Card Interface Kit

PIC KIT 2 BASIC-USERS GUIDE FEMTO ELECTRONICS

KPIC-0818P (V050919) Devices Included in this Data sheet: KPIC-0818P

8051 Microcontroller

Flow Charts and Assembler Programs

SH69P48A EVB. Application Notes for SH69P48A EVB SH69V48A JP2 J4(ICE_J4) S1 IDD TEST JP1 74HC273 JP4 JP3 74HC273 JP6 STKOVE JP7 SW1 J5(ICE_J5)

CONNECT TO THE PIC. A Simple Development Board

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

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

The Freescale MC908JL16 Microcontroller

Breeze Board. Type B. User Manual.

ECE 372 Microcontroller Design

CHAPTER 1 MICROCOMPUTER SYSTEMS. 1.1 Introduction. 1.2 Microcontroller Evolution

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Renesas 78K/78K0R/RL78 Family In-Circuit Emulation

HI-TIDE Release Notes for Version 3.13

SH69P55A EVB. Application Note for SH69P55A EVB SH69P55A EVB SH69V55A

University of Dayton. Electrical & Computer Engineering. ECE 536 Microprocessor Applications. Dr. Ralph Barrera. Assignment (4)

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

3. The MC6802 MICROPROCESSOR

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)

SH69P25/P23/P20B EVB. Application Note for SH69P25/P23/P20B EVB SH69P25/P23/P20B EVB SH69V25

UNCA CSCI 255 Exam 3 Fall 2011

DESIGN AND FABRICATION OF FARE METER OF TAXICAB USING MICROCONTROLLER

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

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

NTE1731 Integrated Circuit CMOS 10 Number Pulse Dialer

Display Real Time Clock (RTC) On LCD. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

SX Device In-System Programming Specifications

PC3 PC4 PC5 PC6 PC7 VSS VPP1 PB0 PB1 PB2 PB3 PB4 PB5

PIC Discussion. By Eng. Tamar Jomaa

Part B Questions. Unit I

Embedded System Design

Getting acquainted with the development tools June 27, 2006 ELE492 Embedded System Design Exercise 1

CLCD1 Serial 1 wire RS232 LCD development board

SECURE DIGITAL ACCESS SYSTEM USING IBUTTON

The FED PIC Flex 2 Development Boards

Chapter 11: Interrupt On Change

A PIC-based LCD Display for Stand-Alone Instrumentation

MICROPROCESSORS A (17.383) Fall Lecture Outline

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

1/Build a Mintronics: MintDuino

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

LCD. Configuration and Programming

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

Team 8: Robert Blake Craig Goliber Alanna Ocampo

EXAMINATION PAPER EMBEDDED SYSTEMS 6EJ005

Bolt 18F2550 System Hardware Manual

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

EEE111A/B Microprocessors

Transcription:

Lecture (04) PIC 16F84A programming I Dr. Ahmed M. ElShafee ١ Agenda Introduction to PIC16F84A programming using C language Preprocessors and, Compiler directives Constants Variables and data types Pointers Variables assignments Arithmetic operations Relational operations Logic operations Bitwise operations Conditions ٢

Loops Embedding assembly Arrays Functions Examples ٣ Introduction to 16F84 PIC16F84 belongs to a class of 8-bit microcontrollers of RISC architecture. Program memory (FLASH)- for storing a written program. can be programmed and cleared more than once. EEPROM - data memory that needs to be saved when there is no supply. ٤

RAM - data memory used by a program during its execution. In RAM are stored all inter-results or temporary data during run-time. PORTA and PORTB are physical connections between the microcontroller and the outside world. Port A has five, and port B has ٥ eight pins. FREE-RUN TIMER is an 8-bit register inside a microcontroller that works independently of the program. On every fourth clock of the oscillator it increments its value until it reaches the maximum (255), and then it starts counting over again from zero. As we know the exact timing between each two increments of the timer contents, timer can be used for measuring time. CENTRAL PROCESSING UNIT has a role of connective element between other blocks in the microcontroller. It coordinates the work of other blocks and executes the user program. ٦

Clock / instruction cycle Clock from the oscillator enters a microcontroller via OSC1 pin where internal circuit of a microcontroller divides the clock into four even clocks Q1, Q2, Q3, and Q4 which do not overlap ٧ These four clocks make up one instruction cycle (also called machine cycle) during which one instruction is executed Q1 : fetching current instruction according to PC (program counter) Q2: encoding current instruction Q3 executing the previous instruction (which saved in instruction register from previous cycle) Q4 writing current instruction to instruction register ٨

If instruction causes a change on program counter, and PC doesn't point to the following but to some other address two cycles are needed for executing the correct instruction in the new locatop This is so because instruction must be processed again, but this time from the right address. ٩ Pin description PIC16F84 has a total of 18 pins (DIP18 ) (Dual In Package) or (SMD 18) (Surface Mount Devices). Pin no.1 RA2 Second pin on port A. Has no additional function Pin no.2 RA3 Third pin on port A. Has no additional function. Pin no.3 RA4 Fourth pin on port A. TOCK1 which functions as a timer is also found on this pin Pin no.4 MCLR Reset input and Vpp programming voltage of a microcontroller Pin no.5 Vss Ground of power supply. Pin no.6 RB0 Zero pin on port B. Interrupt input is an additional function. ١٠

Pin no.7 RB1 First pin on port B. No additional function. Pin no.8 RB2 Second pin on port B. No additional function. Pin no.9 RB3 Third pin on port B. No additional function. Pin no.10 RB4 Fourth pin on port B. No additional function. Pin no.11 RB5 Fifth pin on port B. No additional function. Pin no.12 RB6 Sixth pin on port B. 'Clock' line in program mode. Pin no.13 RB7 Seventh pin on port B. 'Data' line in program mode. Pin no.14 Vdd Positive power supply pole. Pin no.15 OSC2 Pin assigned for connecting with an oscillator Pin no.16 OSC1 Pin assigned for connecting with an oscillator Pin no.17 RA2 Second pin on port A. No additional function Pin no.18 RA1 First pin on port A. No additional function. ١١ XT Oscillator Crystal oscillator is kept in metal housing with two pins, the operating frequency is written on housing. A 33pf ceramic capacitors are connected to gnd. Oscillator and capacitors can be packed in joint case with three pins, called ceramic resonator ١٢

Reset Reset is used when microcontroller doesn't behave the way we want it to, interrupt in program execution, to get a microcontroller ready when loading a program. MCLR has to be connected via resistor to the positive supply pole, to prevent from bringing a logical zero to MCLR pin ١٣ Ports refers to a group of pins on a microcontroller which can be accessed simultaneously, or on which we can set the desired combination of zeros and ones, or read from them an existing status. Physically, port is a register inside a microcontroller which is connected by wires to the pins of a microcontroller. some pins have twofold roles like PA4/TOCKI, fourth bit of port A and an external input for free-run counter. ١٤

Selection of one of these two pin functions is done in one of the configuration registers In order to define a pin as input or output pin, the right combination of zeros and ones must be written in TRIS register. logical "1", then that pin is an input pin logical 0", then that pin is an output pin port A has TRISA, and port B has TRISB Pin direction can be changed during your program PORTA and PORTB state registers are located in bank 0, while TRISA and TRISB pin direction registers are located in bank 1 ١٥ PORTB and TRISB Setting a bit in TRISB register defines the corresponding port pin as input, and resetting a bit in TRISB register defines the corresponding port pin as output. ١٦

Each PORTB pin has a weak internal pull-up resistor (resistor which defines a line to logic one) These 'pull-up' resistors are automatically being turned off when port pin is configured as an output. When a microcontroller is started, pull-ups are disabled. ١٧ PORTA and TRISA PORTA has 5 adjoining pins. The corresponding register for data direction is TRISA Note: RA4 can be input only ١٨

Writing a specialized program in a PC called compiler is in charge of compiling program into machine language. Unlike assembly compilers, these create an executable code which is not always the ١٩ shortest possible. Here is an example of a simple program written in C language: ٢٠

the higher programming languages, such as C, are concerned because somebody has already solved this and many other similar problems for you. It will do to ٢١ write a*b. The main idea of writing program in C language is to break a bigger problem down into several smaller pieces. To write a program for the microcontroller that is going to measure temperature and show results on an LCD display. 1. Activate and set built-in A/D converter; 2. Measure analogue value; 3. Calculate temperature; and 4. Send data in the proper form to LCD ٢٢ display

Creating project ٢٣ ٢٤

٢٥ ٢٦

٢٧ ٢٨

٢٩ ٣٠

٣١ ٣٢

LedFlasher #include <xc.h> #include <pic16f84a.h> int main(void) { TRISB=0x00; while(1) { } } PORTB=0xff; _delay(10); PORTB=0x00; _delay(10); return (0); ٣٣ Working with simulator ٣٤

٣٥ ٣٦

٣٧ ٣٨

٣٩ ٤٠

٤١ ٤٢

٤٣ PressControllerdFlasher #include <xc.h> #include <pic16f84a.h> int main(void) { TRISB=0x00; TRISA=0xff; while(1) { if(ra0==1) { PORTB=0xff; _delay(10); PORTB=0x00; _delay(10); } ٤٤

else { } PORTB=0x00; } } return (0); ٤٥ PressControlledLedStatusToogle #include <xc.h> #include <pic16f84a.h> int main(void) { int led_status=0; TRISB=0x00; TRISA=0xff; Assignment PORTB=0x00; while(1) { if(ra0==1) { _delay(10); if(led_status==0){led_status=1;} else if(led_status==1){led_status=0;} } ٤٦

if(led_status==0) PORTB=0x00; else if(led_status==1) PORTB=0xff; _delay(1000); } Assignment return (0); } ٤٧ Fara7BentEl3omdah #include <xc.h> #include <pic16f84a.h> int main(void) { TRISB=0x00; while(1) { _delay(10); PORTB=0x00; RB0=1; _delay(10); RB0=0; RB1=1; _delay(10); RB1=0; RB2=1; _delay(10); RB2=0; RB3=1; } return (0); } ٤٨

Thanks,.. See you next week (ISA), ٤٩