Interfacing of Input/Output devices with AVR Microcontroller Enrolment No. : 130200111097 Name of the student: SOMAIYA ISHA.

Slides:



Advertisements
Similar presentations
1 ECE 372 – Microcontroller Design Parallel IO Ports - Outputs Parallel IO Ports E.g. Port T, Port AD Used to interface with many devices Switches LEDs.
Advertisements

Introduction to Micro-controllers Anurag Dwivedi.
PROGRAMMABLE PERIPHERAL INTERFACE -8255
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
kashanu.ac.ir Microprocessors 6-1 I/O Devices Switches, LED, LCD Lec note 6.
Input/Output (I/O) Ports and Interfacing
Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 12.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
Programming the ATmega16
Spring EE 316 Computer Engineering Junior Lab LCD modules, PROMs, Serial Ports.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Coordinate Based Tracking System
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
2 Way FM Car Starter Dan Owens April 12, 2005 Instructor: Dr. Pao-Lo Liu Department of Electrical Engineering University at Buffalo Course Requirement.
Embedded Systems Design 1 Lecture Set B Interfacing the MCS-51 to: –7 and 16 segment displays –a Multiplexed 7-Segment Display –a Keypad –an LCD.
Lecture – 7 Basic input and output
Liquid Crystal Display
ECE 353 Introduction to Microprocessor Systems Michael Schulte Week 12.
Digital Outputs LCD Display
1 4-Integrating Peripherals in Embedded Systems (cont.)
Input/Output Ports and Interfacing
Instrumentation & Control Engg. Section Electrical Engineering Department Ahmedabad , Gujarat.
LCD Interfacing.
EE 316 Computer Engineering Junior Lab Serial Ports, LCD Displays & PROMs.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
UNIT 7 - INTRODUCTION TO I/O INTERFACING. TWO MAJOR TYPES OF I/O INTERFACING ISOLATED I/O - DEDICATED I/O INSTRUCTIONS ARE USED TO ACCESS I/O DEVICES.
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
BRANCHES SUBROUTINES AND MEMORY USAGE AVR Assembler M. Neil - Microprocessor Course 1.
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
ECE 447 Fall 2009 Lecture 12: TI MSP430 External LCD.
I/O Devices Switches, LED, LCD
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
Sitarambhai Naranjibhai Patel Institute Of Technology & R.C.
A.D.Patel institute of technology Sub : LCD and Keyboard interfacing with AVR. prepared by, chokshi abhi p ( ) Guided by, Prof. Asif Thakor.
SUBMITTED BY EDGEFX TEAM PORTABLE CODED WIRELESS MESSAGE COMMUNICATION BETWEEN TWO PARTIES SECRETLY WITH LCD DISPLAY.
Introduction to Projects using Microcontroller Md. Khalilur Rhaman Credit: Interface Lab.
A PRESENTATION ON RELAY, OPTOISOLATOR AND STEPPER MOTOR INTERFACING WITH AVR Prepared By:- Katariya Prakash[ ] Kathiriya Shalin[ ]
ARM CORTEX (STM32) BASED MOTOR SPEED CONTROL SUBMITTED BY EDGEFX TEAM.
Sitarambhai Naranjibhai Patel Institute of Technology and Research Centre, Umrakh, Bardoli. A Presentation On “ 16x2 LCD Interfacing with AVR atmega32.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
“ INSTRUCTIONS SET OF AVR MICROCONTROLLER ” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Abhishek Lakhara
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
LCD Interfacing using Atmega 32
ARDUINO BASED AUTOMATIC TEMPERATURE BASED FAN SPEED CONTROLLER
Embedded Systems Programming Examples and Comparison
4-Integrating Peripherals in Embedded Systems (cont.)
UNIVERSAL COLLEGE OF ENGINEERING & TECHNOLOGY
GANDHINAGAR INSTITUTE OF TECHNOLOGY
(6. Sunu) (AVR Assembly Örnekleri)
COMP2121: Microprocessors and Interfacing
Principles & Applications Seven-Segment Displays
COMP2121: Microprocessors and Interfacing
EET 2261 Unit 11 Controlling LCD and Keypad
Subject Name: Microprocessors Subject Code:10EC46 Department: Electronics and Communication Date: /10/2018.
CENG2400 Revision Q1a A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module. Two on/off switches are connected to bit-3.
EET 2261 Unit 11 Controlling LCD and Keypad
I/O Ports in AVR Sepehr Naimi
AVR Programming in C Chapter 7
LCD and Keyboard Sepehr Naimi
I/O Ports in AVR Sepehr Naimi
Advanced Assembly Chapter 6
(Dr. Öğr. Üyesi Deniz Dal)
Interrupt Chapter 10.
Presentation transcript:

