PIC Microcontroller Programing using MikroC

Similar documents
Real-Time Application Surveillance Security System Based on LabVIEW

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

INTERRUPTS. There are 2 methods for communicating between the microcontroller and the external system: POLLING INTERRUPTS

Using The PIC I/O Ports

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

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

1/22/16. You Tube Video. Definitions. Duty Cycle: on-time per period (specified in per cent)

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Timer A (0 and 1) and PWM EE3376

Keil C51 Cross Compiler

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

Chapter 13. PIC Family Microcontroller

Lesson-16: Real time clock DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK

HANDLING SUSPEND MODE ON A USB MOUSE

Section 29. Real-Time Clock and Calendar (RTCC)

AN601 I2C 2.8 Communication Protocol. SM130 SM130 - Mini APPLICATION NOTE

Microprocessor & Assembly Language

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

RS-485 Protocol Manual

Programming A PLC. Standard Instructions

Microtronics technologies Mobile:

Section 14. Compare/Capture/PWM (CCP)

CSE2102 Digital Design II - Topics CSE Digital Design II

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Serial Communications

Software Manual RS232 Laser Merge Module. Document # SU Rev A

DS1104 R&D Controller Board

Monitoring of Intravenous Drip Rate

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

Technical Training Module ( 30 Days)

Key Words Student Paper, School of Professional Studies

STEPPER MOTOR SPEED AND POSITION CONTROL

Freescale Semiconductor, I

Accurate Measurement of the Mains Electricity Frequency

Traditional IBM Mainframe Operating Principles

2.0 Command and Data Handling Subsystem

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

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

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

Lecture N -1- PHYS Microcontrollers

An Introduction to MPLAB Integrated Development Environment

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

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

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

A Practical Approach to Education of Embedded Systems Engineering

THE TRANSITION FROM THE 8085 TO THE MODERN WORLD

Small Hardware Development and Prototyping Board for the SX28

