Expt-1
1.
Title: Interface 16X2 LCD using 8 data
pin
2.
Components
required:
Sl. No.
|
Category
|
Item name/value
|
Quantity
|
1
|
IC
|
ATMEGA32
|
1
|
2
|
7805
|
1
|
|
3
|
Resistor
|
10K
|
1
|
4
|
330R
|
1
|
|
5
|
Capacitor
|
0.1uf
|
2
|
6
|
22pf
|
2
|
|
7
|
10uf, 24Volt
|
1
|
|
8
|
Crystal Oscillator
|
16MHz
|
1
|
9
|
LCD
|
16X2
|
1
|
10
|
Battery
|
9Volt
|
1
|
3.
Procedure
& code:
#ifndef F_CPU
#define F_CPU
16000000UL
#endif
#include <avr/io.h>
#include <stdlib.h>
#include <util/delay.h>
#define E 5
//giving name “enable” to 5 pin of PORTD, since it Is connected to LCD enable
pin
#define RS 6
//giving name “registerselection” to 6 pin of PORTD, since is connected to LCD
RS pin
void send_a_command(unsigned
char command);
void send_a_character(unsigned
char character);
void send_a_string(char
*string_of_characters);
int main()
{
int keypressed=0;
char buffer[10];
DDRD |= 1<<RS;//set
PD6 as output pin
DDRD |= 1<<E;//
set PD5 as output pin
send_a_command(0x01);
//Clear Screen 0x01 = 00000001
_delay_ms(50);
send_a_command(0x38);//telling
lcd we are using 8bit command /data mode
_delay_ms(50);
send_a_command(0b00001111);//LCD
SCREEN ON and courser blinking
send_a_string("Working
for 16X2");//displaying a string
send_a_command(0x80
+ 0x40 +0);// moving courser to second line of LCD
_delay_ms(50);
keypressed=1234;
itoa(keypressed,buffer,10);
send_a_string(buffer);
send_a_command(0x80
+0);//move courser to first line.
_delay_ms(50);
send_a_command(0x01);
//Clear Screen 0x01 = 00000001
return(0);
}
void send_a_command(unsigned
char command)
{
PORTB = command;
PORTD &=
~ (1<<RS); //putting 0 in RS to tell lcd we are sending command
PORTD |= 1<<E;
//telling lcd to receive command /data at the port
_delay_ms(50);
PORTD &=
~1<<E;//telling lcd we completed sending data
PORTB= 0;
}
void send_a_character(unsigned
char character)
{
PORTB= character;
PORTD |= 1<<RS;//telling
LCD we are sending data not commands
PORTD |= 1<<E;//telling
LCD to start receiving command/data
_delay_ms(50);
PORTD &=
~1<<E;//telling lcd we completed sending data/command
PORTB = 0;
}
void send_a_string(char
*string_of_characters)
{
while(*string_of_characters
> 0)
{
send_a_character(*string_of_characters++);
}
}
4.
Circuit:
5.
Simulation:
Expt-2
1.
Title: Interface 16X2 LCD using 4 data
pin
2.
Components
required:
Sl. No.
|
Category
|
Item name/value
|
Quantity
|
1
|
IC
|
ATMEGA32
|
1
|
2
|
7805
|
1
|
|
3
|
Resistor
|
10K
|
1
|
4
|
330R
|
1
|
|
5
|
Capacitor
|
0.1uf
|
2
|
6
|
22pf
|
2
|
|
7
|
10uf, 24Volt
|
1
|
|
8
|
Crystal Oscillator
|
16MHz
|
1
|
9
|
LCD
| 16X2 |
1
|
10
|
Battery
|
9Volt
|
1
|
3.
Procedure
& code:
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
int main()
{
char buffer[10];
uint8_t rpm=30,d=0,duty;
lcd_init(LCD_DISP_ON_CURSOR);// initialize LCD
do
{
if(rpm>90)
{
rpm=30;
}
duty=rpm;
lcd_clrscr();// Clear screen
lcd_gotoxy(0,0);// goto 1st line 1st column
_delay_ms(50);
lcd_puts("RPM=");
itoa(rpm,buffer,10); //buffer loaded with RPM variable value
lcd_puts(buffer); //display RPM value
_delay_ms(50);
lcd_clrscr();// Clear screen
lcd_gotoxy(0,1);// goto 2nd line 1st column
lcd_puts(" Duty=");
d=((duty*100)/255); //percentage of rpm calculated as duty cycle
itoa(d,buffer,10); //buffer is loaded with duty cycle value
lcd_puts(buffer); //display duty cycle valu
lcd_puts("%");
_delay_ms(50);
rpm+=10;
} while (1);
return(0);
}
4.
Circuit:
5.
Simulation:
No comments:
Post a Comment