Simple Microcontroller Programming with PIC16F88.

Slides:



Advertisements
Similar presentations
MICROPROCESSORS AND MICROCONTROLLERS
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Microprocessors Typical microprocessor controlled devices: Camera, mobile phone, stereo, mp3 player, electronic toys… High-level microprocessor controlled.
Lab7: Introduction to Arduino
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
How to use Arduino By: Andrew Hoffmaster.
EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
Vex Robotics Introduction to Sensors. introduction to sensors Sensors assist robots in seeing and feeling the physical world through which they travel.
Basic Stamp II is kinda cool Bytes of EEPROM(non-volatile) - Clock speed of 20 MHz. - Holds 600 lines of code in EEPROM - executes an average of.
Introduction to Microprocessors Number Systems and Conversions No /6/00 Chapter 1: Introduction to 68HC11 The 68HC11 Microcontroller.
Railway Foundation Electronic, Electrical and Processor Engineering.
Railway Foundation Electronic, Electrical and Processor Engineering.
PROGRAMMABLE INTERFACE CONTROLLERS Understanding what PIC’s are. How to use PIC logicator Knowing what you can do with PIC circuits.
Introduction.
 Main Components:  Sensors  Micro controller  Motor drivers  Chasis.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Dr. Hoganson CSIS HC11 Demo Program This is our first lab using the 68HC11 microcontroller. We will “talk” to the microcontroller from a PC, run.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Embedded Programming and Robotics
LSU 06/04/2007BASIC Stamp Editor1 The BASIC Stamp Editor Programming Unit, Lecture 3.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
PICS / Microcontrollers
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Colorado Space Grant Consortium Gateway To Space ASEN 1400 / ASTR 2500 Class #12 Gateway To Space ASEN 1400 / ASTR 2500 Class #12 T-58.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Chapter Introduction to Computers and Programming 1.
Applied Control Systems Technology. © t 4 Galway Education Centre 2 Applied Control Systems Inputs Push switches L.D.R. Microphone Tilt switch Infrared.
1 Applied Control Systems Technology. 2 Pin configuration Applied Control Systems.
Introduction to Computing: Lecture 4
© AJH 2013, V2.0 Computer Programming Embedded Systems Programming Stand-alone code, system initialisation, operating systems. Low-level operations; port.
COMPUTER SYSTEM ARCHITECTURE By Sohaib.  The digital computer is a digital system that performs various computational tasks.  The word digital implies.
MICRO CONTROLLER MODULE 1. Learning Objectives Name some gadgets that use microcontrollers. Define a microcontroller. Differentiate between a computer.
MOBILE OPERATING ROBOT ON EMBEDDED SYSTEM
Digital Electronics Board-of-Education : Input. Board of Education - Input This presentation will explain, both from a hardware and software perspective,
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
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.
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
Microcontrollers, Microcomputers, and Microprocessors
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Department of Electronic & Electrical Engineering Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Submitted by:.  Project overview  Block diagram  Power supply  Microcontroller  MAX232 & DB9 Connector  Relay  Relay driver  Software requirements.
MICROCONTROLLER INTERFACING WITH STEPPER MOTOR MADE BY: Pruthvirajsinh Jadeja ( ) COLLEGE:DIET BRANCH:EC.
PROJECT ON FAULT ANALYSIS AND DETECTION GUIDED BY:: SUBMITTED BY:- MS. SHUBRA GOEL.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
BATCH MEMBERS R.ABHISHEK-08N41A0401 K.DHEERAJ REDDY-08N41A0412 S.RAJENDRA REDDY-08N41A0458 JYOTHISHMATHI COLLEGE OF ENGINEERING AND TECHNOLOGY,TURKAPALLY.
Introduction to Microcontroller Technology
Arduino.
INTRODUCTION TO ROBOTICS Part 5: Programming
Programming and Debugging with the Dragon and JTAG
Fundamentals of Computer Engineering
Arduino Based Industrial appliances control system by decoding dual tone multi frequency signals on GSM / CDMA network. Submitted by:
The first change to your project files that is needed is to change the device to the correct FPGA. This is done by going to the Assignments tab on the.
Microcontroller basics
Arduino & its hardware interfacing
SCADA for Remote Industrial Plant
Microcontroller Applications
PC Mouse operated Electrical Load Control Using VB Application
DIGITAL CALCULATOR USING 8051
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
fischertechnik® RoboPro Software for Gateway To Technology® RoboPro
Introduction to Microprocessors and Microcontrollers
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
ECE 3567 Microcontroller Lab
Presentation transcript:

