Aayush Awasthi
Junior Member level 2
how to use 4 lcd animation character at a time in a program at different location
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include<avr/io.h>
#include<util/delay.h>
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTD
void lcd_string(char*);
void lcd_config();
void lcd_cmd(unsigned char );
void lcd_data(unsigned char);
void animation1();
void animation2();
void animation3();
void animation4();
int main()
{
DDRD=0xFF;
lcd_config();
lcd_cmd(0x01);
_delay_ms(1000);
while(1)
{
lcd_cmd(0x85);
lcd_string("HAPPY");
lcd_data(0);
animation1();
_delay_ms(1);
animation2();
_delay_ms(1);
animation3();
_delay_ms(1);
lcd_data(3);
lcd_cmd(0xc1);
animation4();
lcd_cmd(0xc2);
lcd_string("ANNIVERSARY");
lcd_data(0);
animation4();
_delay_ms(100);
}
return 0;
}
void animation1()
{
lcd_cmd(0x40);
lcd_data(0b00000001);
lcd_data(0b00000001);
lcd_data(0b00000001);
lcd_data(0b00000111);
lcd_data(0b00001111);
lcd_data(0b00011111);
lcd_data(0b00001111);
lcd_data(0b00000011);
}
void animation2()
{
lcd_cmd(0x48);
lcd_data(0b00010000);
lcd_data(0b00010000);
lcd_data(0b00010000);
lcd_data(0b00011100);
lcd_data(0b00011110);
lcd_data(0b00011111);
lcd_data(0b00011110);
lcd_data(0b00011000);
}
void animation3()
{
lcd_cmd(0x50);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
}
void animation4()
{
lcd_cmd(0x60);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
}
void lcd_string(char *str)
{
unsigned int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
}
/* for(i=0;i<=50;i++)
{
lcd_cmd(0x1E);
_delay_ms(100);
}*/
}
void lcd_config()
{
int i=0;
lcd_cmd(0x02);
lcd_cmd(0x06);
lcd_cmd(0x28);
lcd_cmd(0x0C);
for(i=0;i<=50;i++)
{
lcd_cmd(0x1E);
_delay_ms(10);
}
}
void lcd_cmd(unsigned char x)
{
LCD=x&0xF0;
LCD&=~(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
LCD=(x<<4)&0xF0;
LCD&=~(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
}
void lcd_data(unsigned char y)
{
LCD=y&0xF0;
LCD|=(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
LCD=(y<<4)&0xF0;
LCD|=(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
}
#include<avr/io.h>
#include<util/delay.h>
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD PORTD
void lcd_string(char*);
void lcd_config();
void lcd_cmd(unsigned char );
void lcd_data(unsigned char);
void animation1();
void animation2();
void animation3();
void animation4();
int main()
{
DDRD=0xFF;
lcd_config();
lcd_cmd(0x01);
_delay_ms(10);
while(1)
{
lcd_cmd(0x85);
lcd_string("HAPPY");
lcd_cmd(0xc2);
lcd_string("ANNIVERSARY");
animation1();
_delay_ms(1);
animation2();
_delay_ms(1);
animation3();
_delay_ms(1);
animation4();
//lcd_data(0);
animation4();
_delay_ms(100);
}
return 0;
}
void animation1()
{
lcd_data(0);
lcd_cmd(0x64);
lcd_data(0b00000001);
lcd_data(0b00000001);
lcd_data(0b00000001);
lcd_data(0b00000111);
lcd_data(0b00001111);
lcd_data(0b00011111);
lcd_data(0b00001111);
lcd_data(0b00000011);
}
void animation2()
{
lcd_data(0);
lcd_cmd(0x72);
lcd_data(0b00010000);
lcd_data(0b00010000);
lcd_data(0b00010000);
lcd_data(0b00011100);
lcd_data(0b00011110);
lcd_data(0b00011111);
lcd_data(0b00011110);
lcd_data(0b00011000);
}
void animation3()
{
lcd_data(0);
lcd_cmd(0x80);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
lcd_data(0b00000011);
}
void animation4()
{
lcd_data(0);
lcd_cmd(0x88);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
lcd_data(0b00011000);
}
void lcd_string(char *str)
{
unsigned int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
}
/* for(i=0;i<=50;i++)
{
lcd_cmd(0x1E);
_delay_ms(100);
}*/
}
void lcd_config()
{
int i=0;
lcd_cmd(0x02);
lcd_cmd(0x06);
lcd_cmd(0x28);
lcd_cmd(0x0C);
for(i=0;i<=50;i++)
{
lcd_cmd(0x1E);
_delay_ms(10);
}
}
void lcd_cmd(unsigned char x)
{
LCD=x&0xF0;
LCD&=~(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
LCD=(x<<4)&0xF0;
LCD&=~(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
}
void lcd_data(unsigned char y)
{
LCD=y&0xF0;
LCD|=(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
LCD=(y<<4)&0xF0;
LCD|=(1<<LCD_RS);
LCD&=~(1<<LCD_RW);
LCD|=(1<<LCD_EN);
_delay_ms(1);
LCD&=~(1<<LCD_EN);
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 #include <avr/io.h> #define F_OSC 4000000 #include <util/delay.h> #define _LCD_RETURN_HOME 0x02 #define LCD_RS 0 #define LCD_RW 1 #define LCD_EN 2 #define LCD PORTD void LCD_Out(char*); void LCD_Init(); void LCD_Cmd(unsigned char); void LCD_Chr(unsigned char); void CustomChar(char pos_row, char pos_char); const char characterAnim[4][8] = { {1,1,1,7,15,31,15,3}, {16,16,16,28,30,31,30,24}, {3,3,3,3,3,3,3,3}, {24,24,24,24,24,24,24,24} }; void CustomChar(char pos_row, char pos_char){ unsigned char i, j = 0, value; for(j = 0; j < 4; j++){ LCD_Cmd(64 + (j * 8)); for (i = 0; i <= 7; i++) Lcd_Chr(characterAnim[j][i]); LCD_Cmd(_LCD_RETURN_HOME); switch(pos_row){ case 1: value = 0x80 + pos_char; break; case 2: value = 0xC0 + pos_char; break; case 3: value = 0x94 + pos_char; break; case 4: value = 0xD4 + pos_char; break; }; Lcd_Cmd(value); _delay_ms(250); } } void LCD_Init(){ int i = 0; LCD_Cmd(0x02); LCD_Cmd(0x06); LCD_Cmd(0x28); LCD_Cmd(0x0C); for(i=0; i <= 50; i++){ LCD_Cmd(0x1E); _delay_ms(10); } } void LCD_Cmd(unsigned char x){ LCD = x & 0xF0; LCD &= ~(1 << LCD_RS); LCD &= ~(1 << LCD_RW); LCD |= (1 << LCD_EN); _delay_ms(1); LCD &= ~(1 << LCD_EN); LCD = (x << 4) & 0xF0; LCD &= ~(1 << LCD_RS); LCD &= ~(1 << LCD_RW); LCD |= (1 << LCD_EN); _delay_ms(1); LCD &= ~(1 << LCD_EN); } void LCD_Chr(unsigned char y){ LCD = y & 0xF0; LCD |= (1 << LCD_RS); LCD &= ~(1 << LCD_RW); LCD |= (1 << LCD_EN); _delay_ms(1); LCD& = ~(1 << LCD_EN); LCD = (y << 4) & 0xF0; LCD |= (1 << LCD_RS); LCD &= ~(1 << LCD_RW); LCD |= (1 << LCD_EN); _delay_ms(1); LCD &= ~(1 << LCD_EN); } void LCD_Out(char *str){ unsigned int i = 0; while(*str) { LCD_Chr(*str++); } } int main() { DDRD = 0xFF; PORTD = 0x00; LCD_Init(); LCD_Cmd(0x80); LCD_Out("Happy"); LCD_Cmd(0xC0); LCD_Out("Anniversary"); while(1){ CustomChar(2, 14); } return 0; }