Interfacing of Input/Output devices with AVR Microcontroller Enrolment No. : Name of the student: SOMAIYA ISHA

21 June 2016Dr. C.H. Vithalani2 Interfacing of push-button switches Write a program to generate square wave at port pin PC5 if switch connected at Port pin PB3 is pressed.

21 June 2016Dr. C.H. Vithalani3 Interfacing of push-button switches CBI DDRB,3 ;Clear DDR bit for PB3 to make it input SBI DDRC,5 ;Set DDR bit for PC5 to make it output HERE: SBIC PINB,3 ;Skip next instruction if PB3 is LOW RJMP HERE SBI PORTC,5 ;Set PC5 CBI PORTC,5 ;Clear PC5 RJMP HERE Assembly Language

21 June 2016Dr. C.H. Vithalani4 De-bouncing of push button switch De-bouncing can be done by Hardware or by software

21 June 2016Dr. C.H. Vithalani5 Exercise: Write program to Read status of Switch connected at Port Pin PC0, Make LED ON if switch is pressed and Make LED OFF if switch is released …. CBI DDRC,0 ;Set PC0 pin as an input pin SBI DDRB,0 ; Set PB0 pin as an output Port AGAIN: SBIS PINC,0 ; SKIP next instruction if PC0 is high RJMP DEVICE_ON SBI PORTB,0 RJMP AGAIN DEVICE_ON: CBI PORTB,0 RJMP AGAIN

21 June 2016Dr. C.H. Vithalani6 Interfacing of push-button switch Programming in C #include #define SW 3 //Bit position 3 #define SQR 5 //Bit position 5 int main(void) { DDRB=DDRB & ~(1<<SW); //Set PB3 pin input DDRC=DDRC | (1<<SQR);; //Set PC5 pin output while(1) { if(PINB & (1<<SW)) { PORTC=PORTC & ~(1<<SQR); } else { PORTC=PORTC | (1<<SQR); }

21 June 2016Dr. C.H. Vithalani7 LED Flashing Program in C # include void delay_ms(int count) { int i,j; for(int i=0;i<=count;i++){ for(int j=0;j<=100;j++); } int main(void) { DDRD=0xFF; //Port D Output Port PORTD=0xFF; while(1) { PORTD=0x55; delay_ms(1000); PORTD=0xAA; delay_ms(1000); } return 0; }

21 June 2016Dr. C.H. Vithalani8 LED Flashing Program in Assembly LDIR16, 0xFF ; Set Port B as an output Port OUT DDRB, R16 ; LDI R16, 0x08 ; Define Stack pointer OUT SPH,R16 LDI R16, 0x5F OUT SPL,R16 AGAIN: LDI R16, 0x55 OUT PORTB, R16 RCALL DELAY LDI R16, 0xaa OUT PORTB, R16 RCALL DELAY RJMP AGAIN DELAY: LDI R20,0x05 L3:LDI R21,0xFF L2:LDI R22,0xFF L1:DEC R22 BRNE L1 DEC R21 BRNE L2 DEC R20 BRNE L3 RET

21 June 2016Dr. C.H. Vithalani9 Interfacing of DIP switch & Seven Segment Display

