나는지 가르쳐주실수 있으시겠습니까?
자동문으로써 버튼을 누르면 움직이고 또는 센서에 닿으면 움직이는 시스템입니다
#include <avr/io.h>
void _delay_ms(unsigned int m)
{
unsigned int i,j;
for(i=0;i<m;i++)
for(j=0;j<1200;j++);
}//16MHz:1msec
void rotation()
{ unsigned int j=1;
PORTB = 0x60;
_delay_ms(j);
PORTB = 0x20;
_delay_ms(j);
PORTB = 0x30;
_delay_ms(j);
PORTB = 0x10;
_delay_ms(j);
PORTB = 0x90;
_delay_ms(j);
PORTB = 0x80;
_delay_ms(j);
PORTB = 0xC0;
_delay_ms(j);
PORTB = 0x40;
_delay_ms(j);
}
void rerotation()
{ unsigned int j=1;
PORTB = 0x40;
_delay_ms(j);
PORTB = 0xC0;
_delay_ms(j);
PORTB = 0x80;
_delay_ms(j);
PORTB = 0x90;
_delay_ms(j);
PORTB = 0x10;
_delay_ms(j);
PORTB = 0x30;
_delay_ms(j);
PORTB = 0x20;
_delay_ms(j);
PORTB = 0x60;
_delay_ms(j);
}
int main(void)
{
unsigned int r=0;
DDRB = 0xFF; //포트 B 출력
DDRD = 0x00; //포트 D 입력
DDRF = 0X00;
PORTB = 0x00; // 초기화
PORTD = 0X00;
PORTF = 0X00;
_delay_ms(100);
while(1)
{
if((PIND & 0X04)==4||(PINF & 0X02)==2)
{
while((PIND & 0X08)==0)
{
rotation();
r++;
}
_delay_ms(2000);
while(r>0 )
{
r--;
rerotation();
}
}
}
}
복잡해 저리치워