PIC Programming in Assembly. (

Computer and Set of Robots

Microcontrollers in Practice

EMBEDDED SYSTEM BASICS AND APPLICATION

Section 9. I/O Ports

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

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

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

Invisible EYE for Security System

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

AN4646 Application note

eztcp Technical Document Modbus/TCP of eztcp Caution: Specifications of this document may be changed without prior notice for improvement.

Embedded Component Based Programming with DAVE 3

Process Visualization of a Manufacturing Plant Based On Lean Concept

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

Exception and Interrupt Handling in ARM

PCAN-MicroMod Universal I/O Module with CAN Interface. User Manual. Document version ( )

Building Blocks for PRU Development

3. Identification of water pumps through RFID technology. 4. Wireless control of remote water pump using RF technology.

Application Note: Using the Motor Driver on the 3pi Robot and Orangutan Robot Controllers

C Programming Structure of a C18 Program

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Measuring Resistance Using Digital I/O

Building A RISC Microcontroller in an FPGA

PICmicro tm Development Board

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

Ultrasonic Distance Measurement Module

LADDER LOGIC/ FLOWCHART PROGRAMMING DIFFERENCES AND EXAMPLES

Lab Experiment 1: The LPC 2148 Education Board

PIC Lab Manual. PIC Lab Manual. 1 Include CD-ROM 2010/2011

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

Soft processors for microcontroller programming education

Welcome to the Introduction to Controller Area Network web seminar My name is William Stuart, and I am a Applications Engineer for the Automotive

Palaparthi.Jagadeesh Chand. Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P.

How to Interface a Microchip PIC MCU with a hobby R/C Servo

MICROPROCESSOR AND MICROCOMPUTER BASICS

Automatic Miniblinds System. San Jose State University. Department of Mechanical and Aerospace Engineering. Brian Silva Jonathan Thein

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

Advanced Car Security System Using GSM

8051 MICROCONTROLLER COURSE

Open Architecture Design for GPS Applications Yves Théroux, BAE Systems Canada

How to design and implement firmware for embedded systems

Application Note AN-1187

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

The goal is to program the PLC and HMI to count with the following behaviors:

Transcription:

PIC Microcontroller Programing using MikroC Mr. Charith Sucharitharathna Department of Electronic and Computer Engineering Sri Lanka Institute of Information Technology

What is a microcontroller? uhsfl%dlkafg%da,rhla hkq ixhqla; ;ksj l%shdl< yels mß.klhla jeks fohls' iïmq¾k fm%dfiirhls' u;lh yd Input/Output w;+re uqyqk;a tlg tlaj mj;sk WmlrKhls'

Computer Architecture

PIC16f877A Architecture

PIC fhdod.eksug fya;+.. tys we;s ir,;dj úodk,ndosfï myiqj wfkl+;a uhsfl%dlkafg%da,r iu. iei SfïoS tys we;s,dnodhsnj. nyq, jyfhka fmd;m; yd wjyh f;dr;+re,nd.eksfï yelshdj. wvq n,yla;s mßfndackh. f;dard.eksï rdyshla iys;ùu.

fm%da.%ï lsífïos ie,lshhq;+ uq,sl lrekq.. uhsfl%dlkafg%da,rhla fm%da.%ï lsífïos ie,lsh hq;+ lrekq fudkjdo@

uhsfl%dlkafg%da,rhla fm%da.%ï lsífïos uq,sl jyfhka ;sìh hq;+ foaj,a fudkjdo''' IDE and Compiler Microcontr oller Programmer

PIC Programming Programmer Compiler

Packages of PIC Microcontrollers

Packages of PIC Microcontrollers

PIC 16F877A (DIP Package)

PIC16F8xxx

uq,sl Input/Output w;+re uqyqk;a PIC16F877A uhsfl%dlkafg%da,rh fodrgq mylska iukaú;fõ (PORT A,B,C,D,E ) fodrgqj, osydj ;SrKh lr.eksug TRIS kue;s frðiagrh Ndú;d lsíug is fõ' 1 Ndú;fhka Input fodrgqjla f,io, 0 Ndú;fhka Output fodrgqjla f,io ilid.; yel'

Binary / Decimal/ Hexa-Decimal Number Systems

Basic C Program to drive LEDs using PORTD void main() { } TRISD = 0x00; PORTD = 0x00; while(1) { } PORTD = 1; Delay_ms(100); PORTD = 2; Delay_ms(100); PORTD = 4; Delay_ms(100); PORTD = 8; Delay_ms(100); PORTD = 16; Delay_ms(100); PORTD = 32; Delay_ms(100); PORTD = 64; Delay_ms(100); PORTD = 128; Delay_ms(100); // PORTD is output //initialize PORTD //move 1 to port D //wait for few seconds

Exercise wdf,dal ú,s ix{d iys; ld¾hnyq, ud¾.hla yryd.uka lrk frdfndahka;%hlg.e,sï igykla w kak'

A flow chart showing the robot how to cross the road

Interrupts In real-time systems, there could be events that require immediate (within a specified delay) action from the CPU. The vast majority of MPU/MCUs have the capability to deal with a range of such events. In the case of a microcontroller, requests for service may come from an internal peripheral device, such as a timer overflowing, or the completion of an analog to digital conversion, or from a source entirely external to the device in the outside world. At the very least, on reset (a type of external hardware event) the MCU must be able to get (vector) to the first instruction of the main program. In the same manner an external service request or interrupt when answered must lead to the start of the special subroutine known as an interrupt service routine

Interrupt Controlling Polling. Is some mechanism which will keep on checking for some thing. This is the simplest way of checking for some thing. Resource consumption is high. Processor is always busy. There are chances to miss some events.

Interrupt Controlling.. cont Interrupt Once event get occurred only it will notify to relevant handling party. wvq iïm;a mßfndackh. md,kh lsífï wmyiqnj. isoaëka i yd uq,sl;ajh osfï l%shdms<sfj;la ks¾udkh lsífï yelshdj'

Interrupt md,kh lrk wdldrh void main() { INTCON.GIE = 1; INTCON.INTE = 1; //Enable general interrupts //Enable RB0 Interrupt OPTION_REG.INTEDG = 0; //Set Edge triggering } while(1) { } void interrupt() { if (INTCON.INTF) { PORTD = 0xff; Delay_ms(200); INTCON.INTF = 0; } }

Rising Edge/ Falling Edge

Multiple Interrupts Each of these sources can set an associated interrupt flag bit. In the cases where more than one source of interrupt requests are enabled, these flags can be monitored by software by polling to check the origin of the requests. Although a flag is set by an external event, it can be cleared in software. It is recommended that you clear it in the interrupt service routine.

void interrupt() { if(intf) go to relevant sub rooting else if (RBIF) go to relevant sub rooting }

Time to think fj< ie,lg we;+,ajk.kqfokqlrejka m%udkh.eksu i yd.kl hka;%hla ks¾udkh lrkak' l+uk wdldrfha Interrupts Ndú;dl, hq;+o@ l+uk wdldrfha ixfõol Ndú;dl, hq;+o@

PWM (Pulse Width Modulation)

PWM Ndú;d lrk wdldrhka void main() { TRISC = 0x01; Pwm_Init(5000); // PORTC is output //initialize PWM Pwm_Change_Duty(255); Pwm_Start(); Delay_ms(200); //Change duty Cycle Pwm_Change_Duty(191); Pwm_Start(); Delay_ms(200); Pwm_Change_Duty(127); Pwm_Start(); Delay_ms(200); Pwm_Change_Duty(64); Pwm_Start(); Delay_ms(200); }

Motor Control Use L293D motor control circuit.

Motor Control void main() { TRISD = 0x00; while(1) { PORTD = 0b00000101; Delay_ms(1000); PORTD = 0b00000001; Delay_ms(500); PORTD = 0b00000100; Delay_ms(500); PORTD = 0b00000101; Delay_ms(1000); } }

Mechatronic