Interfacing of SS Display.. 21 June 2016Dr. C.H. Vithalani10

Program in C … 21 June 2016Dr. C.H. Vithalani11 int main(void) { DDRD=0xFF; //Port D Output Port DDRA=0x00; //Port A Input PORTD=0xFF; unsigned char ssdata[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92, 0x82,0xF8, 0x80,0x90,0xC8,0x83,0xC6,0xA1,0x86, 0x8E,0x00}; unsigned char switchdata; while(1) { switchdata=PINA; switchdata=switchdata&0x0F; PORTD=ssdata[switchdata]; }

21 June 2016Dr. C.H. Vithalani12 Program: DIP SW and SS Display LDI R16,0x00 OUT DDRC,R16 ;Port C Input to read DIP Switch LDI R16,0xFF OUT DDRB,R16 ;Port B Output to Display on SS LDI ZH,HIGH(SSDATA<<1) ;Memory pointer NEXT: IN R16,PINC ANDI R16,0b ;Mask Upper Nibble LDI ZL,LOW(SSDATA<<1) ADD ZL,R16 LPM R17,Z OUT PORTB,R17 RJMP NEXT SSDATA:;Look Up Table for SS Code.DB 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xC8,0x83.DB 0xC6,0xA1, 0x86, 0x8E,0x00

21 June 2016Dr. C.H. Vithalani13 Program: DIP SW and SS Display int main(void) { unsigned char ssdata[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0xC8,0x83,0xC6,0xA1,0x86, 0x8E,0x00}; unsigned char switchdata; DDRC=0x00; //Port C Input DDRB=0xFF; //Port B Output while(1) { switchdata=PINC; switchdata=switchdata&0x0F; PORTB=ssdata[switchdata]; }

21 June 2016Dr. C.H. Vithalani14 Interfacing of thumb wheel SW Thumb wheel switch is widely used in the industry for setting various parameters like temperature at various points in furnace, pressure, fluid flow etc. It is widely used in code lock system to set password and then open lock with that password. It is used when we want to operate equipment by unskilled operator. Operator has to rotate the wheel (or in some switches, push the switch to increment the digit) to change parameters. Thumb wheel switch comes in two configuration: Decimal switch which provides BCD output and Hexadecimal switch which provides binary output corresponding to hexadecimal number. BCD thumbwheel switch is more popular because unskilled operator can use it to set the parameters.

21 June 2016Dr. C.H. Vithalani15 Interfacing of thumb wheel SW

21 June 2016Dr. C.H. Vithalani16 Program #include int main(void) { unsigned char ssdata[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0xC8,0x83,0xC6,0xA1,0x86, 0x8E,0x00}; unsigned char switchdata; DDRA=0x00; //Port A Input DDRD=0xFF; //Port D Output while(1) { switchdata=PINA; switchdata=switchdata&0x0F; PORTD=ssdata[switchdata]; } }

21 June 2016Dr. C.H. Vithalani17 LCD Basic Principle LCD is constructed by sandwiching a thin layer of liquid crystal fluid between two glass plates. A transparent electrically conductive film (electrodes) or back plane is kept on rear glass sheet. Each pixel of an LCD typically consists of a layer of molecules aligned between two transparent electrodes and two polarizing filters, the axes of transmission are perpendicular (cross) to each other With no liquid crystal between the polarizing filters, light passing through the first filter would be blocked by the second (crossed) polarizer.

21 June 2016Dr. C.H. Vithalani18 Basic Principle When a voltage is applied across the electrodes (between backplane and segments), electric field created to align the liquid crystal molecules parallel which will cause transmission of light for particular segment.

21 June 2016Dr. C.H. Vithalani19 Basic Principle We can not apply steady dc voltage between back plane and segment. LCD segment drive signals must be square wave with a frequency 30 Hz to 150 Hz. Microcontroller application designer should not take care of applying square waves by programming 8051 because this care is already taken inside LCD module by dedicated microcontroller. The HD44780U is dot-matrix liquid crystal display controller and driver. It can be configured to drive a dot-matrix liquid crystal display under the control of a 4 or 8 bit microcontroller.

21 June 2016Dr. C.H. Vithalani20 Basic Principle LCD controller HD44780 supports: 16  1 (16 characters, single row), 16  2 (16 characters, two row) 20  2 (20 characters, two row), 24  2 (24 characters, two row) 40  2 (40 characters, two row)

21 June 2016Dr. C.H. Vithalani21 Alphanumeric LCD Interfacing Pinout 8 data pins D7:D0 RS: Data or Command Register Select R/W: Read or Write E: Enable (Latch data) RS – Register Select RS = 0  Command Register RS = 1  Data Register R/W = 0  Write, R/W = 1  Read E – Enable Used to latch the data present on the data pins. D0 – D7 Bi-directional data/command pins. Alphanumeric characters are sent in ASCII format. E R/W RS DB7–DB0 LCD controller communications bus 8 LCD Module Microcontroller

21 June 2016Dr. C.H. Vithalani22 LCD Commands The LCD’s internal controller can accept several commands and modify the display accordingly. Such as: Clear screen Return home Decrement/Increment cursor After writing to the LCD, it takes some time for it to complete its internal operations. During this time, it will not accept any new commands or data. We need to insert time delay between any two commands or data sent to LCD

21 June 2016Dr. C.H. Vithalani23 Interfacing diagram PORTD : Data bus D0-D7 of LCD PB0: Register select pin RS of LCD PB2: Enable pin of LCD R/W pin of LCD Grounded

21 June 2016Dr. C.H. Vithalani24 Programming steps …. Initialize the LCD. For example send command word #38h to initialize LCD for 5  7 dots/character and 2 rows. send command word #3Ch for 5  10 dots/character and two rows. Write separate routine to send command. Make RS=0 and after transferring command word to port Port D, enable LCD by sending pulse at port pin PB0. Make PB1 pin low because it is write operation. Write separate routine to send data to the LCD in which Make RS=1 and after transferring data to port Port D, we will enable LCD to display data. Make pin Pb1 low because it is write operation.

21 June 2016Dr. C.H. Vithalani25 LCD Assembly Language program.EQU LCD_DATA=PORTD ;Port D drives data lines.EQU LCD_DDR =DDRD.EQU LCD_CMD = PORTB ;Port B drives control signals RS,E and RW.EQU LCD_CDDR = DDRB.EQU RS=0.EQU RW=1.EQU EN=2 LDI R16, 0xFF ; Set Port D as an output Port OUT LCD_DDR, R16 ; we can also write OUT DDRD,R16 OUT LCD_CDDR,R16 ; We can also write OUT DDRB,R16 LDI R16, 0x08 ; Define Stack pointer OUT SPH,R16 ;Stack pointer initialisation LDI R16, 0x5F OUT SPL,R16

21 June 2016Dr. C.H. Vithalani26 LCD Assembly Language program CALL LCD_INIT LDI R16,'G' CALL LCDData LDI R16,'E' CALL LCDData LDI R16,'C' CALL LCDData LOOP:RJMP LOOP

21 June 2016Dr. C.H. Vithalani27 LCD Assembly Language program LCD_INIT: LDI R16,0x38 ;Initialise LCD for 5x7 dots/char, two lines CALL LCDCommand LDI R16,0x0E ;Display ON, Cursor ON CALL LCDCommand LDI R16,0x01 ; Clear LCD CALL LCDCommand LDI R16,0x06 ; Shift cursor right CALL LCDCommand LDI R16,0x80 ; Move cursor to first line, first column CALL LCDCommand RET

21 June 2016Dr. C.H. Vithalani28 LCD Assembly Language program LCDCommand: OUT LCD_DATA,R16 CBI LCD_CMD,RS ;RS=0 to select command register CBI LCD_CMD,RW ;RW=0 for write operation SBI LCD_CMD,EN ;EN=1 to enable LCD NOP ;Short delay with NOP NOP CBI LCD_CMD,EN ; EN=0 CALL DELAY ; Call delay RET

21 June 2016Dr. C.H. Vithalani29 LCD Assembly Language program LCDData: OUT LCD_DATA,R16 SBI LCD_CMD,RS ;RS=1 to select command register CBI LCD_CMD,RW ;RW=0 for write operation SBI LCD_CMD,EN ;EN=1 to enable LCD NOP ;Short delay with NOP NOP CBI LCD_CMD,EN ; EN=0 CALL DELAY ; Call delay RET

21 June 2016Dr. C.H. Vithalani30 LCD Assembly Language program DELAY: LDI R21,0x05 L2: LDI R22,0xFF L1: DEC R22 BRNE L1 DEC R21 BRNE L2 RET

21 June 2016Dr. C.H. Vithalani31 Command for position of cursor

21 June 2016Dr. C.H. Vithalani32 Display String CALL LCD_INIT LDI R31,HIGH(msg<<1) ;Pointer for LCD Message LDI R30,LOW(msg<<1) LOOP: LPM R16,Z+ ;Get data from location defined by memory pointer ; and increment memory pointer CPI R16,0 BREQ EXIT CALL LCDData RJMP LOOP EXIT: RJMP EXIT msg:.db “Welcome to GEC Rajkot",0

21 June 2016Dr. C.H. Vithalani33 LCD Program in C # include # include //To use in-built delay routine #define LCD_DATA PORTD #define LCD_DDR DDRD #define LCD_CMD PORTB #define LCD_CDDR DDRB #define RS 0 #define RW 1 #define EN 2 void mydelay(int count) { int i,j; for(int i=0;i<=count;i++) { for(int j=0;j<=100;j++); } }

21 June 2016Dr. C.H. Vithalani34 LCD Program in C void lcdCommand(unsigned char); void lcdData(unsigned char); void lcdMessage(char *); void lcdInit(); int main(void) { lcdInit(); lcdCommand(0x80); lcdMessage("GEC RAJKOT"); lcdCommand(0xC0); lcdMessage("EC Department"); while(1); return 0; }

21 June 2016Dr. C.H. Vithalani35 LCD Program in C void lcdInit() { LCD_DDR=0xFF; LCD_CDDR=0xFF; lcdCommand(0x38); //Initialise LCD for 5x7 dots/char, 2 lines lcdCommand(0x0E); //Display ON and Cursor ON lcdCommand(0x01); //Clear LCD mydelay(10); lcdCommand(0x06); //Shift cursorn right }

21 June 2016Dr. C.H. Vithalani36 LCD Program in C void lcdCommand(unsigned char cmd) { LCD_DATA=cmd; LCD_CMD=LCD_CMD & ~(1<<RS); //Make RS=0 LCD_CMD=LCD_CMD & ~(1<<RW); //Make RW=0 LCD_CMD=LCD_CMD | (1<<EN); //Make EN=1 mydelay(1); LCD_CMD=LCD_CMD & ~(1<<EN); //Make EN=0 mydelay(10); }

21 June 2016Dr. C.H. Vithalani37 LCD Program in C void lcdData(unsigned char mydata) { LCD_DATA=mydata; LCD_CMD=LCD_CMD | (1<<RS); //Make RS=1 LCD_CMD=LCD_CMD & ~(1<<RW); //Make RW=0 LCD_CMD=LCD_CMD | (1<<EN); //Make EN=1 mydelay(1); LCD_CMD=LCD_CMD & ~(1<<EN); //Make EN=0 mydelay(10); }

21 June 2016Dr. C.H. Vithalani38 LCD Program in C void lcdMessage(char *msg) { unsigned char i=0; while(msg[i]!=0) { lcdData(msg[i]); i++; } }

21 June 2016Dr. C.H. Vithalani39 Some Commands

21 June 2016Dr. C.H. Vithalani40 THANK YOU