Simple Microcontroller Programming with PIC16F88. ECE 3102/ ECE 4102 International Islamic University Malaysia

ABOUT MICROCONTROLLER

Microcontroller in Common Modern Appliances Microcontrollers typically have the same functions like Computer yet it is much smaller and cheaper. It can be used in everyday appliances such as washing machine, modern car, mobile robot and home appliances. Microcontroller: mini size 4cm x 2 cm or smaller. Computer: big size Microcontroller also consumes less energy.

Some Appliances Using Microcontroller AC Rice Cooker Washing machine Auto gate Modern car Electric chair

Introduction to Microcontroller Microcontroller, also called as MCU or C, is an integrated electric circuit (IC) having some properties to perform like computer i.e: CPU (Central Processing Unit), code memory, data memory and I/O port. Its small size allows to be embedded into various home and industrial appliances, robotic applications and etc. ADC PWM Low Power High Speed Cheap Small Layout Timer/ Counter function Digital I/O RAM ROM Serial I/O

Microcontroller: Practical in Use The command/ program is written in BASIC or C and transferred into the memory of the Microcontroller via programmer or writer device. After the Microcontroller is programmed, then it is ready to use in the application. Blank Microcontroller Programmer/writer Application unit Computer

Preparation to Microcontroller Programming Software: Compiler MikroC can be downloaded freely from: http://www.mikroe.com Data transformer to Microcontroller: Winpic800. Download free from: http://www.winpic800.com Hardware: Programmer Application circuit) Programmer Example of application circuit

Programmer Circuit This Programmer uses external 5V power supply. 5volt power supply Resistor: 100 W or 56W This Programmer uses external 5V power supply.

Simple Programmer This Programmer does not use external power supply but sources the power directly from serial port. More convenient.

Simple Application Circuit The available ports can be directly connected to LED, Transistor, Buzzer, Sensor and Actuator. Oscillator (10k – 20MHz) Minimal component to drive Microcontroller: IC Microcontroller External Power supply, 5 V Fixed Frequency Oscillator The Oscillator seems to have same function as heart in our body. It is to trigger constant pulses to execute the program in Microcontroller.

Important Notice in Microcontroller Operation Microcontroller PIN location must be correct. Check properly the Socket direction by looking at PIN mark or number. Switch Off the power supply when assembling and dismantling the Microcontroller to and from the Socket. Don’t touch the Microcontroller on the PINs since our body include static electricity. The IC may be sensitive. Use pincer or small screwdriver to assist the IC removal from socket. Check the voltage of the supply for safety. Input voltage can not be more than the specified (e.g. 5volt, 9volt). 5. Work carefully during IC dismantling since the PINs of IC and socket are fragile.

Input – Output (I/O) Microcontroller I/O configuration can be seen on the Datasheet of the Microcontroller. Input of Microcontroller can be digital or analog. If digital, then 0V input for low (0) and 5V for high (1). If analog, then input range is from 0V to 5V. Output of Microcontroller is only digital; 0V for state 0 and 5V for state 1.

Port I/O Microcontroller Example: From datasheet Microcontroller PIC16F88: Pin Input Analog (AN0-AN6): 17,18,1,2,3,12,13 Pin Input Digital: PORT A (RA0-RA4): 17,18,1,2,3 PORT B (RB0-RB7): 6,7,8,9,10,11,12,13 Pin Output only digital: PORT A (RA0-RA4): 17,18,1,2,3 PORT B (RB0-RB7): 6,7,8,9,10,11,12,13 PIN can be assigned as input or output depending on the programming setting.

Digital Value of Port I/O Microcontroller

Microcontroller Kit Microcontroller Kit is designed for training in Microcontroller programming. MINI18 PIC Training Kit is used here to design, test and develop PIC microcontroller programming. This Kit consists of Programmer and Application Circuit in one unit. uses PIC16F88 microcontroller. has many applications in addition to the low price that is suitable for education and robotic competition. has 14 pin I/O and also ADC and PWM functions.

