목차
신호등제어
동작순서
설계요소
동작순서
설계요소
본문내용
d port_init(void) //포트 초기화
{
DDRC=0x0F; //C포트를 출력으로 사용
PORTC=0x0F;
}
void int_init(void)
{
TCCR0=0x05; // 5:1024분주
TCNT0=0x62; //0.01sec 마다 리셋 TCNT0=255-(0.01sec*(16Mhz/1024))=98=0x62
TIMSK=1<
}
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=0x62; //0.01sec 마다 리셋
TimeCount++;
}
void main(void)
{
port_init();
int_init();
TimeCount=0; //초기 카운트값
g_out=0x0E; //Green
y_out=0x0B; //Yellow
a_out=0x0C; //Arrow,green
r_out=0x07; //Red
#asm("sei")
while(1)
{
if(TimeCount==0) //초기 신호등
{
PORTC=y_out; //Yellow on
}
if(TimeCount==200) //2초후 (0.01*200=2sec)
{
PORTC=r_out; //Red on
}
if(TimeCount==900) //9초후
{
PORTC=a_out; //Arrow,Green on
}
if(TimeCount==1200) //12초후
{
PORTC=g_out; //Green on
}
if(TimeCount==1400) //14초후
{
TimeCount=0; //Yellow on
}
}
}
6)실제 구동모습
{
DDRC=0x0F; //C포트를 출력으로 사용
PORTC=0x0F;
}
void int_init(void)
{
TCCR0=0x05; // 5:1024분주
TCNT0=0x62; //0.01sec 마다 리셋 TCNT0=255-(0.01sec*(16Mhz/1024))=98=0x62
TIMSK=1<
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=0x62; //0.01sec 마다 리셋
TimeCount++;
}
void main(void)
{
port_init();
int_init();
TimeCount=0; //초기 카운트값
g_out=0x0E; //Green
y_out=0x0B; //Yellow
a_out=0x0C; //Arrow,green
r_out=0x07; //Red
#asm("sei")
while(1)
{
if(TimeCount==0) //초기 신호등
{
PORTC=y_out; //Yellow on
}
if(TimeCount==200) //2초후 (0.01*200=2sec)
{
PORTC=r_out; //Red on
}
if(TimeCount==900) //9초후
{
PORTC=a_out; //Arrow,Green on
}
if(TimeCount==1200) //12초후
{
PORTC=g_out; //Green on
}
if(TimeCount==1400) //14초후
{
TimeCount=0; //Yellow on
}
}
}
6)실제 구동모습
소개글