Introduction to Projects using Microcontroller Md. Khalilur Rhaman Credit: Interface Lab.

Slides:



Advertisements
Similar presentations
I/O Interfacing and Programming
Advertisements

EMS1EP Lecture 6 Digital Inputs
Lab7: Introduction to Arduino
Chung-Ta King National Tsing Hua University
C HAPTER 2 PIC 16F887 M ICROCONTROLLER Eng. Hazem W. Marar.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Programming the ATmega16
Learn by doing Less is more Frank Vahid (UC Riverside) Tony Givargis (UC Irvine)
Introduction.
Eejit’s guide to using a LCD alphanumeric display with the CCS C compiler 1.Hardware connection 2.The LCD.C include file 3.An example.
1 4-Integrating Peripherals in Embedded Systems (cont.)
O IL W ELL M ONITORING S YSTEM Presented By:- Louis Bengtson Kaleb Stunkard Jimit Shah.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
Team 6. Code Modules Codec Bluetooth Module Rotary Encoder Menu State Machine.
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
1 Lab 5: Controls and feedback. 2 Lab 5: Control and Feedback This embedded system uses the Photo sensor to detect the light intensity of the environment.
Instrumentation & Control Engg. Section Electrical Engineering Department Ahmedabad , Gujarat.
Franz Duran INTRODUCTION TO A RDUINO PROGRAMMING & INTERFACING Engr. Franz Duran, MEP-ECE RapidSignal Electronics.
Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs.
Engineering 1040: Mechanisms & Electric Circuits Winter 2015 Interfacing Light-Emitting Diodes (LEDs) & Push Buttons to Microcontrollers.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Warmup – 16FEB2012 This one is for practice. I have paper if you need it. Suppose there are eight, single-pole, single-throw (SPST) switches connected.
Robotics Research Laboratory Louisiana State University.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
Input Interface – Microprocessor
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
C Examples 1. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Device Overview 1.  The advantages of all PIC18Fxxxx microcontrollers:  High computational performance  High-endurance  Enhanced Flash program memory.
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 Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
PIC16F887.
ECE 447 Fall 2009 Lecture 12: TI MSP430 External LCD.
Closed Loop Temperature Control Circuit with LCD Display Mike Wooldridge ECE 4330 Embedded Systems.
Arduino DC Motor Motion Control Instructor: Dr Matthew Khin Yi Kyaw.
Atmega328p Introduction for Digital and PWM Output Brion L Fuller II Robotics Club.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
Pulse-Width Modulation: Simulating variable DC output
Interfacing of Input/Output devices with AVR Microcontroller Enrolment No. : Name of the student: SOMAIYA ISHA.
VEHICLE ACCIDENT PREVENTATION USING EYE BLINK SENSOR PRESENTED BY LAKSHMY PREMARAJAN ASHIKA K VARGHESE AKHILA S KUMAR.
Module 8 Tutorial  An 8086 system is used for controlling the speed of a motor. The motor can operate at 5 different speeds (1- 5).  The speed.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
Microprocessors A practical approach..
INTERFACING HARDWARE WITH MICROCONTROLLER GUIDED BY: Prof. ASIF SIR 1. AKSHAY KIRAN 2. DEEP PARIKH 3. JIGAR PATEL 4. TILAK PATEL ,05,D2D06,09.
VEHICLE ACCIDENT PREVENTATION USING EYE BLINK SENSOR
 Mini-Computer ◦ Microprocessor  The Brains  Arithmetic Logic Unit (ALU)  Control Unit  Program/ Data Storage  Peripherals (Input/Output)  Low-Cost.
Application Case Study Christmas Lights Controller
LCD Interfacing using Atmega 32
Microprocessor Systems Design I
4-Integrating Peripherals in Embedded Systems (cont.)
Input/Output Ports and Interfacing
Microcontroller 8951S #interface-2.
Microprocessor Systems Design I
UNIVERSAL COLLEGE OF ENGINEERING & TECHNOLOGY
GANDHINAGAR INSTITUTE OF TECHNOLOGY
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Arduino.
IoT Programming the Particle Photon.
LCD and Keyboard Sepehr Naimi
Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman
ADC and DAC Programming in AVR
Sensors and actuators Sensors Resistive sensors
8051 Micro Controller.
Supervised by : Dr. Kamel Subhi
Lab 1. Introduction to the DE2 Board
PIC16F887.  1.Microcontroller introducton  2.MPLAB,Hi-tech compilers  3.LED  4.Switches/push buttons  5.7-Segment Display  6.Keypad  7.LCD  8.Timers.
Pulse-Width Modulation: Simulating variable DC output
Buttons.
Presentation transcript:

Introduction to Projects using Microcontroller Md. Khalilur Rhaman Credit: Interface Lab

