/*
* 7seg count.c
*
* Created: 08-02-2019 10:19:22
* Author : Rakeshkumar
*/
#include <avr/io.h> //header to enable data flow control over pins #define F_CPU 16000000 //telling controller crystal frequency attached #include <util/delay.h> //header to enable delay function in program int main(void) { DDRB = 0x00; // Taking portB as input port DDRA = 0xff; //taking porta as output port DDRD = 0b11111111; //taking portd as output int DISPLAY1 [10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67}; //character display values from 0-9 int c = 0; int one = 0; //memory for storing ones place value int ten =0; //memory for storing tens place value int hun = 0; int temp = 0; int PRESSED = 0; int PRESSED_CONFIDENTIAL_LEVEL = 0; //int RELEASED_CONFIDENTIAL_LEVEL =0; while(1) { if(bit_is_clear(PINB,0)) //when button one is pressed { PRESSED_CONFIDENTIAL_LEVEL++; if(PRESSED_CONFIDENTIAL_LEVEL > 80) { if(PRESSED == 0 && c >= 0 && c < 999) { c++; } PRESSED_CONFIDENTIAL_LEVEL = 0; } } if(bit_is_clear(PINB,1)) //when button one is pressed { PRESSED_CONFIDENTIAL_LEVEL++; if(PRESSED_CONFIDENTIAL_LEVEL > 80) { if(PRESSED == 0 && c <= 999 && c > 0) { c--; } PRESSED_CONFIDENTIAL_LEVEL = 0; } } hun = c/100; temp = c%100; ten = temp/10; one = temp%10; PORTD &=~(1<<PIND6); PORTA = DISPLAY1[one]; _delay_ms(1); PORTD |=(1<<PIND6); PORTD &=~(1<<PIND5); PORTA = DISPLAY1[ten]; _delay_ms(1); PORTD |=(1<<PIND5); PORTD &= ~(1<<PIND4); PORTA = DISPLAY1[hun]; _delay_ms(1); PORTD |= (1<<PIND4); } }