#include <mega8.h>
#include <alcd.h>
#include <delay.h>
#include <stdio.h>
#define ddr DDRD
#define port PORTD
#define pin PIND
#define pin_a 0
#define pin_b 1
#define pin_1 3
#define pin_2 4
#define pin_3 5
#define pin_4 6
#define pin_5 7
unsigned char number = 5;
char str[17];
void main(void)
{
ddr = 0x00;
port = 0xff;
lcd_init(16);
while(1)
{
if(pin == 0xff)
{
sprintf(str, "number = %d", number);
lcd_gotoxy(0,0);
lcd_puts(str);
lcd_gotoxy(0, 1);
lcd_puts("makan:A B C D E");
}
else if(!(pin & (1<<pin_a)))
{
delay_ms(100);
if((!(pin & (1<<pin_a))) && (pin_b>0))
{
delay_ms(100);
number--;
}
}
else if(!(pin & (1<<pin_b)))
{
delay_ms(100);
if((!(pin & (1<<pin_b))) && (pin_a<5))
{
number++;
}
}
else if(!(pin & (1<<pin_1)))
{
delay_ms(100);
if(!(pin & (1<<pin_1)))
{
lcd_gotoxy(6, 1);
lcd_puts(" ");
}
}
else if(!(pin & (1<<pin_2)))
{
delay_ms(100);
if(!(pin & (1<<pin_2)))
{
lcd_gotoxy(7, 1);
lcd_puts(" ");
}
}
else if(!(pin & (1<<pin_3)))
{
delay_ms(100);
if(!(pin & (1<<pin_3)))
{
lcd_gotoxy(9, 1);
lcd_puts(" ");
}
}
else if(!(pin & (1<<pin_4)))
{
delay_ms(100);
if(!(pin & (1<<pin_4)))
{
lcd_gotoxy(11, 1);
lcd_puts(" ");
}
}
else
{
delay_ms(100);
if(!(pin & (1<<pin_5)))
{
lcd_gotoxy(13, 1);
lcd_puts(" ");
}
}
}
}