Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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