hello freaks,
I just got into Timer/counter programming, and i'm trying to make a counter circuit using atmega16 and 7-segment.
but i reached to a point where the counting on 7-segment displays doesn't go well.
Here is the code I used and the circuit is attached too:
#define F_CPU 1000000ul #include <avr/io.h> #include <util/delay.h> #define SegOne 0x01 #define SegTwo 0x02 #define SegThree 0x04 int main(void) { TCCR0 |= (1<<CS02) | (1<<CS01); TCCR0 &= ~(1<<CS00); DDRC = 0xff; // Data lines DDRD = 0xff; // Control signal PORTD0-PORTD3 int num,temp; char seg_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; while (1) { num = TCNT0; temp = num / 100; num = num % 100; PORTD = SegOne; PORTC = seg_code[temp]; _delay_ms(1); temp = num / 10; num = num % 10; PORTD = SegTwo; PORTC = seg_code[temp]; _delay_ms(1); temp = num / 1; PORTD = SegThree; PORTC = seg_code[temp]; _delay_ms(1); } }
Can anyone please tell me where is my mistakes?