Corporate Excellence Program In Electronics & Communication AVR Development Board
Building Blocks
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program
Outline: AVR Development Board
- Feature Overview - Block Diagram of Development Board - Components in Development Board - How to burn Programs on the Board - A sample Program to burn - How to write Programs for ATMEGA 16 - LED Pattern Example - Interfacing a simple Output Device with ATMEGA 16 - Seven Segment Example - Interfacing a Display Device with ATMEGA 16 - LCD Display Example -
www.buildingblocks.in | www.bulo.in | 9818403093
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program
Outline: AVR Development Board
Following points should kept in mind to write program Programmer notepad- Open the programmer notepad - Select the c/c++ from the plan text tool bar - write the program - Click on File and save the program with C extension example : led.c in separate folder - minimize the programmer notepad MFile(WinAVR) - open the Mfile - Click on Makefile - click on main file name & give the file same file name without C extennsion. example : Main file led - Click on Mfie & click on MCU type & select the type of microcontroller ATMEG 16 - Click on Mfie then programmer & click on PON EYSER - Click on Mfie & click on File & Save as with name (Makefile) in the same folder. Programmer notepad- Maximize the programmer notepad & click on Tool - then click on (WinAVR)Makefile:- make is formed - Connect the hardware - then click on (WinAVR) program :- The program is burned in MCU.
www.buildingblocks.in | www.bulo.in | 9818403093 4
Corporate Excellence Program
Development Board: Features Overview
AVR ATMEGA 16 Development board has: 16MHz crystal oscillator for maximum speed. One ATMEGA-16 Chip In-built motor driving circuitry On board LCD connector LCD brightness control variable resistor 1 Switch for the ON/OFF power indicator LED
RED LED as a Power Indicator.
All Pins accessible through male header pins. On Board Voltage Regulator with filters and operating voltage from 6V to 12V.
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program
Development Board: Block Diagram
LCD: device where you can display the string or character. Switch : can be used ON & OFF the power supply Can be used to drive the motors.
Sensors: used to sense the change in environment.
Can be used to indicate the power supply .
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program
Development Board: Component Overview Misc. There are some small and essential component which are required to initialize the Development Board, which are: Power on/off Button-provide power to the LED indicator of Development Board Power Jack Used to connect the power source with the development Board.
L293D IC is used to take 5 voltage in input and provide the voltage of 6 to 8v to the motors.
7805 IC is used to give 5 volt to the ATMEGA 16. Crystal oscillator:- Is used to gives
the fixed value of clock to the MC
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program ATMEGA 16: Overview Overview - Is an 8 Bit Microcontroller - Is a 40 Pin IC - Advanced RISC Architecture - 32x8 General Purpose Working Registers Memory - 16 K Bytes of In-system Self Programmable Flash - 512 Bytes of EEPROM - 1K Byte Internal SRAM I/O Peripherals - 32 Programmable I/O Lines - 8 Channel, 10 Bit ADC
Interrupts/Timers - 8 Bit Timer/Counters 2 - 16 Bit Timer/Counter 1
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program ATMEGA 16: Overview
Overview Vcc (Pin 10) is power-up voltage for the IC - GND (Pin 11, 31) must be grounded - RESET (Pin 9) Reset Pin generates Low Level Pulse Length that is longer than the minimum Pulse Length - XTAL1 (Pin-13) It Inputs to the inverting Oscillator amplifier and input to the internal clock operating circuit. - XTAL2 (pin-12) -- Output from the inverting Oscillator amplifier. - AVCC (pin-30) --AVCC is the supply voltage pin for Port A and the A/D - AREF (pin- 32) AREF is the analog reference pin for the A/D Converter. I/O (Input/output) pins grouped as A, B, C & D with 8 pins in each group. PA0 - PA7 (PORTA) PB0 - PB7 (PORTB) PC0 - PC7 (PORTC) PD0 - PD7 (PORTD)
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program ATMEGA 16: Overview
Four bidirectional I/O ports. Port A (PA7...PA0) It is beginning from the (pin 33- 40) 1. is acting as the analog inputs to the A/D Converter. 2. also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. 3. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B (PB7...PB0)---- It is beginning from the (pin 08- 01) 1. is an 8-bit bi-directional I/O port with internal pull-up resistor 2. Port B also serves the functions
Port C
1. 2.
(PC7...PC0)---- It is beginning from the (pin 29- 22) is an 8-bit bi-directional I/O port with internal pull-up resistor Port B also serves the functions
Port D (PD7...PD0)---- It is beginning from the (pin 21- 14) 1. is an 8-bit bi-directional I/O port with internal pull-up resistor 2. Port B also serves the functions
www.buildingblocks.in | www.bulo.in | 9818403093
10
Corporate Excellence Program ATMEGA 16: Overview ADC system of Atmega16 microcontroller consists of following pins: i ADC0-ADC7: 8 Channels from Pin 40 to Pin 33 ii. AREF: Pin32 of Atmega16 microcontroller, - the voltage on AREF pin acts as the reference voltage for ADC conversion, - reference voltage is always less than or equal to the supply voltage, i.e., Vcc. iii. AVCC: - Pin30, - is the supply voltage pin for using PORTA and the ADC; - must be connected to Vcc to use PORTA and ADC. Note: External reference voltage source can be used at AREF pin. However, Atmega16 also has internal reference voltage options of 2.56V and Vref = Vcc.
www.buildingblocks.in | www.bulo.in | 9818403093 11
Corporate Excellence Program
Development Board: How to write Programs
Following points should kept in mind to write program Programmer notepad- Open the programmer notepad - Select the c/c++ from the plan text tool bar - write the program - Click on File and save the program with C extension example : led.c in separate folder - minimize the programmer notepad MFile(WinAVR) - open the Mfile - Click on Makefile - click on main file name & give the file same file name without C extennsion. example : Main file led - Click on Mfie & click on MCU type & select the type of microcontroller ATMEG 16 - Click on Mfie & click on PON EYSER - Click on Mfie & click on File & Save as with name (Makefile) in the same folder. Programmer notepad- Maximize the programmer notepad & click on Tool - then click on (WinAVR)Makefile:- make is formed - Connect the hardware - then click on (WinAVR) program :- The program is burned in MCU.
www.buildingblocks.in | www.bulo.in | 9818403093 12
Corporate Excellence Program
Development Board: Hardware Requirement for burning the program
Burner: It provides an interface between computer and hardware(Development Board). Power Cable: It provides a voltage to the development board circuit. Serial Cable: It provides an interface between computer and burner. 6 Pin Female molex connecting cable: It provide an interface between Development Board and Burner. Development Board: It is board where instructions is resided and executed. the
www.buildingblocks.in | www.bulo.in | 9818403093
13
Corporate Excellence Program
Development Board: How to write Programs
-A program is a sequence of instructions written to perform a specified task for a computer or a hardware.
Following are the commonly used keywords in AVR Programming:
Make File: It is a file which gives the information about the file to the compiler that which interface we used, which microcontroller we are using etc.
Make All: It is a command which is used to compile the program essentially it is a set of statements.
www.buildingblocks.in | www.bulo.in | 9818403093
14
Make Clean: To remove all the executable files - .hex, .elf, .o etc. Whenever you make any changes to the code, you will have to execute this command.
Make Program: In order to burn the program into the chip, Program extension is used after make on the command prompt.
Ponyser: It is the programmer (hardware circuit) for the serial interface.
www.buildingblocks.in | www.bulo.in | 9818403093
15
Corporate Excellence Program
Development Board: Hardware Interfacing of LED Board
INPUT/OUTPUT Board: - is used as a Input/output device. - On the pin of the PORT of MC, The value of 1 is written and this value is sent on the LED board through Molex connecting wire. Ground: ground may be the reference point in an electrical circuit from which other voltages are measured. This ground comes from the development. 8-Pin connector: The point where development Boards Port is attached directly with the LED Board to show output. The power comes to LEDs through the programming to LEDs board by 8 pin Molex connecting cables. Push Button: This button makes the LED Board functional. The power is on www.buildingblocks.in | www.bulo.in | /off 9818403093 through this switch.
16
Corporate Excellence Program
Development Board: Hardware Interfacing of LED Board
Molex Female Connecting Cable: There are three types of cable is used here. 1. 2 pin molex connecting Cable:- Is generally used to power supply to the board. 2. 6 pin molex connecting Cable:- Is used to interface the Engineering Development Board with serial programmer. 3. 8 pin molex connecting Cable:- Is generally used to interface the PORT of the Microcontroller to the peripherals board such as LEDs board , seven segment board. .
www.buildingblocks.in | www.bulo.in | 9818403093 17
Corporate Excellence Program
Development Board: Hardware Interfacing of LED Board
Serial programmer:- This device is used to burn the program from computer to the microcontroller. Serial Cable:- Is the cable used to interface the serial programmer with computer.
www.buildingblocks.in | www.bulo.in | 9818403093
18
Following points should kept in mind to write program Programmer notepad- Open the programmer notepad - Select the c/c++ from the plan text tool bar - write the program - Click on File and save the program with C extension example : led.c in separate folder - minimize the programmer notepad MFile(WinAVR) - open the Mfile - Click on Makefile - click on main file name & give the file same file name without C extennsion. example : Main file led - Click on Mfie & click on MCU type & select the type of microcontroller ATMEG 16 - Click on Mfie & click on PON EYSER - Click on Mfie & click on File & Save as with name (Makefile) in the same folder. Programmer notepad- Maximize the programmer notepad & click on Tool - then click on (WinAVR)Makefile:- make is formed - Connect the hardware - then click on (WinAVR) program :- The program is burned in MCU.
www.buildingblocks.in | www.bulo.in | 9818403093
19
Corporate Excellence Program
Development Board: Programming in embedded C How to write the programming in embedded C? Following steps should be followed to write any program
1. Initialize the Header File a. Header File: contains prototypes and other compiler/pre- processor directives. Or in other words DEFINITIONS Without header file, Embedded c is the useless software. Whenever the program is written we initialize the header file.
Following header files are initialize while programming:a. <avr/io.h> :- This header file is used for giving input to the microcontroller & taking output from the microcontroller . Syntax:- #include<avr/io.h>
b. <util/delay.h> : - This is the header file used to initialize the delay function in the programming. Syntax:- #include<util/delay.h>
www.buildingblocks.in | www.bulo.in | 9818403093 20
Corporate Excellence Program
Development Board: Programming in embedded C
2. Write void main() :- The execution of the program is stared from the void main. Syntax : <return_type> main() { /* opening of the main function */
// set of execution statements could be any: - Declaration statements; - Arithmetic Operations; - Function Calls; return (instance of <return_type>) ; } /* end of the main function */
4. Do Commenting - used to make any program readable/understandable for other programmers - is not an executable statement - should be given at the beginning or end of the line but not in middle of the line 5. Every statement in c should end with semicolon (;) Note: C is a case sensitive Language
www.buildingblocks.in | www.bulo.in | 9818403093
21
Corporate Excellence Program
Development Board: Programming in embedded C
6.Initialize the Data Direction Register:- this is the register used to indicate the microcontroller that programmer will used the particular port as either input or output in the programming. - is initialized at the beginning in the main function. - Example:- DDRA ox00-----For declare PORT A as input port. DDRA oxFF-----For declare PORT A as output port. 7. Write the PORTA/ PORTB/PORTC/PORTD for making output of the pin of a port of the MC Example:- PORTA=ob11110000;
www.buildingblocks.in | www.bulo.in | 9818403093
22
Corporate Excellence Program
Development Board: Interfacing LED Board
LED Board Circuit diagram Home work:Make an input/output board containing 5 switch & 5 LEDs
www.buildingblocks.in | www.bulo.in | 9818403093
23
Corporate Excellence Program
Development Board: Interfacing LED Board
Qu.1. write a program to glow the Number of LEDs as 1, 2, 3, 4,-. One by one with using of loop.
#include<avr/io.h> #include<util/delay.h> Void main() { DDRD= 0xFF; PORTD=0b10000000; _delay_ms(500); PORTD=0b01000000; _delay_ms(500); PORTD=0b00100000; _delay_ms(500); PORTD=0b00010000; _delay_ms(1000); }
Assignment 1. Write a program to rotate the LEDs glow one by one in right shift. Assignment 2. Write a program to rotate the LEDs glow one by one in Left shift. Assignment 3. Write a program to glow all odd ON in one time & all Even LEDs on on www.buildingblocks.in second time. This pattern will glow continuously.| www.bulo.in | 9818403093
24
Corporate Excellence Program
Development Board: Delay programming
#include<avr/io.h> #include<util/delay.h> void DELAY(unsigned int j) { for(;j>0;j--) { _delay_ms(10); } } Void main() { DDRD= 0xFF; while(1) { PORTD=0b10000000; DELAY(100); PORTD=0b01000000; DELAY(200); PORTD=0b00100000; DELAY(200); } }
www.buildingblocks.in | www.bulo.in | 9818403093 25
Corporate Excellence Program
Embedded command: INPUT command
PIN command :- is the command used to give the input power supply to the MC pin - write PINA for input to the port A - write PINB------ for input to the port B, write PINC------ for input to the port C write PIND------ for input to the port D Example:- PINA=ob11110000;
Embedded C Has Three major decision making instructions:1. If statement 2. If-else statement 3. if else if statement
If statement:
- is used to implement the decision control instruction. - Syntax: if (This condition is true) { execute this statement ; } - Generally Relational operators are used to compare two values to get a TRUE or FALSE - No semicolon at the end of the if statement - No bracket is needed if single statement has to be executed
www.buildingblocks.in | www.bulo.in | 9818403093
26
Corporate Excellence Program
Embedded command: Decisional Instruction
Assignment
1. Two ports, A & B are taken, One I/O card is connected at PORTA for input & second I/O card is connected at PORTB for output display. Then If input key 1 is press to input then all odd LEDs glow, 2 is press to input then all even LEDs glow, 3 is press to input then 1,2,3 LEDs glow, 4 is press to input then 4,5,6 LEDs glow, 5 is press to input then 7,8 LEDs glow. 2. Quest. Give the input on port D & output port A . By pressing first switch of I/P board then output will be display first 4 led glow on LED board connected on PORT A. How will use the LED board as input board. / PIN programming
www.buildingblocks.in | www.bulo.in | 9818403093
27
Corporate Excellence Program
Embedded command: INPUT command
If else if statement:
- is used to implement the decision control instruction. - Syntax: if ( This condition is true) { execute this statement ; } else if ( This condition is true) { execute this statement ; } - Generally Relational operators are used to compare two values to get a TRUE or FALSE - No semicolon at the end of the if statement - No bracket is needed if single statement has to be executed
www.buildingblocks.in | www.bulo.in | 9818403093
28
www.buildingblocks.in | www.bulo.in | 9818403093
29
www.buildingblocks.in | www.bulo.in | 9818403093
30
www.buildingblocks.in | www.bulo.in | 9818403093
31
Corporate Excellence Program
Development Board: PIN programming
Quest. Give the input on port D & output port A . By pressing first switch of I/P board then output will be display first 4 led glow on LED board connected on PORT A.How will use the LED board as input board. / PIN programming #include<avr/io.h> #include<util/delay.h> Void main() { DDRD= 0X00; DDRA= 0XFF; If(0b10000000==PIND) { PORTA=0b11110000; } else If(0b01000000==PIND) { PORTA=0b00001111; } If(0b00100000==PIND) { PORTA=0b11111111; } }
www.buildingblocks.in | www.bulo.in | 9818403093
32
www.buildingblocks.in | www.bulo.in | 9818403093
33
Corporate Excellence Program
Development Board: Loop Programming
Loops : - Is a programming control used to repeat a set of instructions for a certain number of times. - The number of times can be defined ITERATIVELY or based on a CONDITION - There are three methods by which we implement LOOPS in C for statement while statement do-while statement 1. While statement: Syntax: while(CONDITION) { do this ; do this ; } - is used to execute a set of instructions till the condition is TRUE . - when the condition is false, then the control will come out of the loop - Examples: - To implement an infinite LOOP, while (1) - To implement a timed LOOP, while (i < 20) { i++; }
www.buildingblocks.in | www.bulo.in | 9818403093 34
Corporate Excellence Program
Development Board: Loop Programming
Qu.1. write a program to glow the Number of LEDs as 1, 2, 3, 4,-. One by one with using of loop. #include<avr/io.h> #include<util/delay.h> Void main() { DDRD= 0xFF; while(1) { PORTD=0b10000000; _delay_ms(500); PORTD=0b01000000; _delay_ms(500); PORTD=0b00100000; _delay_ms(500); PORTD=0b00010000; _delay_ms(1000); } } Assignment 1. Write a program to rotate the LEDs glow one by one in right shift. Assignment 2. Write a program to rotate the LEDs glow one by one in Left shift. www.buildingblocks.in | www.bulo.in Assignment 3. Write a program to glow all odd ON in one time &|all Even LEDs on on second 9818403093 time. This pattern will glow continuously.
35
Corporate Excellence Program
Development Board: Interfacing LED Board
void DELAY(unsigned int j) { for(;j>0;j--) { _delay_ms(10); } } int main (void) { PORTD=0b11110000; DELAY(20); } Assignment 4. Write a program to rotate the first 4 LEDs from left to right & remaining 4 LEDs from right to left by using the delay function. Assignment 2. Write a program with use of proper delay function to rotate the LEDs glow one by one in Left shift. Assignment 3. Write a program to glow all odd ON in one time & all Even LEDs on on second time. This pattern will glow continuously.
www.buildingblocks.in | www.bulo.in | 9818403093 36
Corporate Excellence Program
Development Board: Delay programming
#include<avr/io.h> #include<util/delay.h> void DELAY(unsigned int j) { for(;j>0;j--) { _delay_ms(10); } } Void main() { DDRD= 0xFF; while(1) { PORTD=0b10000000; DELAY(100); PORTD=0b01000000; DELAY(200); PORTD=0b00100000; DELAY(200); } }
www.buildingblocks.in | www.bulo.in | 9818403093
37
Corporate Excellence Program
Development Board: Interfacing Seven Segment
Seven-segment display:-is an electronic display device for displaying numerical digit, Letters, Punctuation. - - is composed of seven different elements . - Individually on or off, they can be combined to produce simplified representations of the numerals.
Application of the Seven Segment: -used in digital clock , - electronic meters, and - other electronic devices for displaying numerical information.
Description of Seven-segment Display: Standard Common Cathode Seven-Segment Display It has 10 pins. Each pin is used to ON or OFF the segments. The Middle two pins of a seven segment is a cathode (-ve), which provides a ground to the seven segment. Decimal Point also connected Standard 5V control for Atmeaga16 controller. Easy to Connect Female Headers
www.buildingblocks.in | www.bulo.in | 9818403093 38
Corporate Excellence Program
Development Board: Seven Segment Board
Important point to remember: 7-Segment Display can be attached to any PORT through connector. 8 pins can be connected to one port & 4 pins can be connected to second port. Ground is connected from the supply of the board. Connection with Development Board must be same as with the LED.
www.buildingblocks.in | www.bulo.in | 9818403093
39
Corporate Excellence Program
Development Board: Segment PORT Value
www.buildingblocks.in | www.bulo.in | 9818403093
40
Corporate Excellence Program
Development Board: Program on Seven Segment
Q.2. Write a program to display 1 to 4 numeric number on 7- Segment at constant delay on different segment.
#include <avr/io.h> #include<util/delay.h>
Void main() { DDRD= 0XFF; DDRA=0XFF; while(1) { PORTA=0b10000000; PORTD=0b01100000; delay_ms(2000); PORTA=0b01000000; PORTD=0b11011100; delay_ms(2000); PORTA=0b00100000; PORTD=0b11110100; delay_ms(2000); PORTA=0b00010000; PORTD=0b01100010; delay_ms(2000);
} }
//1
//2
//3
//4
www.buildingblocks.in | www.bulo.in | 9818403093
41
Corporate Excellence Program
Development Board: Interfacing seven segment Display Assignment.3 Write a program to display all 1 to 9 on the seven segment board one by one on seven segment. Assignment4. Interface LED board on port A & sevaen segment with port B & D . Display n all even number on seven segment & all even LEDs ON at the same time .
#include <avr/io.h> #include<util/delay.h> Void main() { DDRA= 0XFF; DDRB=0XFF; DDRB=0XFF; while(1) { PORTA=0b01000000; delay_ms(2000); PORTA=0b00010000; delay_ms(2000); PORTA=0b00000100; delay_ms(2000); PORTA=0b00000001; delay_ms(2000);
PORTA=0b01000000; PORTD=0b11011100; //2 delay_ms(2000); PORTA=0b00010000; //4 PORTD=0b01100010; delay_ms(2000); } }
www.buildingblocks.in | www.bulo.in | 9818403093
42
Corporate Excellence Program
Development Board: Interfacing Motors (DC) Motor : is a device which converts electrical energy into mechanical energy.
Principal and working of motor : This motor works on Farad law of the electromagnetic induction.
Law:A current -carrying conductor generates a magnetic field. when a current carrying conductor is placed in the external magnetic field, it will experience a force proportional to the current in the conductor, and to the strength of the external magnetic field. Application Motor is applied where there is there motion is needed. - Used in car, used in washing machine, fans ets.
www.buildingblocks.in | www.bulo.in | 9818403093
43
Corporate Excellence Program
Development Board: Interfacing Motors (DC, Stepper)
Q.2. Write a program to run two motors in forward direction for 20 second and back ward direction for 10 second #include <avr/io.h> #include<util/delay.h> Void main() { DDRD= 0xFF; DDRC=0XFF; while(1) { PORTD=0b00001010; delay_ms(20000); PORTD=0b00000101; delay_ms(2000); } }
www.buildingblocks.in | www.bulo.in | 9818403093 44
Corporate Excellence Program
Development Board: Interfacing LCD Display
LCD PINS Pin 1 Pin2 Pin3 Pin4 Pin5 Pin6 Pin7 Pin8 Pin9 Pin10 Pin11 Pin12
SYMBOL
CONNECTION TO AVR
Pin13 Pin14
Pin15 Pin16
GND Vcc Vee RS RW PIN 24 DB DB DB DB DB DB DB DB K A
GND VCC PIN 22 GND EN NOT USED NOT USED NOT USED NOT USED PIN 28 PIN 27 PIN 26 PIN 29 VCC GND
45
www.buildingblocks.in | www.bulo.in | 9818403093
Corporate Excellence Program
Development Board: Interfacing I/P (Touch Sensors)
www.buildingblocks.in | www.bulo.in | 9818403093
46
Corporate Excellence Program
Development Board: Create A Line Follower
www.buildingblocks.in | www.bulo.in | 9818403093
47
Corporate Excellence Program
Development Board: Create A Wall Follower
www.buildingblocks.in | www.bulo.in | 9818403093
48
Corporate Excellence Program
Development Board: Create A Obstacle Avoider
www.buildingblocks.in | www.bulo.in | 9818403093
49