# include<iom128v.h>
# include<macros.h>
# define uint unsigned int
# define uchar unsigned char
uchar up_data[8]={0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9};
uchar down_data[8]={0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8};
uchar up_flag=0;
uchar down_flag=0;
uchar stop_flag=0;
uchar rate;
# define beep_0 (PORTB=PORTB&0x7f)
# define beep_1 (PORTB=PORTB|0x80)
void Delay_ms(uint xms)
{
int i,j;
for(i=0;i<xms;i++)
{for(j=0;j<1140;j++);}
}
void port_init(void)
{
DDRC=0x33;
PORTC=0xff;
DDRD=0x0e;
PORTD=0xff;
DDRB=0x04;
PORTB=0xff;
}
void beep()
{
beep_0;
Delay_ms(100);
beep_1;
Delay_ms(100);
}
void motor_up()
{
uchar i;
for(i=0;i<8;i++)
{
PORTC=up_data[i];
Delay_ms(30);
}
}
void motor_down()
{
uchar i;
for(i=0;i<8;i++)
{
PORTC=down_data[i];
Delay_ms(30);
}
}
main()
{
port_init();
while(1)
{
if((PORTD&0x01)==0)
{
Delay_ms(01);
if((PORTD&0x10)==0)
{
up_flag=1;
down_flag=0;
stop_flag=0;
beep();
}
}
if((PORTD&0x02)==0)
{
Delay_ms(10);
if((PORTD&0x02)==0)
{
down_flag=1;
up_flag=0;
stop_flag=0;
beep();
}
}
if((PORTD&0x04)==0)
{
Delay_ms(10);
if((PORTD&0x04)==0)
{
stop_flag=1;
up_flag=0;
down_flag=0;
beep();
}
}
if(up_flag==1)motor_up();
if(down_flag==1)motor_down();
if(stop_flag==1)PORTC=0x00;
}
}
# include<macros.h>
# define uint unsigned int
# define uchar unsigned char
uchar up_data[8]={0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1,0xf9};
uchar down_data[8]={0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8};
uchar up_flag=0;
uchar down_flag=0;
uchar stop_flag=0;
uchar rate;
# define beep_0 (PORTB=PORTB&0x7f)
# define beep_1 (PORTB=PORTB|0x80)
void Delay_ms(uint xms)
{
int i,j;
for(i=0;i<xms;i++)
{for(j=0;j<1140;j++);}
}
void port_init(void)
{
DDRC=0x33;
PORTC=0xff;
DDRD=0x0e;
PORTD=0xff;
DDRB=0x04;
PORTB=0xff;
}
void beep()
{
beep_0;
Delay_ms(100);
beep_1;
Delay_ms(100);
}
void motor_up()
{
uchar i;
for(i=0;i<8;i++)
{
PORTC=up_data[i];
Delay_ms(30);
}
}
void motor_down()
{
uchar i;
for(i=0;i<8;i++)
{
PORTC=down_data[i];
Delay_ms(30);
}
}
main()
{
port_init();
while(1)
{
if((PORTD&0x01)==0)
{
Delay_ms(01);
if((PORTD&0x10)==0)
{
up_flag=1;
down_flag=0;
stop_flag=0;
beep();
}
}
if((PORTD&0x02)==0)
{
Delay_ms(10);
if((PORTD&0x02)==0)
{
down_flag=1;
up_flag=0;
stop_flag=0;
beep();
}
}
if((PORTD&0x04)==0)
{
Delay_ms(10);
if((PORTD&0x04)==0)
{
stop_flag=1;
up_flag=0;
down_flag=0;
beep();
}
}
if(up_flag==1)motor_up();
if(down_flag==1)motor_down();
if(stop_flag==1)PORTC=0x00;
}
}