Microcontroller Kit Circuit Application circuit Programmer Circuit

PIC 16F88 Microcontroller Kit Application socket Programmer socket Programming circuit can be connected directly to serial port of PC or using extension cable. In the application circuit above, there are 2 input switches, 6 LEDs, 1 LDR sensor and 1 Buzzer Alarm.

Kit Connection to PC This is used when downloading the program from PC to PIC.

Kit Connection to PC Serial extension cable can also be used.

Transfer from Programmer to Application After the programming download is completed, The PIC can be removed from programmer socket to application socket. Be careful since the PINs are fragile. Then connect 9V supply to the terminal and switch ON test the circuit.

Basic Command in C

Statement/Comment Comment is made only to help the programmer as explanation, it will not be executed by computer. Using // for one line statement or /*.....statement........*/ for one paragraph statement or comment. Example: PORTB = 0; //Setting all values of PORTB = 0

Programming Structure For each program, it must begin with command: void main() Each command line ends with semicolon: ;

Operator Assignment operator It uses (“=”). example: input = 80; //variable “input” is equal to 80 A = x * y; //variable “A” has value of multiplicaion between x and y. Arithmatic operator * : multiplication / : division + : addition - : subtraction

Operator (contd.) Relational Operator Logic Operator < less than <= Less than or equal to > Greater than >= Greater than or equal to == Equal to != Not equal to Logic Operator && Logic AND || Logic OR ! Logic NOT

Conditions if…. and if….else In the structure if.....else the are at least two statement. If the given expression is true then statement-1 will be executed, otherwise if the given expression is false then stetement2 will be executed. It has common form as: If (condition) {…..} if(condition){statement-1} else {statement-2 } Example: if (m == 1) {x = x + 20} else {y = y – 10}; // If m=1 then the new value of x is x+20, otherwise the new value of y is y-10.

Looping Looping with do..while The looping process will continue if the given condition is true otherwise looping will be stopped. do {statement} while (condition); Example: int s, i; s = i = 0; do { s = s + 2; i = i + 1; } while (i < 7); //This will add value of variable s by 2 in 7 times; at the end the value of s will be 14.

PIN and PORT Assignment Byte Mapping in PORT PORTB has 8 pins: B0, B1, B2, B3, B4, B5, B6, B7 With the order from right: PORTB = RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 For example to set only pin RB2 and RB4 to high state 1 (ON), the command is: PORTB=0b00010100; PORTB = 1

PIN and PORT Assignment PIN or PORT values can be determined per PIN or per PORT. The command below are the same: PORTB.F0 = 0; PORTB.F1 = 0; PORTB.F2 = 1; PORTB.F3 = 0; PORTB.F4 = 1; PORTB.F5 = 1; PORTB.F6 = 0; PORTB.F7 = 1; Per PIN Same as: Per PORT PORTB= 0b10110100;

Per PORT Command Per PORT command can be in decimal, binary or hexadecimal form. Bilangan Operator Example Value Binary 0b PORTB=0b00111111; Value of PORT B: B0=1, B1=1, B2=1, B3=1, B4=1, B5=1, B6=0, B7=0 Hexa-decimal 0x PORTB=0x0F ; 0F is equivalent to 00001111, that means PORT B value: B0=1, B1=1, B2=1, B3=1,B4=0,B5=0, B6=0, B7=0 Decimal PORTB =12 ; Decimal 12 is equal to 00001100 in binary, thus PORT B: B0=0,B1=0, B2=1, B3=1, B4=0,B5=0, B6=0, B7=0

Defining Input or Output PORT/PIN To assign a PORT or PIN as Input or Output, command TRIS is assigned: PORTB as output TRISB = 0 ; //same as 0b00000000 PORTB as input TRISB = 0b11111111; Only PIN B1 as output TRISB.F1 = 0; Only PIN B3 as input TRISB.F3 = 1;

Digital Input Checking To check digital input to the PIC (0V or 5 V), this command can be given: If (expression) {statement…} Example: If Port RA1 = 5V then Output of Port RB1 will be 1 (5V). If (PORTA.F1 == 1) {PORTB.F1=1} To delay the next command to be executed, the command is: Delay_ms(1000); //To delay the next command by 1s (1000 ms)