Basic Input and Output // define Switch pins for input #define SW1 RC0_bit #define SW2 RC1_bit // define Switch pin Direction #define SW1_TRIS TRISC0_bit #define SW2_TRIS TRISC1_bit // define LED pins for output #define LED1 RB7_bit #define LED2 RB5_bit #define LED3 RB6_bit // define LED pin Direction #define LED1_TRIS TRISB7_bit #define LED2_TRIS TRISB5_bit #define LED3_TRIS TRISB6_bit void main() { // make SW1 and SW2 pin as input SW1_TRIS = 1; SW2_TRIS = 1; // make LED1, LED2 and LED3 pin as output LED1_TRIS = 0; LED2_TRIS = 0; LED3_TRIS = 0; // turn off all LED LED1 = 0; LED2 = 0; LED3 = 0; if(SW1 == 0) { LED2 = 0; // lit only LED1, if SW1 pressed LED3 = 0; LED1 = 1; } else if(SW2 == 0) { LED1 = 0; // lit only LED2, if SW2 pressed LED3 = 0; LED2 = 1; } else { LED1 = 0; // lit only LED3, if no switch pressed LED2 = 0; LED3 = 1; }

Character LCD Interfacing // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections void main() { Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off // Write a Character LCD_Chr(2,1,’W’"); // Write some String LCD_Out(1,1,"Hello!"); }

DC Voltmeter void main() { char Voltage; unsigned int AdcValue; while(1) { AdcValue = ADC_Read(0); Voltage = (AdcValue * 5) / 256; Delay_ms(100); /* * Voltage contains the actual Input voltage * in AN0. Show Voltage to user using LCD */ }

PWM Capture/Compare/PWM

Code Functions: PWM(n)_Init(Frequency); PWM(n)_Set_Duty(Duty_Ratio); PWM(n)_Start(); PWM(n)_Stop(); Implementation: void main() { // Initialize PWM1 and PWM2 module at 5KHz PWM1_Init(5000); PWM2_Init(5000); // start PWM1 and PWM2 PWM1_Start(); PWM2_Start(); // Set current duty for PWM1 and PWM2 PWM1_Set_Duty(0); PWM2_Set_Duty(250); while (1) { // Set duty for PWM1 and PWM2 PWM1_Set_Duty(100); PWM2_Set_Duty(150); Delay_ms(2000); // Set duty for PWM1 and PWM2 PWM1_Set_Duty(130); PWM2_Set_Duty(120); Delay_ms(2000); // Set duty for PWM1 and PWM2 PWM1_Set_Duty(200); PWM2_Set_Duty(70); Delay_ms(2000); // Set duty for PWM1 and PWM2 PWM1_Set_Duty(250); PWM2_Set_Duty(0); Delay_ms(2000); }

Another Code while (1) { // endless loop if (RA0_bit) { // button on RA0 pressed Delay_ms(40); current_duty++; // increment current_duty PWM1_Set_Duty(current_duty); } if (RA1_bit) { // button on RA1 pressed Delay_ms(40); current_duty--; // decrement current_duty PWM1_Set_Duty(current_duty); } if (RA2_bit) { // button on RA2 pressed Delay_ms(40); current_duty1++; // increment current_duty1 PWM2_Set_Duty(current_duty1); } if (RA3_bit) { // button on RA3 pressed Delay_ms(40); current_duty1--; // decrement current_duty1 PWM2_Set_Duty(current_duty1); } Delay_ms(5); // slow down change pace a little } unsigned short current_duty, old_duty, current_duty1, old_duty1; void InitMain() { ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; PORTA = 255; TRISA = 255; // configure PORTA pins as input PORTB = 0; // set PORTB to 0 TRISB = 0; // designate PORTB pins as output PORTC = 0; // set PORTC to 0 TRISC = 0; // designate PORTC pins as output PWM1_Init(5000); // Initialize PWM1 module at 5KHz PWM2_Init(5000); // Initialize PWM2 module at 5KHz } void main() { InitMain(); current_duty = 16; // initial value for current_duty current_duty1 = 16; // initial value for current_duty1 PWM1_Start(); // start PWM1 PWM2_Start(); // start PWM2 PWM1_Set_Duty(current_duty); // Set current duty for PWM1 PWM2_Set_Duty(current_duty1); // Set current duty for PWM2

PWM Capture/Compare/PWM

Code void main() { short current_duty_1 = 16; // initial value for current_duty_1 short current_duty_2 = 16; // initial value for current_duty_2 TRISD = 0xFF; // PORTD as input TRISC = 0x00; // PORTC as output PWM1_Init(5000); // Initialize PWM1 PWM2_Init(5000); // Initialize PWM2 PWM1_Start(); // start PWM1 PWM2_Start(); // start PWM2 PWM1_Set_Duty(current_duty_1); // Set current duty for PWM1 PWM2_Set_Duty(current_duty_2); // Set current duty for PWM2 while (1) // endless loop { if (!RD0_bit) // if button on RD0 pressed { Delay_ms(40); current_duty_1++; // increment current_duty_1 PWM1_Set_Duty(current_duty_1); //Change the duty cycle } if (!RD1_bit) // button on RD1 pressed { Delay_ms(40); current_duty_1--; // decrement current_duty_1 PWM1_Set_Duty(current_duty_1); } if (!RD2_bit) // if button on RD2 pressed { Delay_ms(40); current_duty_2++; // increment current_duty_2 PWM2_Set_Duty(current_duty_2); } if (!RD3_bit) // if button on RD3 pressed { Delay_ms(40); current_duty_2--; // decrement current_duty_2 PWM2_Set_Duty(current_duty_2); } Delay_ms(10); // slow down change pace a little }