Introduction to Microcontrollers

33
By P. Venkata Sai Vamsi, 3 rd Year EE, B.Tech, IIT Indore. INTRODUCTION TO MICROCONTROLLERS ELECTRONICS CLUB, IIT INDORE

description

This can be considered as tutorial for the project "CID Calculator"

Transcript of Introduction to Microcontrollers

Page 1: Introduction to Microcontrollers

By P. Venkata Sai Vamsi,3rd Year EE, B.Tech,

IIT Indore.

INTRODUCTION TO MICROCONTROLLERS

ELECTRONICS CLUB, IIT INDORE

Page 2: Introduction to Microcontrollers

Outline

• Introduction• Block Diagrams• Classifications in Microcontrollers (Atmega 32A)• Integration of Keyboard with the Microcontroller• Integration of LCD Display with the Microcontroller• CID CALCULATOR• Programming

Page 3: Introduction to Microcontrollers

Introduction (Source – Wikipedia)

Microprocessor:- The microprocessor is a multipurposeprogrammable device that accepts digital data as input, processesit according to instructions stored in its memory, and providesresults as output.

8085 MICROPROCESSOR

Page 4: Introduction to Microcontrollers

Microcontroller:- is a small computer on a single integratedcircuit containing a processor core, memory, andprogrammable input/output peripherals.

Example:-

Microcontroller basedMicrowave

Peripherals:- is a device that is connected to a host computer,but not an integral part of it. It expands the host's capabilitiesbut does not form part of the core computer architecture. It isoften, but not always, partially or completely dependent on thehost.

Page 5: Introduction to Microcontrollers

There are three different types of peripherals:I. Input devices (mouse, keyboards, etc.)II. Output devices (monitors, printers, etc.)III. Storage devices (hard drives, flash drives, etc.)

Examples:-

4x4 Keypad 16x2 LCD Display

Page 6: Introduction to Microcontrollers

Microprocessor Block Diagram

MICROPROCESSOR

Ex:- Keyboard

Page 7: Introduction to Microcontrollers

Microcontroller Block Diagram

MICROCONTROLLER

PORTS

Page 8: Introduction to Microcontrollers

Classifications in Microcontrollers (ATMEGA 32A)

• Ports:- PORT A, PORT B, PORT C, PORT DEach port consists of 8 pins, to transfer 8 bit data between the Microcontroller and the Peripheral devices. These ports can acts as both input/output ports.

• Interrupts:- INT 0, INT 1interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. The processor responds by suspending its current activities, saving its state, and executing a small program called an interrupt handler (or interrupt service routine, ISR) to deal with the event. This interruption is temporary, and after the interrupt handler finishes, the processor resumes execution of the previous thread.

Page 9: Introduction to Microcontrollers

Edge triggered interrupt:- An edge-triggered interrupt is aninterrupt signaled by a level transition on the interrupt line,either a falling edge (high to low) or a rising edge (low to high).

***For more details in using Interrupts contact me [email protected]

Active Low and Active High:- If any port is activated by givinglow (0) input, then it is called as Active Low and vice versa.Ex:- Reset is active low

Page 10: Introduction to Microcontrollers

• ATMEGA 32A Pin ConfigurationBack

Page 11: Introduction to Microcontrollers

Integration of Keyboard with the Microcontroller

Page 12: Introduction to Microcontrollers

Key Board Integration (4x4 Keyboard)

Switches

Here I connected the keyboard to PortB. Any port will solve the purpose.

Page 13: Introduction to Microcontrollers

Before Pressing a key

Page 14: Introduction to Microcontrollers
Page 15: Introduction to Microcontrollers

By following the above procedure, we can get the row no of the key pressed.Question:- How we will find the column no of the key pressed?

Page 16: Introduction to Microcontrollers

By following the above procedure, we can get the ‘row no’ of the key pressed.Question:- How we will find the ‘column no’ of the key pressed?Answer:- By setting the value of each column to ‘1’ (one at a time), we can observe the change in the state of the row 1 for the corresponding change in the state of column 1 (here we pressed the 1st key).

*****This is the end of the keyboard integration*****

Page 17: Introduction to Microcontrollers

Why do we prefer LCD Display to 16/17 segment ALPHA Numeric Display?Reasons:-1. Length of the display - In 16x2 LCD Display unit, we can