PIN Setting as Digital or Analog Command ANSEL can only be used by PIN with label AN. For example AN6 (Pin B7) will be set as analog, thus the command: ANSEL.F6=1; If let say PIN AN3 (Pin A2) is set to be digital: ANSEL.F3=0; For all PINs AN to be digital input: ANSEL=0b0000000;

ADC Activation To activate function conversion from analog to Digital (ADC), if PIN AN (Input Analog) is used. The command is ADCON0. To make the ADC function active: ADCON0 = 1; To make ADC function inactive, the command is: ADCON0 = 0;

First Project: Exercise In this first project, we will try to turn on LED with the sequence as follows: All 6 LEDs connected to PORT B (RB0 to RB5) are ON in the first 1s. In the next 1s, only LED on PORT B0, B2, B4 are ON (or Red-Green-Yellow). Then, in the next 1s after that, only LED on PORT B1, B3 and B5 are ON (Yellow-Green-Red). The process is repeated to sequence 1.

First Project: Algorithm For this project, the algorithm is as follows: Define PORT that will be used as output. Define initial value of PORT. Start the program. Set output HIGH (1) for PIN on PORT B0-B5 Delay for 1s (1000ms). Set output HIGH for PORT B0, B2, B4 only, the rest are LOW. Set output HIGH for PORT B1, B3 and B5, the others are LOW. Repeat to number 3.

First Project: Programming Programming is done using MicroC software. Click ProjectNew, then specify the name of the project and folder location.

Write the project name as “First_project” Specify the Project Path to save the files. Discription, we can leave it as blank (optional). Select Device, select PIC16F88. In Clock, write 20.000000 (20 MHz). Click default to use default settings. Then click OK. Then, MikroC compiler will prepare the project file and displays the window editor to write the source code program.

/* Name: First_project written in C Connection: LED B0-Red, B1-Yel, B2-Gre, B3-Red, B4-Yel, B5-Gre B6_SW1, B7-SW2 A1=Buzzer, A0=LDR */ void main() { PORTB = 0; //Initial setting PORTB=0 TRISB = 0; //Set PORTB as Output do PORTB = 0b00111111; //output PORTB in binary 00111111 Delay_ms(1000); PORTB = 0b00101010; //output PORTB in binary 00101010 PORTB = 0b00010101; // output PORTB in binary 00010101 } while(1) ;

Command Definition Command Explanation void main() To begin the main program {or } The bracket is used only to identify command into the blocks. To make the program easy to undertand. // or /*…..*/ Comment that will not be executed by computer. // is for one line statement. /* in the beginning of paragraph and */ in the end of paragraph. PORTB = 0b00000000; TRISB = 0b00000000; Set initial value PORTB=0. Set PORTB as Output. Example: TRISB = 0x00 is also to set PORT B as output and TRISB = 0b11111111 is to set PORT B as input. Partly input and output can also be set, for example: TRISA= 0b00001111 means PORTA pin A0,A1,A2,A3 as input (since set to 1) and pin A4,A5,A6,A7 as output (since set to 0).

Command Definition (contd.) do… while(1); To set the loop without ending. While (1) if the condition is TRUE or 1, then repeat to do again. PORTB = 0b00111111; On PORTB the output is given as: B0=1,B1=1,B2=1,B3=1,B4=1,B5=1, B6=0, B7=0. (bit sequence from right) Delay_ms(1000); To pause the next exceution by 1000ms or 1s.

Program Compiling After the program is wriiten in the editor, then save the file. Then click Compile Icon or build project. It takes a while for MikroC to compile the program, a .hex file will be crated. This .hex file will be transferred into the Microcontroller.

Transferring Hex File to PIC To transfer or download the .hex file to PIC, firstly open WinPIC800 software. Then plug the PIC Kit board into Serial Port/COM1 in the PC. The PIC must be connected to Programmer circuit to download .hex file. Select PIC 16F88 in pull down as shown by figure. Then click to check the serial port connection of the PIC board to the PC.

Then click icon “erase all” to delete all previous program existing in the PIC. Then click open file icon to select .hex file that will be downloaded to the PIC. Then click to transfer the hex file of your project to PIC.

After the hex file has been transferred, then unplug the PIC board from the serial port of the PC. And remove the IC to application circuit. Connect 9v supply to the terminal and press switch ON. We can see the LEDs are ON according to the programmed sequence.