-
Notifications
You must be signed in to change notification settings - Fork 0
/
7-seg
40 lines (40 loc) · 843 Bytes
/
7-seg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
unsigned char digit[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x83, 0xF8, 0x80, 0x98};
int number;
void display_7seglend(unsigned char *led, unsigned int number){
PORTA = ~led[number];
}
int main(void){
DDRA = 0xFF; DDRC=0xff;
number=2345;
int ch =0;
while (1)
{
int four = number % 10000 / 1000;
int three = number % 1000 / 100;
int two = number % 100 / 10;
int one = number % 10;
if((PIND &= 1<<PD6) && (ch == 0)){
ch=1;
}
else if((PIND &= 1<<PD6) && (ch == 1)){
number++;
_delay_ms(10);
ch=0;
}
if(PIND &= 1<<PD7){
number--;
_delay_ms(10);
}
int num[] = {four, three, two, one};
for(int i=0; i<4; i++){
PORTC = ~(1<<i);
display_7seglend(digit, num[i]);
_delay_ms(10);
}
}
return 0;
}