display up to the 32 characters. Whereas, in 16/17 segment ALPHA Numeric Display we require, 32 display units to display the same.

2. Ease of use – Predefined libraries are available for the LCD Display.

Integration of LCD Display with the Microcontroller

Page 18: Introduction to Microcontrollers

Integration of LCD Display with the Microcontroller

Connections with Atmega 32A

Page 19: Introduction to Microcontrollers

Procedure

Add the predefined libraries to your project folder and initialize the LCD subsystem using a call to LCDInit(LS_BLINK|LS_ULINE).To write any text call LCDWriteString("Welcome"); To write any number call void LCDWriteInt(int val,unsigned int field_length); This will print a integer contained in “val”. The field length is the length of field in which the number is printed.Example:- LCDWriteInt(3,4); will print as follows

Page 20: Introduction to Microcontrollers

Question:- Can any one guess what happens if we write LCDWriteInt(123,5); ?

Page 21: Introduction to Microcontrollers

Question:- Can any one guess what happens if we write LCDWriteInt(123,5); ?

Answer:-

Page 22: Introduction to Microcontrollers

Next function - void LCDGotoXY(uint8_t x,uint8_t y); Here, uint8_t represents unsigned integer which is 8bit.So, the maximum number it can store = 2^8-1 = 255.LCDGotoXY(11,1);

This function changes the cursor position to the given X,Y coordinates.

Page 23: Introduction to Microcontrollers

LCD Display panel, will retain the previously displayed value. It won’t clear it.

Well, does anyone wonder how to clear the display then?Here comes the use of another important function LCDClear();This will clears the display and reset’s the default cursor position to (0,0).

Next function - LCDWriteStringXY(x,y,msg);With this function, user can display the message at his desired coordinates.

Page 24: Introduction to Microcontrollers

For Example:-LCDWriteStringXY(3,0,”hello”); LCDWriteStringXY(8,1,”world”);

Similarly there is a function for integers.LCDWriteIntXY(x,y,num,field_length);

*****This is the end of the LCD Display integration*****

Page 25: Introduction to Microcontrollers

CID CALCULATOR

Basic components required:-1. ATMEGA 32A Microcontroller2. Display unit ( I suggest you to use

16x2 LCD Display unit)3. 4x4 Keyboard(No restriction with

the size)4. Connecting Wires5. Circuit Board6. Battery7. *HD74LS08 IC (AND Gate)8. **Programmer

*Depends on whether you are going to use interrupts or not.**We do possess one USB Programmer, which can be used for programming.Bread boards, Soldering wire and Soldering irons are available with our electronics club.

FEB 7th 2014FLUXUS 2014

Page 26: Introduction to Microcontrollers

How to start???

I think this is the big question in your mind!!!

Page 27: Introduction to Microcontrollers

Steps to complete the CID CALCULATOR:-

1. Finish off the connections part.2. Start programming the microcontroller.3. Implement your own ideas.4. Test the functionalities of your design.

That’s it!!!

Page 28: Introduction to Microcontrollers

How to Connect??

Page 29: Introduction to Microcontrollers

How to Connect??Connection’s part is already covered!!!

Page 30: Introduction to Microcontrollers

Programming

Software used: Atmel Studio 6.1Size: Around 900MB(This can be downloaded directly from the atmel website)Language: ‘Embedded C’There is no much difference between ‘embedded c’ and ‘c’.

Page 31: Introduction to Microcontrollers

How to connect the Programmer

ISP- In System Programming

If you remember the pin configuration of ATMEGA 32A

MOSI - Pin 6 MISO - Pin 7SCK - Pin 8RESET - Pin 9VCC - Pin 10GND - Pin 11

Page 32: Introduction to Microcontrollers

Sample Program

To Blink an LED:-#define F_CPU 8000000UL //Setting the clock frequency for

using delay#include<avr/io.h>#include<avr/interrupt.h> // For Interrupts#include<util/delay.h> // For Delay function int main(void){ DDRD = 0xFF; //setting Port D as output portwhile(1) //to run the loop continuously{ PORTD = 0XFF; //giving high (1) as output to the port D

_delay_ms(1000); //giving delayPORTD = 0x00;//giving low (0) as output to the port D

_delay_ms(1000); //giving delay}}

Atmel Studio 6.1

Page 33: Introduction to Microcontrollers

THANK YOU

For queries, write to me @[email protected]