Professional Documents
Culture Documents
Lab Manual Degree MM (3141008)
Lab Manual Degree MM (3141008)
Institute logo
Directorate of Technical
Education,Gandhinagar,Gujarat
Microprocessor & Microcontroller (3141008)
Place: __________
Date: ___________
By using this lab manual students can go through the relevant theory and procedure in
advance before the actual performance which creates an interest and students can have
basic idea prior to performance. This in turn enhances pre-determined outcomes amongst
students. Each experiment in this manual begins with competency, industry relevant skills,
course outcomes as well as practical outcomes (objectives). The students will also achieve
safety and necessary precautions to be taken while performing practical.
This manual also provides guidelines to faculty members to facilitate student centric lab
activities through each experiment by arranging and managing necessary resources in order
that the students follow the procedures with required safety and necessary precautions to
achieve the outcomes. It also gives an idea that how students will be assessed by providing
rubrics.
Utmost care has been taken while preparing this lab manual however always there is
chances of improvement. Therefore, we welcome constructive suggestions for
improvement and removal of errors if any.
[Type text]
Microprocessor & Microcontroller (3141008)
Interface I/O peripheral devices with AVR microcontroller to develop embedded system (Apply)
Sr. CO CO CO CO CO
Objective(s) of Experiment
No. 1 2 3 4 5
Understand Arduino open source hardware and
programming environment and write program to blink LED
1. √ √
using Arduino instructions, C language & Assembly
language.
Interface Digital/Analog input output
2. interfacing module with Arduino board √
and write programs related to I/O module
The following industry relevant competency are expected to be developed in the student
by undertaking the practical work of this laboratory.
1. Students will be able to switch over to ant other microcontroller easily.
2. Students will be able to interface any Input-output device to given
Microcontroller.
Write Assembly language and C programs using ATMEL Studio or Microchip Studio
Simulate Assembly and C Language programs using PROTEUS software or any other
available simulation software in lab or in your personal laptop
Install Arduino open source software to write, compile and download programs in
Arduino UNO board and Arduino Nano board.
Student has to construct mini-project based on AVR (Either Arduino Nano/ Arduino
UNO or any other development board)
Suggested list of mini-projects based on Arduino board will be given by faculty. However
students are free to choose any mini-project. It is desirable if students find out some real
life problem related to society or industry and solve it.
Students should refer websites and literature along with datasheet relevant to this course
Student should develop a habit of submitting the experimentation work as per the
schedule and s/he should be well prepared for the same.
Student shall develop the habits of evolving more ideas, innovations, skills etc. apart from
those included in scope of manual.
[Type text]
Microprocessor & Microcontroller (3141008)
INDEX
(Progressive Assessment Sheet)
Sr. No. Objective(s) of Experiment Page Date of Date of Assessme Sign. of Remarks
No. perform submiss nt Teacher
ance ion Marks with date
1 Understand Arduino open source hardware and
programming environment and write program to
blink LED using Arduino instructions, C language
& Assembly language.
2 Interface Digital/Analog input output
interfacing module with Arduino board
and write programs related to I/O module
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 1
AIM: Understand Arduino open source hardware and programming environment and write
program to blink LED.
Objectives:
To install Arduino open source software
To learn Arduino UNO and nano open source hardware
To learn programming of Arduino UNO and Nano boards
To start with we can use Arduino UNO board or Arduino nano board. Arduino UNO board is
as shown in the following figure.
This Arduino UNO board uses ATMEL AVR Microcontroller ATMEGA328P.
ATMega238P Microcontroller is 28 pin, 8 bit RISC microcontroller having total 23
programmable I/O lines, 6 channel 10 bit ADC, two 8 bit timer/counter, one 16 bit
timer/counter with compare and capture mode. It has 32 general purpose 8 bit registers R0 to
R31. Students are advised to refer datasheet for more information about the chip.
Analog (6): Six Analog pins are available which is labelled as A0 through A5. These
pins can read the signal from an analog sensor (like a temperature sensor, light sensor,
weight sensor (strain gauge) and convert it into a digital value which can be displayed
on LCD. We can process this analog signal and take decision based on value of it.
Digital I/O: Digital input/output pins (0 through 13 on the UNO) are available. These
pins can be used for both digital input (like telling if a button is pushed) and digital
output (like powering an LED).
PWM (8): Please notice the tilde (~) sign next to some of the digital pins (3, 5, 6, 9,
10, and 11 on the UNO). These pins act as normal digital pins, but can also be used
for supplying Pulse-Width Modulation (PWM) output.
[Type text]
Microprocessor & Microcontroller (3141008)
AREF (9): Stands for Analog Reference. Most of the time you can leave this pin
alone. It is sometimes used to set an external reference voltage (between 0 and 5
Volts) as the upper limit for the analog input pins.
External power socket: Usually Arduino board takes power by USB cable when
connected to LAPTOP or Desktop. But once program is downloaded in it and if we
want to use this board as standalone board, we can connect external +5V through this
external power connector.
Tx and Rx pin and LEDs: Digial pins 0 and 1 is also used for serial communication.
Tx and Rx LEDs are blinking when serial communication is going on.
USB connector: USB connector is used to connect Arduino with PC/Laptop with
USB cable. It is also giving +5V power required by the board. USB cable is used to
download program into AVR chip (From PC side it is called uploading).
This pin mapping is useful if students want to write program using ATMEL Studio or other
tools and want to program Arduino board.
Note:
Care should be taken while interfacing external devices with Arduino board. Do not draw
more current from I/O pins, if devices required more than current specified above, driver
circuit should be used. To drive DC motor or Stepper motor using Arduino board, separate
driver circuit like IC LM293D should be used. Similarly to drive electromagnetic relay or
solenoid switching transistor SL-100 should be used. If external circuit requires large current,
separate power supply should be used for that circuit.
Arduino is coming with large set of sample programs. Students can use this sample programs
and modify it according to hardware and application.
Steps to use sample program:
1. File -> Examples->Basics->Blink
[Type text]
Microprocessor & Microcontroller (3141008)
2. This will open original Blink sketch in a new window. We will work in that window
now. Do not bother about old window.
3. Now select the board and programming port using
4. Tools-> Board -> ARDUINO UNO. This will select our board.
5. Now select the programming interface: Tools-> Serial Port-> COMx. This will select
virtual serial port created by USB to Serial Driver. To know on which COM port
Arduino is connected use device manager of PC or Laptop.
6. Press VERIFY Button (or from menu Sketch->Verify). Bottom right shows progress
bar. Bottom left line shows “Compiling Sketch…” and after some time after the
compilation is over it displays “Done compiling”. If there were any compilation errors
they will be highlighted in red at the bottom of the screen
7. Press UPLOAD button, second on top left, performs dual tasks of compilation as well
as transportation of machine code to the board. When we press UPLOAD button, the
IDE bottom line shows first Compiling Sketch and then Uploading…. If the board is
connected and powered, the uploading will begin in 2-3 seconds. The Debug LED as
well as Tx and Rx LEDs on board will blink on the board indicating that machine
code file is being transferred from PC to board. The time it takes depends upon length
of program but it is usually 2 to 10 seconds.
Program:
/* This program blinks LED connected at pin 13 */
/*setup function runs once when you press reset or power the board */
void setup()
{
// initialize digital pin 13 (PB5) as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever just like while(1)
void loop()
{
digitalWrite(13, HIGH); // turn the LED on connected at PB5
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off
delay(1000); // wait for a second
}
void setup()
{
DDRB=DDRB | (1<<5); //Set pin PB5 as output pin (LED is connected)
}
void loop()
{
PORTB=PORTB | (1<<5); //Set PB5 pin
delay(100);
PORTB=PORTB & ~(1<<5); //Clear PB5 pin
delay(100);
}
To start with we can use Arduino UNO or Arduino NANO board. Pin diagram of Arduino
NANO is given below.
[Type text]
Microprocessor & Microcontroller (3141008)
Use ATMEL Studio or AVR Studio for following C language and Assembly language
program for Arduino board.
int main(void)
{
DDRD=0xFF; //Port D Output Port
DDRB=DDRB|(1<<5); //Inbuilt Arduino LED connected to PB5 pin
DDRD=0xFF;
while(1)
{
PORTB=PORTB|(1<<5);
delay_ms(5000);
PORTB=PORTB&~(1<<5);
delay_ms(5000);
}
return 0;
}
Assembly language program to blink LED:
SBI DDRB,5 ;In-built Arduino LED connected to PB5 pin
LDI R16, 0x08 ; Define Stack pointer
OUT SPH,R16
LDI R16, 0x5F
OUT SPL,R16
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
[Type text]
Microprocessor & Microcontroller (3141008)
:: WORKSHEET::
Activity #1:
Write instructions to initialize PB0, PD0 and PD1 pins as output pins using Arduino
instructions, Assembly language and C language instructions. Write program to blink LEDs
connected on these pins.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #2:
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3:
Write program to blink Arduino LED (Connected at pin 13, PB5 pin) in increasing and
decreasing rate continuously. Rate should increase from 1 second to 5 second and then rate
should decrease from 5 second to 1 second. Monotonically increasing and decreasing rate.
Write program either using Arduino instructions or C language(Hint: Use For loop or While
loop for this purpose)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
EXPERIMENT NO. 2
[Type text]
Microprocessor & Microcontroller (3141008)
We will need male/female wires to connect I/O board with Arduino card.
Program:
Write program to detect push-button press and make LED on if push-button switch is
pressed. Consider push-button switch connected to digital pin number 2. Use internal LED
(Which is connected to Pin 13)
const int SW = 2; // Push button switch with Pin No. 2
const int LED = 13; // the number of the LED pin
void setup() {
// initialize the LED pin as an output:
pinMode(LED, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(SW, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(SW);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(LED, HIGH);
}
else {
// turn LED off:
digitalWrite(LED, LOW);
}
}
:: WORKSHEET::
Activity #1: Connect 4 LEDs of DAIO module with Arduino digital pins 2 to 5. Write
following program, compile, upload and execute the program and observe LEDs.
int LEDPins[]={2,3,4,5};
int totalPin=4;
void setup() {
int i;
for(i=0;i<totalPin;i++)
{
pinMode(LEDPins[i], OUTPUT);
}
}
[Type text]
Microprocessor & Microcontroller (3141008)
void loop() {
int i;
for(i=0;i<totalPin;i++)
{
digitalWrite(LEDPins[i],HIGH);
}
delay(1000);
for(i=0;i<totalPin;i++)
{
digitalWrite(LEDPins[i],LOW);
}
delay(1000);
}
Observation:
_____________________________________________________________________
_____________________________________________________________________
____________________________________________________________________
Explain program:
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
____________________________________________________________________
Activity #2: Modify program given in activity 1 such that all 4 LED becomes ON one by one
after 1 second and then turn OFF one by one. Write program again. Compile and execute this
program in Arduino board.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3: Connect +Vcc and Gnd of Arduino board with DAIO module. Digital pin 2 with
Buzzer pin of DAIO module. Write program to sound buzzer for 1 second and OFF for 2
second. Repeat this five times.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
Activity #4: Modify program given in activity 3 such that when SW1 of DAIO module is
pressed, Buzzer should sound otherwise it should remain OFF. Connect Buzzer of DAIO
module with Digital pin 7.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #5: Prepare OR gate with SW1 and SW2. Write program such that when SW1 or
SW2 or both are pressed, internal LED of Arduino board should glow. Connected SW1 with
pin 6 and SW2 with pin 7 of Arduino board. Write program in following space.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
EXPERIMENT NO. 3
AIM: Generate PWM waveform and change intensity of LED connected with
Arduino board
Objectives:
To generate PWM waveform
Know importance of PWM for light dimmer and speed control
Program 1:
/*
Change Intensity of LED by PWM
Two LEDs of General purpose I/O board is connected to Pin 9 and 10.
Brightness of one LED will increase while other will decrease and vice-varsa */
{
pinMode(LED1, OUTPUT); // set pin 9 as output.
pinMode(LED2, OUTPUT); // set pin 10 as output.
}
void loop()
{
for (i=minBrightness; i<=maxBrightness; i=i+1)
{
analogWrite(LED1,i);
analogWrite(LED2,255-i);
delay(10);
}
delay(1000);
}
[Type text]
Microprocessor & Microcontroller (3141008)
Program 2:
Change Intensity of LED by pressing different switches on DAIO Board.
/*
Change Intensity of LED by PWM using switches
Switches are connected to Pin 2 and 3
*/
int LED = 9 ;// LED is connected to pin 9 PWM channel.
int SW1=2;
int SW2=3;
boolean sws1,sws2;
void setup()
{
pinMode(LED, OUTPUT); // set pin 9 as an output.
pinMode(SW1,INPUT); // Pin 2,3 Input
pinMode(SW2,INPUT);
void loop()
{
sws1=digitalRead(SW1);
sws2=digitalRead(SW2);
if(sws1==0)
{
analogWrite(LED,200);
}
delay(100);
if(sws2==0)
{
analogWrite(LED,100);
}
delay(100);
}
Observe waveforms on Pin 9 for by pressing SW1 and SW2 one by one by one
and then draw waveforms.
Waveform when SW1 is pressed:
Waveform when SW2 is pressed:
:: WORKSHEET::
Activity #1: Connect three color LED with PWM pins 9,10 and 11. Write program to
produce 8 different colors. Write your program in following space. (If three color LED not
available then connect three separate LEDs and produce eight different binary patterns from
000 to 111)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
Activity #2: Connect three color LED with PWM pins 9,10 and 11. Write program to
produce 8 different colors. Write your program in following space. Connect Switches SW1,
SW2 and SW3 with pin number 2, 3 and 4. Generate color from LED in following sequence.
ON ON ON WHITE
ON ON OFF YELLOW
ON OFF ON MAGENTA
OFF ON ON CYAN
Objectives:
To measure temperature using LM35
Understand specifications of LM35
Transmit values using serial communication
Specifications of LM35:
Calibrated Directly in Celsius (Centigrade)
Linear + 10-mV/°C Scale Factor
Temperature sensor LM35 is available on DAIO Board. Connect LM35 pin to A0 pin of
Arduino board. Compile and upload following program in Arduino card. See value of
temperature on serial monitor.
[Type text]
Microprocessor & Microcontroller (3141008)
Program 1:
/*
Measure Temperature and Transmit value serially
*/
int sensorValue = 0;
int alarm = 13;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(alarm,OUTPUT);
}
void loop() {
int sum = 0; // Variable to store sum of temperature readings
float temperature;
for (int i = 0; i<100; i++)
{
sum = sum + (long)(analogRead(sensorValue));// read one value and add it to var sum.
delay(10);// wait for some time before taking next sample.
}
// sum now contains total of 100 readings. Divide it by 100 to get average value.
sum = sum /100L;
temperature = (((float)(sum) )* 5000.0 /1023.00 )/10.0; // convert int temp into voltage in
mV. Then divide it by 10 to get temperature in degree Celcius.
if(temperature>30)
digitalWrite(alarm, HIGH);
else
digitalWrite(alarm, LOW);
// print temperature value to the serial monitor:
Serial.println(temperature);
delay(1000); // Take reading at every 1 second
}
ATMega328 microcontroller used in Arduino board has 10 bit ADC, reading is divided by
1024 (210=1024). Value is again divided by 10 to convert readings from mV to 0C (because
sensitivity of LM 35 is 10-mV/°C)
If temperature is above 300C, LED will become ON (Student may connect Buzzer in place of
LED).
Program 2:
Check status of Door Switch and send message “Door is Open” if switch is open and “Door
is Closed” if switch is closed through serial communication.
/* Program to read status of Door lock switch and transmit
* status of Door serially
*/
int LED=13;
int SW=12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED,OUTPUT);
pinMode(SW,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int SWSTATUS;
SWSTATUS=digitalRead(SW);
Serial.println(SWSTATUS);
if(SWSTATUS==1)
{
Serial.println("DOOR IS OPEN");
digitalWrite(LED,HIGH);
}
else if(SWSTATUS==0)
{
Serial.println("DOOR IS CLOSE");
digitalWrite(LED,LOW);
}
delay(100);
Serial.flush();
}
Program 3: Measure Temperature, transmit values serially and write in spreadsheet or text
file.
#include <SPI.h>
#include <SD.h>
/*
Analog input, analog output, serial output
Connect Analog Input at pin 0
*/
[Type text]
Microprocessor & Microcontroller (3141008)
File myFile;
const int analogInPin = A0;
const int analogOutPin = 13;
int sensorValue = 0; // value read from the pot
int alarm = 13;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(alarm,OUTPUT);
myFile = SD.open("d:/tempdata.txt", FILE_WRITE);
}
void loop() {
int count=0;
while(count<100)
{
int sum = 0; // Variable to store sum of temperature readings
float temperature;
for (int i = 0; i<100; i++)
{
sum = sum + (long)(analogRead(sensorValue
delay(10);// wait for some time before taking next sample.
}
sum = sum /100L;
temperature = (((float)(sum) )* 5000.0 /1023.00 )/10.0;
if(temperature>30)
digitalWrite(alarm, HIGH);
else
digitalWrite(alarm, LOW);
// print the results to the serial monitor:
Serial.print("TEMPERATURE = " );
Serial.println(temperature);
myFile.write(temperature); //Write temperature data in file
delay(1000);
count++;
}
myFile.close();
:: WORKSHEET::
Activity #1: Connect LDR in place of LM35 and measure value of light. Transmit amount of
light intensity through serial communication. If Light intensity is low, transmit “DARK” and
if light intensity is high, transmit “BRIGHT” through serial communication. Write your code
and execute. Write light intensity results in “light.txt” file.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 5
AIM: Write and execute Arduino program to display message on LCD & GLCD
Objectives:
Understand interfacing of LCD & GLCD with Arduino UNO Board.
Write Arduino program to display message on LCD & GLCD
Write Arduino program to display counter on LCD & GLCD
Pin connections:
LCD ARDUINO
3 Contrast (GND)
5 Read/write (GND)
6 Enable 10 Digital 10
7 D0 (Keep open)
8 D1 (Keep open)
9 D2 (Keep open)
10 D3 (Keep open)
11 D4 5 Digital 5
12 D5 4 Digital 4
13 D6 3 Digital 3
14 D7 2 Digital 2
Pin connections:
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("GEC RAJKOT!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
:: WORKSHEET::
[Type text]
Microprocessor & Microcontroller (3141008)
Activity: In the LCD Connection setup of this experiment, connect variable resistor output
VR1 of DAIO Board with A0 pin of Arduino board. Connect +Vcc and Ground of DAIO
board with Arduino board. Write and upload following program
int AnalogPin = 0;
int POTValue1 = 0;
LiquidCrystal lcd(11, 10, 5, 4, 3, 2);// LCD in 4 bit mode
void setup() {
lcd.begin(16, 2);
lcd.print("EC Department MI LAB");
for(i=0;i<10;i++)
{
lcd.scrollDisplayLeft();
delay(500);
}
lcd.clear();
delay(1000);
}
void loop() {
lcd.setCursor(0,1);
lcd.print("Value:");
lcd.setCursor(6, 1);
POTValue= analogRead(AnalogPin));
lcd.print(POTValue);
delay(100);
}
Observation:
_____________________________________________________________________
_____________________________________________________________________
____________________________________________________________________
Explain program:
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity 2 : Search Graphical LCD interface on internet and draw connection diagram in
following space.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
___________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 6
AIM: Sense temperature using LM35 sensor and display temperature value
on LCD
Objectives:
Write program to read temperature using LM35 and display it on LCD for Arduino.
Connections:
Connect LCD as per experiment No. 5
Connect Temperature sensor LM35 output of DAIO board to A0 pin of Arduino
Program:
#include <LiquidCrystal.h>
int sensorPin1 = 0; // select the input pin for the potentiometer
int count,i,count_char=0;
char message[16];
float temperature;
long sum;
const int ledPin = 13;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(11, 10, 5, 4, 3, 2);// LCD in 4 bit mode
void setup() {
// set up the LCD's number of columns and rows:
i=0;
temperature=0;
sum=0;
pinMode(ledPin, OUTPUT);
lcd.begin(16, 2);
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
sum = 0; // initialize sum before starting to 0.
for (i = 0; i<100; i++)
{
sum = sum + (long)(analogRead(sensorPin1));
delay(10); // wait for some time before taking next sample.
}
sum = sum /100L;
temperature = ( ((float)(sum) )* 5000.0 /1023.00 )/10.0;
/* convert int temp into voltage in mV. then divide it by 10 to get temperature in
degree Celsius.*/
if(temperature>70)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.setCursor(6, 1);
lcd.print(temperature);
lcd.setCursor(13,1);
lcd.print("Deg.C.:");
delay(100);
}
:: WORKSHEET::
Activity #1: In this experiment set up remove LM35 output connection with Arduino board
and connect LDR with A0 pin of Arduino board.
Observation:
Activity #2: Write Arduino program such that LED connected with Pin 13 (On board LED)
should turn OFF when light falls on LDR and it should turn ON in dark condition.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3: Connect LCD Data lines D7 to D4 with pins 2 to 5. RS with pin 11 and Enable
with pin 10. (As per earlier experiment) Connect Switch with pin number 7. Write program
to display number on LCD depending on number of times switch is pressed. It should display
“count value” corresponding to number of times switch is pressed.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
EXPERIMENT NO. 7
AIM: Write assembly language programs for ATMega32 Microcontroller and simulate
using ATMEL Studio
Objectives:
To install ATMEL Studio
To learn assembly language instructions for AVR Microcontroller
Download ATMEL Studio from the website http://www.atmel.com or obtain setup from the
faculty in DVD or Pen drive. Install ATMEL Studio in your desktop PC or laptop.
Program 1: Write and assemble a program to load a value into each location of R20 – R23.
Complement the value in each register. Use the simulator to single-step and examine the flags
and register content after the execution of each instruction
.INCLUDE "M32DEF.INC"
Note:
LDI Instruction is used to load immediate 8 bit data to general purpose registers.
COM Instruction is used to complement content of registers
There are 32 general purpose registers in AVR microcontroller known as R0,R1,R2
…. R31.
LDI instruction cannot be used to load data in registers R0 to R15. It can be used for
registers R16 to R31
Semicolon (;) can be used to write comments (Anything written after ; will be ignored
by compiler). It is necessary for readability of programs
0x sign before the number is used to represent hexadecimal number i.e. 0xFF is
hexadecimal number whose decimal equivalent is 255.
Alternately $ sign can be used to represent hexadecimal number.
[Type text]
Microprocessor & Microcontroller (3141008)
Program 2: Write and assemble a program to load a value 0x55 to register R16, 0x33 to
register R17, Transfer content of R16 to R0 and R17 to R1. Add value of registers R0 and R1
and store result in register R0. Transfer value of register R16 to R2 and R17 to R3. Subtract
R3 from R2 and store result in register R2.
.INCLUDE "M32DEF.INC"
Note:
$ sign is used to represent hexadecimal value (Option of 0x )
MOV instruction is used to copy one register value into other …
(Source and destination can be any register R0 to R31)
ADD instruction used to add content of specified operands
SUB instruction used to subtract content of specified operands
RJMP is unconditional relative jump instruction used to create infinite loop at the end
of the program.
Program 3: Write and assemble a program to flash LEDs connected to Port B. Simulate
program to observe flashing on Port B.
.INCLUDE "M32DEF.INC"
LDI R16, 0xFF ; Set Port B as an output Port
OUT DDRB, R16 ;
LDI R16, 0x08 ; Define Stack pointer 0x085F
OUT SPH,R16
LDI R16, 0x5F
OUT SPL,R16
AGAIN:
LDI R16, 0x55 ;Copy data 0x55 to register R16
OUT PORTB, R16 ; Turn alternate LEDs ON
RCALL DELAY
LDI R16, 0xAA ;Copy data 0x55 to register R16
OUT PORTB, R16 ; Make ON LED OFF and OFF LED ON
RCALL DELAY
RJMP AGAIN
DELAY:
LDI R20,0x05
L3: LDI R21,0x01 ;Load 0xFF for hardware
L2: LDI R22,0x01 ;Load 0xFF for hardware
L1: DEC R22
BRNE L1 ; Brach if Z=0 i.e. if register content=0
DEC R21
BRNE L2
DEC R20
BRNE L3
RET
Note:
DDRB defines direction of PORT B. If we transfer 0x00 to DDRB, port becomes
input port and if we transfer 0xFF to DDRB, it becomes output port.
We are connecting 8 LEDs with port B so 0xFF is first loaded into R16 and then R16
is copied to DDRB to initialize PORT B as an output port.
This program uses “DELAY” subroutine
When “DELAY” subroutine is called from Main program using RCALL (Relative
call) instruction, value of Program counter is stored in stack memory pointed by
SP(Stack pointer) at 0x085F
DELAY routine uses three counters using registers R20, R21 and R22, it decrements
these registers until it becomes ZERO. For simulation use 0x01 for R21 and R22
(Less delay) and for hardware use 0xFF to get enough observation period for flashing
of LEDs
Program 4: Write assembly language program to monitor switch connected at port Pin PB2,
When Switch is not pressed (logic HIGH), send value 0x55 to port C and high to low pulse at
port pin PD3
.INCLUDE "M32DEF.INC"
CBI DDRB, 2 ;Set PB2 pin as an input pin
LDI R16, 0xFF ;Set Port C as an output Port
OUT DDRC, R16 ;
SBI DDRD, 3 ; Make PD3 pin output
AGAIN:
SBIS PINB, 2 ; SKIP next instruction (i.e. exit loop) if PB2 is high (SET)
RJMP AGAIN
LDI R16, 0x45
OUT PORTC, R16
SBI PORTD, 3
CBI PORTD, 3
HERE: RJMP HERE
Note:
CBI instruction used to clear bit immediately CBI DDRB,2 clears PB2 bit to use it
input pin (Because switch is connected)
SBI instruction is used to set bit immediately SBI DDRD,3 set pin PD3 to make it
output pin (because we want to generate pulse at PD3)
:: WORKSHEET::
Activity #1:Write and assemble the following program. Use the simulator to single-step
and examine the flags and register content after the execution of each instruction.
.INCLUDE "M32DEF.INC"
[Type text]
Microprocessor & Microcontroller (3141008)
LDI R20,$27
LDI R21,$15
SUB R20, R21
LDI R20,$20
LDI R21,$15
SUB R20, R21
LDI R24,95
LDI R25,95
SUB R24, R25
LDI R22,50
LDI R23,70
SUB R22, R23
L1: RJMP L1
------------------------------------------------------------------------------------------
Activity #2: Examine status of carry (C) flag after execution of following instructions in
single stepping mode.
Activity #3: Write assembly language program to make LEDs connected at port B ON
one by one at certain specified delay
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #4: Write assembly language program to read switches connected at PORT D and
display status of these switches on LEDs connected to PORTB. Simulate this program using
ATMEL studio.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #5 : W.A.P. to find the number of 1’s in a given byte stored at location 0x300.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #6: W.A.P. to convert packed BCD no. to two ASCII no. and place them in R21 and
R22.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 8
AIM: Understand hardware of ATMega32 Kit. Write and execute following programs …
Program to flash LEDs
Program to read status of switch display it on LEDs.
Program to display count value 0 to 9 on seven segment display at the interval of
approximately 1 second.
Program to read status of switches connected at port A and display its number on
seven segment display.
Objectives:
Understand hardware components of ATMega32 kit
Write and execute program in C language to flash (Blink) LEDs
Write program to read switches and take action based on status of switches
Interfacing of seven segment display with ATMega32 microcontroller
Interfacing of switches with ATMega32 microcontroller
Write program to display numbers on seven segment display using look up table
method.
AVRDude:
AVRdude is command line tool to program HEX (Binary) file from PC to AVR
microcontroller.
HFUSE and LFUSE is for AVR fuse bits. Fuse bits are used to choose features of AVR
microcontroller. ATMega32 has two fuse bytes: hfuse and lfuse. (Refer Chapter 8 of text
book for more details)
Another way is configure ATMEL Studio to Program ATMega32 Kit using ToolsExternal
tool option. Specify path of avrdude and give above parameters as arguments to program chip
using this short-cut.
E PB2
RWPB1
(Through PCF8591
ADC/DAC)
1 LCD, Seven Segment, 8 Input SW, ADC/DAC, SW3 and SW4 OFF
LM35 Temp Sensor
SW5,SW6,SW7 ON
[Type text]
Microprocessor & Microcontroller (3141008)
1
RN1
470
10
9
8
7
6
5
4
3
2
9 22
RESET PC0/SCL
23
PC1/SDA
13 24
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
26
PC4/TDO
40 27
PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29
PA2/ADC2 PC7/TOSC2
37
PA3/ADC3
36 14
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
PA7/ADC7 PD3/INT1
18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4
PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32
# include <avr/io.h>
void mydelay(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=0xFF;
mydelay(1000);
PORTD=0x00;
mydelay(1000);
}
return 0;
}
Sample program read switches and glow LEDs based on status of switches.
This program reads status of switch continuously and glow LED if switch is ON.
Program 2: Read status of switches and display status on LEDs
# include <avr/io.h>
int main(void)
{
unsigned char switchdata;
DDRD=0xFF; //Port D Output Port, LEDs are connected with Port D
DDRA=0x00; //Port A Input Switches are connected with Port A
while(1)
[Type text]
Microprocessor & Microcontroller (3141008)
{
switchdata=PINA;
PORTD= switchdata;
}
}
9 22
RESET PC0/SCL
23
PC1/SDA
13 24
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
26
OFF ON PC4/TDO
16 1 40 27
PA0/ADC0 PC5/TDI
15 2 39 28
PA1/ADC1 PC6/TOSC1
14 3 38 29
PA2/ADC2 PC7/TOSC2
13 4 37
PA3/ADC3
12 5 36 14
PA4/ADC4 PD0/RXD
11 6 35 15
PA5/ADC5 PD1/TXD
10 7 34 16
PA6/ADC6 PD2/INT0
9 8 33 17
PA7/ADC7 PD3/INT1
18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4
PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32
Sample program to read switches and display its hexadecimal number of seven segment
display.
Program 3: Read status of switches and display its hexadecimal number on seven segment
display.
# include <avr/io.h>
void mydelay(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
DDRA=0x00; //Port A Input
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];
}
}
# include <avr/io.h>
void mydelay(int count)
{
int i,j;
for(int i=0;i<=count;i++)
{
for(int j=0;j<=100;j++);
}
}
int main(void)
{
unsigned char count i=0;
DDRD=0xFF; //Port D Output Port
DDRA=0x00; //Port A Input
unsigned char ssdata[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,
0xF8,0x80,0x90,0xC8,0x83,0xC6,0xA1,0x86,
0x8E,0x00};
while(1)
{
PORTD=ssdata[count];
count++;
if(count==10) count=0;
}
}
[Type text]
Microprocessor & Microcontroller (3141008)
:: WORKSHEET::
Activity #1:
Modify sample program of blink LED so that Alternate LED blinks in following manner.
Write program again.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #2:
Modify program given in Activity #1 in such a way that LED should glow one by one from
left to right and than from right to left continuously…
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3:
Write assembly language program to glow LEDs one by one at the interval of 1 second.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #4: Write program for down-counter from 9 to 0 and display it on seven segment
display.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #5:
Write program to display number 1234 on four seven segment display one by one at the
interval of 1 second.
(Hint: Send seven segment hex code corresponds to 1 on PORTD, make PB0 pin high, after 1
second send seven segment hex code of number 2 on PORTD and make PB1 high and so on
for number 3 (PB2 high) and 4 (PB3 high).
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #6:
Read switch positions connected at PORT A pins PA4 to PA7. Display its 1’s complemented
value on seven segment display.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 9
AIM: Write program to display message “EC Department” on first line of LCD & GLCD.
Simulate circuit in PROTEUS software
Objectives:
Understand Interfacing of LCD & GLCD with microcontroller
Write program to display messages and numbers on LCD & GLCD
Interfacing diagram:
LCD1
LM016L
VDD
VSS
VEE
RW
RS
D0
D1
D2
D3
D4
D5
D6
D7
E
9 22
RESET PC0/SCL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
23
PC1/SDA
13 24
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
26
PC4/TDO
40 27
PA0/ADC0 PC5/TDI
39 28
PA1/ADC1 PC6/TOSC1
38 29
PA2/ADC2 PC7/TOSC2
37
PA3/ADC3
36 14
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
PA7/ADC7 PD3/INT1
18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4
PB3/AIN1/OC0
5
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32
C Program:
# include <avr/io.h>
# include <util/delay.h>
#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
{
unsigned char i=0;
while(msg[i]!=0)
{
lcdData(msg[i]);
i++;
}
}
Assembly Language Program for LCD:
.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
CBI LCD_CMD,EN ;Make EN=0 Initially disable LCD
CALL LCD_INIT
LDI R31,HIGH(msg1<<1) ;Pointer for LCD Message
LDI R30,LOW(msg1<<1)
LOOP:
LPM R16,Z+ ;Get data from memory and increment memory pointer
CPI R16,0
BREQ SecondLine
CALL LCDData
RJMP LOOP
SecondLine:
LDI R16,0xC0 ; Move cursor to second line, first column
CALL LCDCommand
LDI R31,HIGH(msg2<<1) ;Pointer for LCD Message
LDI R30,LOW(msg2<<1)
LOOP1:
LPM R16,Z+ ;Get data from location defined by memory pointer and increment
; memory pointer
CPI R16,0
BREQ EXIT
CALL LCDData
RJMP LOOP1
EXIT:
JMP EXIT
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
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
NOP
CBI LCD_CMD,EN ; EN=0
CALL DELAY ;Call delay
RET
LCDData:
OUT LCD_DATA,R16
SBI 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
NOP
CBI LCD_CMD,EN ; EN=0
CALL DELAY ;Call delay
RET
DELAY:
LDI R21,0x05
L2: LDI R22,0xFF
L1: DEC R22
BRNE L1
DEC R21
BRNE L2
RET
msg1: .db "GEC Rajkot",0
msg2: .db "EC DEPARTMENT ",0
Interfacing diagram:
[Type text]
Microprocessor & Microcontroller (3141008)
C Program:
#define F_CPU 8000000UL /* Define CPU clock Frequency 8MHz */
#include "Font_Header.h"
int main(void)
{
my_GLCD_String(0,"Microprocessor");
while(1);
[Type text]
Microprocessor & Microcontroller (3141008)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #2: Write program in C language to display different message on the LCD depending on position of
switches. If SW1 ON: First Floor SW2 ON: Second Floor SW3 ON: Third Floor and so on….
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
EXPERIMENT NO. 10
AIM: Write and execute program to rotate stepper motor clockwise and anticlockwise with
half step and full step mode
Objectives:
Understand Interfacing stepper motor with microcontroller
Write program to rotate stepper motor in anticlockwise and clockwise direction.
Write program to rotate stepper motor at different speeds.
Introduction:
Stepper motor is brushless synchronous motor which runs in discrete steps. It divides
full rotation into discrete steps. Stepper motor is manufactured with steps per revolution of
12, 24, 72, 144, 180, 200 and 400 which results into step angle of 30 0, 150, 50, 2.50, 20, 1.80,
and 0.90 per step. Stepper motor can be controlled precisely with or without feedback. It
converts electrical pulses into mechanical rotation in steps.
Stepper motor is widely used in Robots, Machine tools, CNC machines, floppy drives,
semiconductor wafer cutting machines and many other industrial control applications.
Stepping motors come in three varieties:
Permanent magnet type
[Type text]
Microprocessor & Microcontroller (3141008)
A
U1
9 22
RESET PC0/SCL
23
PC1/SDA
13 24
XTAL1 PC2/TCK
12 25
XTAL2 PC3/TMS
40
PA0/ADC0
PC4/TDO
PC5/TDI
26
27 D B
39 28
PA1/ADC1 PC6/TOSC1 U2
38 29
PA2/ADC2 PC7/TOSC2
37 10
PA3/ADC3 COM
36
35
PA4/ADC4
PA5/ADC5
PD0/RXD
PD1/TXD
14
15
1
2
1B
2B
1C
2C
18
17 C
34 16 3 16
PA6/ADC6 PD2/INT0 3B 3C
33 17 4 15
PA7/ADC7 PD3/INT1 4B 4C
18 5 14
PD4/OC1B 5B 5C
1 19 6 13
PB0/T0/XCK PD5/OC1A 6B 6C
2 20 7 12
PB1/T1 PD6/ICP1 7B 7C
3 21 8 11
PB2/AIN0/INT2 PD7/OC2 8B 8C
4
PB3/AIN1/OC0
5 ULN2803
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32
In bipolar stepper Motor there is single winding per pole. Total there are two coils. Direction
of current for stepper motor needs to be changed by the driving circuit. So the driving circuit
of the bipolar stepper motor becomes complex. Bipolar motor comes with four terminals
(Two terminals per coil as shown in following figure. Each coil requires H-bridge to drive.
Total two H-bridge requires driving one stepper motor.
Interfacing Diagram for Bipolar Mode:
+12V +12V
470 470
PD0 Q5 PD3 Q5
BC 557 BC 557
470 470
Q1 Q3 Q1 Q3
BC 547 BC 547 BC 547 BC 547
PD1 W in d in g PD4 W in d in g
Red Black
Yellow Brown/
470 470 Orange
Q2 Q4 Q2 Q4
BC 547 BC 547 BC 547 BC 547
PD2 PD5
IC L293D has inbuilt two H-bridge so it can be used to drive bi-polar stepper motor.
Arduino Program:
[1] Rotate motor in full step uni-polar mode
int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
speed = 500;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
void loop() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, HIGH);
[Type text]
Microprocessor & Microcontroller (3141008)
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(speed);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(speed);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, HIGH);
delay(speed);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(speed);
}
C Program for ATMega32 microcontroller to rotate motor in clockwise direction in
full-step uni-polar mode:
(Stepper Motor is connected to Port D PD0-PD3 pins via ULN2803)
#include <avr/io.h>
#include <avr/delay.h>
int main(void)
{
unsigned char stepdata=0x01;
DDRD=0x0F; //PD0-PD3 output to drive stepper motor
while(1)
{
PORTD=stepdata;
_delay_ms(1000);
stepdata<<=1;
if(stepdata==0x10) stepdata=0x01;
}
}
Circuit Diagram:
U1 10
COM
9 22 1 18
RESET PC0/SCL 1B 1C
23 2 17
PC1/SDA 2B 2C
13 24 3 16
XTAL1 PC2/TCK 3B 3C
12 25 4 15
XTAL2 PC3/TMS 4B 4C
26 5 14
PC4/TDO 5B 5C
40 27 6 13
PA0/ADC0 PC5/TDI 6B 6C
39 28 7 12
PA1/ADC1 PC6/TOSC1 7B 7C
38 29 8 11 +88.8
PA2/ADC2 PC7/TOSC2 8B 8C
37
PA3/ADC3
36 14 ULN2803
PA4/ADC4 PD0/RXD
35 15
PA5/ADC5 PD1/TXD
34 16
PA6/ADC6 PD2/INT0
33 17
PA7/ADC7 PD3/INT1
18
PD4/OC1B
1 19
PB0/T0/XCK PD5/OC1A
2 20
PB1/T1 PD6/ICP1
3 21
PB2/AIN0/INT2 PD7/OC2
4
PB3/AIN1/OC0
5 Anti-clockwise Clockwise
PB4/SS
6
PB5/MOSI
7 32
PB6/MISO AREF
8 30
PB7/SCK AVCC
ATMEGA32
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
unsigned char stepdata=0x01;
int main(void)
{
DDRC=0x0F; //PC0-PC3 output to drive stepper motor
PORTD=1<<2; //Pull up of PD2 activated
PORTD=1<<3;
MCUCR=0x02; //Negative Edge Trigerred
GICR=0xE0;
sei(); //SET interrupt flag in SREG
while(1);
}
ISR(INT0_vect)
{
sei();
while(1)
{
PORTC=stepdata;
_delay_ms(200);
stepdata<<=1;
if(stepdata==0x10) stepdata=0x01;
}
}
ISR(INT1_vect)
{
sei();
while(1)
{
PORTC=stepdata;
_delay_ms(200);
stepdata>>=1;
[Type text]
Microprocessor & Microcontroller (3141008)
if(stepdata==0x00) stepdata=0x08;
}
}
Assembly language program to rotate motor in clockwise direction in full step mode:
(Considering stepper motor is connected to Port C PC0-PC3 pins using ULN 2803 driver IC)
int main(void)
{
unsigned char stepdata[]={0x01,0x03,0x02,0x06,0x04,0x0C,0x08,0x09,0x00};
unsigned char i=0;
DDRC=0x0F; //PD0-PD3 output to drive stepper motor
while(1)
{
PORTC=stepdata[i];
_delay_ms(1000);
i++;
if(stepdata[i]==0) i=0;
}
}
:: WORKSHEET::
Activity #1:Draw interfacing diagram to drive stepper motor with PC0-PC3 pins of ATMega 32
microcontroller. Connect switch with INT0 pin. Write and execute C language programme to rotate
stepper motor in full step mode continuously. Speed of the motor should increase when switch
connected with INT0 is pressed.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #2:
[Type text]
Microprocessor & Microcontroller (3141008)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3:
Stepper motor is connected with shaft of CNC machine. One revolution of stepper motor
displace shaft by 10 cm. Write C or Assembly language program to displace shaft by 5 cm.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 11
AIM: Write and execute program to rotate DC motor of Robot for forward,
reverse, left and right motion. Simulate program using PROTEUS
Software
Objectives:
Understand Interfacing DC motor with microcontroller
Understand use of DC motor for robot motion control
Write program to rotate DC motor in anticlockwise and clockwise direction to move
robot in forward and reverse direction
Write program to rotate DC motor at different speeds using PWM.
Interfacing Details:
DC Motors are driven by L293D (Two H-bridge driver circuit).
U1
30 97
RESET PF0/ADC0
96
PF1/ADC1
34 95
XTAL1 PF2/ADC2
33 94
XTAL2 PF3/ADC3
93
U2 PF4/ADC4/TCK
8 16 78 92
PA0/AD0 PF5/ADC5/TMS
77 91
PA1/AD1 PF6/ADC6/TDO
3 2 76 90
OUT1 VS VSS IN1 PA2/AD2 PF7/ADC7/TDI
6 7 75
OUT2 IN2 PA3/AD3
+88.8 1 74 51
EN1 PA4/AD4 PG0/WR
73 52
PA5/AD5 PG1/RD
72 70
PA6/AD6 PG2/ALE
9 71 28
EN2 PA7/AD7 PG3/TOSC2
11 10 29
OUT3 IN3 PG4/TOSC1
14 15 19 1
OUT4 GND GND IN4 PB0/SS/PCINT0 PG5/OC0B
20
PB1/SCK/PCINT1
+88.8 21 12
PB2/MOSI/PCINT2 PH0/RXD2
L293D 22 13
PB3/MISO/PCINT3 PH1/TXD2
23 14
PB4/OC2A/PCINT4 PH2/XCK2
24 15
PB5/OC1A/PCINT5 PH3/OC4A
25 16
PB6/OC1B/PCINT6 PH4/OC4B
26 17
PB7/OC0A/OC1C/PCINT7 PH5/OC4C
18
PH6/OC2B
53 27
PC0/A8 PH7/T4
54
PC1/A9
55 63
PC2/A10 PJ0/RXD3/PCINT9
56 64
PC3/A11 PJ1/TXD3/PCINT10
57 65
PC4/A12 PJ2/XCK3/PCINT11
58 66
PC5/A13 PJ3/PCINT12
59 67
PC6/A14 PJ4/PCINT13
60 68
PC7/A15 PJ5/PCINT14
69
PJ6/PCINT15
43 79
PD0/SCL/INT0 PJ7
44
PD1/SDA/INT1
45 89
PD2/RXD1/INT2 PK0/ADC8/PCINT16
46 88
PD3/TXD1/INT3 PK1/ADC9/PCINT17
47 87
PD4/ICP1 PK2/ADC10/PCINT18
48 86
PD5/XCK1 PK3/ADC11/PCINT19
49 85
PD6/T1 PK4/ADC12/PCINT20
50 84
PD7/T0 PK5/ADC13/PCINT21
83
PK6/ADC14/PCINT22
2 82
PE0/RXD0/PCINT8/PDI PK7/ADC15/PCINT23
3
PE1/TXD0/PDO
4 35
PE2/XCK0/AIN0 PL0/ICP4
5 36
PE3/OC3A/AIN1 PL1/ICP5
6 37
PE4/OC3B/INT4 PL2/T5
7 38
PE5/OC3C/INT5 PL3/OC5A
8 39
PE6/T3/INT6 PL4/OC5B
9 40
PE7/ICP3/CLKO/INT7 PL5/OC5C
41
PL6
98 42
AREF PL7
100
AVCC
ATMEGA2560
}
}
Activity #1: Write Assembly language program to move robot in forward directi
Continuously.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
Activity #2:
(To take right turn, stop right motor and rotate left motor. Similarly to take left turn, stop left
motor and rotate right motor)
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #3: Connect Arduino card with motor driver module. FRC connector details of
motor driver module for DC motor is as under:
• Pin1&2 : Enable
• Pin3&4 : Input1
• Pin5&6 : Input2
• Pin7&8 : Direction Switch
• Pin19&20 is GND
Write Arduino program to rotate motor in clockwise direction and anticlockwise direction.
Draw connection diagram and run program.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
Activity #4: Connect arduino card with motor driver module to drive servo motor. FRC
connector details of motor driver module for Servo motor is as under. Draw Connection
diagram and run the program.
Servo Motor:
Introduction of I2C:
I2C is two wire serial data and control bus
Implemented with one serial data (SDA) and one clock (SCL) line.
[Type text]
Microprocessor & Microcontroller (3141008)
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
#include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("hello "); // respond with message of 6 bytes
// as expected by master
}
Transmit data from slave and receive it on master. Observe I2C waveforms on Storage
oscilloscope.
Introduction of SPI:
SPI is system for serial communication.
There are four wires: one for transmission, second for reception, third for clock
(synchronization) and fourth for selecting device for communication.
SPI is used in many devices such as ADC, DAC, EEPROM, RTC etc.
Many other hardware devices like (MAX7221) supports SPI. It receives SPI signals
from AVR or other microcontroller and drives multiple seven segment displays
PB5 SCK
PB4MISO
PB3MOSI
PB2SS
#include <SPI.h>
[Type text]
Microprocessor & Microcontroller (3141008)
Activity #1: Find out any one application of interfacing IO device with Arduino using SPI protocol.
Draw its circuit diagram (Connection diagram) and write code for it.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Activity #2: Find out any one application of interfacing sensor with Arduino using I2C protocol.
Draw its circuit diagram (Connection diagram) and write code for it.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 13
AIM: Write Arduino program to receive IR Signal from IR remote and
operate Electrical device based on switch pressed.
Objectives:
Write program to receive IR code transmitted by IR Remote
Understand TSOP 1738 sensor
Understand how to operate electrical device with Arduino board using relay.
Program:
/* This program detects types of IR Remote
* Tuning is required for different remote.
* Assuming that devices are connected at PD4,PD5,PD6 and PD7
* IR Sensor connected at PD2*/
#include <IRremote.h>
const int RECV_PIN = 2;
const int DEVICE1=4;
const int DEVICE2=5;
const int DEVICE3=6;
const int DEVICE4=7;
const int POWERON=8;
int myflag=0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
irrecv.blink13(true);
pinMode(DEVICE1,OUTPUT);
pinMode(DEVICE2,OUTPUT);
pinMode(DEVICE3,OUTPUT);
pinMode(DEVICE4,OUTPUT);
pinMode(POWERON,OUTPUT);
digitalWrite(DEVICE1,LOW); /* If common anode then HIGH */
digitalWrite(DEVICE2,LOW);
digitalWrite(DEVICE3,LOW);
digitalWrite(DEVICE4,HIGH);
digitalWrite(POWERON,HIGH);
Serial.println("IR Remote testing Program: ");
}
void loop() {
if (irrecv.decode(&results)) {
if (results.decode_type == NEC) {
Serial.print("NEC: ");
} else if (results.decode_type == SONY) {
Serial.print("SONY: ");
} else if (results.decode_type == RC5) {
Serial.print("RC5: ");
} else if (results.decode_type == RC6) {
Serial.print("RC6: ");
} else if (results.decode_type == UNKNOWN) {
Serial.print("UNKNOWN: ");
}
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
/* This code is for Philips Remote
if(results.value==0x2FD48B7)
Serial.println("POWER ON BUTTON PRESSED");
if(results.value==0x2FD807F)
Serial.println("1 is pressed");
if(results.value==0x2FD40BF)
Serial.println("2 is pressed");
if(results.value==0x2FDC03F)
Serial.println("3 is pressed");
if(results.value==0x2FD20DF)
Serial.println("4 is pressed");*/
/* This code is for remote provided in Workshop*/
if(results.value==0x80C)
{
Serial.println("POWER ON BUTTON PRESSED");
digitalWrite(POWERON,LOW);
myflag=~myflag;
if(!myflag)
{
digitalWrite(DEVICE1,HIGH);
digitalWrite(DEVICE2,HIGH);
digitalWrite(DEVICE3,HIGH);
digitalWrite(DEVICE4,LOW);
digitalWrite(POWERON,LOW);
}
}
if(results.value==0x801)
{
Serial.println("1 is pressed");
digitalWrite(DEVICE1,HIGH);
digitalWrite(DEVICE2,LOW);
digitalWrite(DEVICE3,LOW);
}
if(results.value==0x802)
{
Serial.println("2 is pressed");
digitalWrite(DEVICE1,LOW);
digitalWrite(DEVICE2,HIGH);
digitalWrite(DEVICE3,LOW);
}
if(results.value==0x803)
{
Serial.println("3 is pressed");
digitalWrite(DEVICE1,LOW);
digitalWrite(DEVICE2,LOW);
digitalWrite(DEVICE3,HIGH);
}
if(results.value==0x804)
{
Serial.println("4 is pressed");
digitalWrite(DEVICE4,LOW);
}
}
}
[Type text]
Microprocessor & Microcontroller (3141008)
EXPERIMENT NO. 14
AIM : Students will construct Mini Project circuit on AVR Microcontroller using Arduino
Developement Board or General Purpose developement Board
and write report about it.
Title:____________________________________________
Components : _______________________
_______________________
_______________________
_______________________
_______________________
_______________________
_______________________
Circuit Diagram :
Program Code :
[Type text]
Microprocessor & Microcontroller (3141008)