0% found this document useful (0 votes)
41 views5 pages

"LCD.H": Main (Init - LCD Display - String )

The documents contain C code for displaying graphics on an LCD screen using an AVR microcontroller. Document 1 displays "Hello World" on the screen. Document 2 draws a filled yellow rectangle. Document 3 animates a filled yellow square that bounces around the screen within bounds. Document 4 controls movement of a green rectangle using button inputs. Document 5 combines elements of documents 3 and 4, animating both a bouncing square and user-controlled rectangle simultaneously on the screen.

Uploaded by

justme8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views5 pages

"LCD.H": Main (Init - LCD Display - String )

The documents contain C code for displaying graphics on an LCD screen using an AVR microcontroller. Document 1 displays "Hello World" on the screen. Document 2 draws a filled yellow rectangle. Document 3 animates a filled yellow square that bounces around the screen within bounds. Document 4 controls movement of a green rectangle using button inputs. Document 5 combines elements of documents 3 and 4, animating both a bouncing square and user-controlled rectangle simultaneously on the screen.

Uploaded by

justme8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1)

#include <avr/io.h>
#include "lcd.h"
int main()
{
init_lcd();
display_string("Hello World");
}

2)
#include <avr/io.h>
#include "lcd.h"

int main()
{
init_lcd();
rectangle shape= {20,220, 110,200};
fill_rectangle (shape, YELLOW);
}

3)
#include <avr/io.h>
#include "lcd.h"
#include <util/delay.h>
#define speed 1

int main()
{
init_lcd();
int top=160;
int bottom=165;
int left=180;
int right=185;
int v=speed;
int h=speed;
rectangle square= {left, right, top, bottom};
while(1)
{
while ((left>=0&&right<=239)&&(top>=0&&bottom<=319))
{
top+=v;
bottom+=v;
left+=h;
right+=h;
rectangle square= {left, right, top, bottom };
fill_rectangle(square, YELLOW);
_delay_ms(1);
fill_rectangle(square, BLACK);
}
if (top<=0)
{v=speed;}
if (bottom>=319)
{v=-speed;}
if (left<=0)
{h=speed;}
if (right>=239)
{h=-speed;}
top+=v;
bottom+=v;
left+=h;
right+=h;
}
}

4)
#include <avr/io.h>
#include "lcd.h"
#include <util/delay.h>
#define speed 1
int main()
{
DDRB=0x00;
PORTB|=_BV(0);
PORTB|=_BV(1);
int J,K;
int A = PINB;
init_lcd();
int t=309;
int b=319;
int l=0;
int r=30;
rectangle shape= {l, r, t, b};
fill_rectangle(shape, GREEN);
while(1)
{
K=((A &_BV(0))|(A&_BV(1)));
if ((J==0 && K==1 )||(J==3 && K==2 ))
{
l+=30;
r+=30;
if(r>=239)
{
l=209;
r=239;
}
}
else if ((J==0 && K==2 )||(J==3 && K==1 ))
{
l-=30;
r-=30;
if(l<=0)
{
l=0;
r=30;
}
}
rectangle shape= {l, r, t, b};
fill_rectangle(shape, GREEN);
J=K;
A=PINB;
_delay_ms(1);
fill_rectangle(shape, BLACK);
}
}

5) #include <avr/io.h>
#include "lcd.h"
#include <util/delay.h>
#define speed 1

int main()
{
DDRB=0x00;
PORTB|=_BV(0);
PORTB|=_BV(1);
int J,K;
int A = PINB;
init_lcd();
int top=160;
int bottom=165;
int left=180;
int right=185;
int t=309;
int b=319;
int l=100;
int r=150;
int v=speed;
int h=speed;
rectangle shape= {l, r, t, b};
while(1)
{
while ((left>=0&&right<=239)&&(top>=0&&bottom<=309))
{
top+=v;
bottom+=v;
left+=h;
right+=h;
rectangle square= {left, right, top, bottom };
rectangle shape= {l, r, t, b};
fill_rectangle(shape, GREEN);
fill_rectangle(square, YELLOW);
J=K;
A=PINB;
_delay_ms(5);
K=((A &_BV(0))|(A&_BV(1)));
fill_rectangle(shape, BLACK);
fill_rectangle(square, BLACK);
if ((J==0 && K==1 )||(J==3 && K==2 ))
{
l+=30;
r+=30;
if(r>=239)
{
l=189;
r=239;

}
}
else if ((J==0 && K==2 )||(J==3 && K==1 ))
{
l-=30;
r-=30;
if(l<=0)
{
l=0;
r=50;
}
}
}
if (top<=0)
{v=speed;}
else if (left<=0)
{h=speed;}
else if (right>=239)
{h=-speed;}
else if (bottom>=309)
{
if(right>=l && left<=r)
{v=-speed;}
else
{clear_screen();
display_string("Game Over");
_delay_ms(500);
main();}
}
top+=v;
bottom+=v;
left+=h;
right+=h;
rectangle square= {left, right, top, bottom };
}
}

You might also like