void err(unsigned int id, char *str) { transmit_str(STDERR, str); _terminate(id); }
int main( void ) { system_init(); lcd_init(); uart_init(); timer_init(); DDRA_Bit3=1; PORTA_Bit3=0; __enable_interrupt(); write_str(" Traffic counter Nagy Krisztina 2013"); d_1s(); d_1s(); d_1s(); ptr_lcd=0; write_str("People IN: "); write_str(" "); write_str("Total traffic: "); write_str(" "); while(1) { if(flag1==1) { timer1=1000; flag1=0; } if(flag2==1) { timer2=1000; flag2=0; } if((timer1>0 && timer2>0) && (timer2 > timer1)) { people_in++; people_all++; flag1=0; flag2=0; timer1=0; timer2=0; /*write to LCD*/ write_num_on_lcd(); } if((timer1>0 && timer2>0) && (timer1 > timer2)) { if(people_in) { people_in--; } flag1=0; flag2=0; timer1=0; timer2=0; /*write to LCD*/ write_num_on_lcd(); } if(flag_button1==1) { people_in=0; write_num_on_lcd(); flag_button1=0; } if(flag_button2==1) { transmit_str("Number of people in the room:"); transmit_char(lcd[16]); transmit_char(lcd[17]); transmit_char(lcd[18]); transmit_char(lcd[19]); transmit_char((char)13); transmit_str("Total traffic:"); transmit_char(lcd[36]); transmit_char(lcd[37]); transmit_char(lcd[38]); transmit_char(lcd[39]); transmit_char((char)13); flag_button2=0; } } }
int main(void) { DDRB=0x00; USART_Init(51); TCCR1B=0x04; // setting falling edge trigger(bit 6) and pre-scaler to 256 long int a,b,c,x,duty,rise,fal,tot; while(1) { TCNT1=0; // this detects the first falling edge while(!(TIFR&(1<<ICF1))); TCCR1B|=0x40; // setting rising edge triggering TIFR|=(1<<ICF1); // reseting input capture flag // here we detecting rising edge while(!(TIFR&(1<<ICF1))); TIFR|=(1<<ICF1); // reseting input capture flag TCCR1B&=0x0f; // setting falling edge triggering a=ICR1; // saving value of ICR1(TCNT1 stored at edge trigger) in variable // here we detecting falling edge while(!(TIFR&(1<<ICF1))); TIFR|=(1<<ICF1); // reseting input capture flag TCCR1B|=0x40; // setting rising edge triggering b=ICR1; // here we detecting rising edge while(!(TIFR&(1<<ICF1))); TIFR|=(1<<ICF1); // reseting input capture flag TCCR1B&=0x0f; // setting falling edge triggering c=ICR1; // we are using rising falling rising format with variables as a b c respectively tot=c-a; rise=b-a; fal=c-b; duty=(rise*100)/tot; transmit_str("duty rate:"); x=(duty/10)+48; USART_Transmit(x); x=(duty%10)+48; USART_Transmit(x); USART_Transmit('%'); USART_Transmit(' '); USART_Transmit(' '); rise=rise*32000; transmit_str("Rise time: 0."); x=(rise/100000000)+48; USART_Transmit(x); rise=rise%100000000; x=(rise/10000000)+48; USART_Transmit(x); rise=rise%10000000; x=(rise/1000000)+48; USART_Transmit(x); rise=rise%1000000; x=(rise/100000)+48; USART_Transmit(x); rise=rise%100000; x=(rise/10000)+48; USART_Transmit(x); rise=rise%10000; x=(rise/1000)+48; USART_Transmit(x); rise=rise%1000; x=(rise/100)+48; USART_Transmit(x); rise=rise%100; x=(rise/10)+48; USART_Transmit(x); x=(rise%10)+48; USART_Transmit(x); transmit_str("sec"); USART_Transmit(' '); USART_Transmit(' '); fal=fal*32000; transmit_str("Fall time: 0."); x=(fal/100000000)+48; USART_Transmit(x); fal=fal%100000000; x=(fal/10000000)+48; USART_Transmit(x); fal=fal%10000000; x=(fal/1000000)+48; USART_Transmit(x); fal=fal%1000000; x=(fal/100000)+48; USART_Transmit(x); fal=fal%100000; x=(fal/10000)+48; USART_Transmit(x); fal=fal%10000; x=(fal/1000)+48; USART_Transmit(x); fal=fal%1000; x=(fal/100)+48; USART_Transmit(x); fal=fal%100; x=(fal/10)+48; USART_Transmit(x); x=(fal%10)+48; USART_Transmit(x); transmit_str("sec"); USART_Transmit(' '); USART_Transmit(' '); } }