Belicht_001.c


1
#include <avr/io.h>
2
#include <stdint.h>
3
#include <avr/signal.h>
4
#include <avr/delay.h>
5
#include <avr/interrupt.h>
6
7
void unterprogramm();
8
void zeit_t2_1s();
9
10
SIGNAL(SIG_OVERFLOW2);
11
SIGNAL(SIG_OVERFLOW0);
12
13
uint8_t x[10],j[13], i, t, d1,d2,d3;
14
int main (void)
15
{
16
  DDRA = 0b11111111;
17
  DDRB = 0b00000111;
18
  DDRD = 0b00000000;
19
20
  TCCR0=0x04;  //Vorteiler auf 256 festlegen (8000000 / 255 / 256 = 8,1ms)
21
  TCNT0=0;  //Startwert auf 0 setzen
22
  TIMSK = 1;
23
24
25
  TCCR2=0x05;  //Vorteiler auf 1024 festlegen (8000000 / 1024 = 7812,5 / 8Bit = 30)
26
  TCNT2=0;  //Startwert auf 0 setzen
27
  TIMSK = 64;
28
29
  sei();
30
  
31
  i = 0;
32
  t = 0;
33
34
  x[1] = 0b00000110;  //Zahl 1
35
  x[2] = 0b01011011;  //Zahl 2
36
  x[3] = 0b01001111;  //Zahl 3
37
  x[4] = 0b01100110;  //Zahl 4
38
  x[5] = 0b01101101;  //Zahl 5
39
  x[6] = 0b11111101;   //Zahl 6
40
  x[7] = 0b00000111;  //Zahl 7
41
  x[8] = 0b11111111;  //Zahl 8
42
  x[9] = 0b11101111;  //Zahl 9
43
  x[0] = 0b10111111;  //Zahl 0
44
45
  unterprogramm();
46
}
47
48
49
void unterprogramm()
50
{
51
  uint8_t i,k[5];  
52
53
  k[1]= 0b00000001;
54
  k[2]= 0b00000010;
55
  k[3]= 0b00000100;
56
57
  
58
  for(;;)
59
  {    
60
      j[1]= x[d1];    //Stelle 1
61
      j[3]= x[d2];    //Stelle 2  
62
      j[2]= x[d3];    //Stelle 3
63
    
64
    for (i=1;i<=3;i++)
65
    {    
66
      PORTA = j[i];
67
    //  _delay_us(10);
68
      PORTB = k[i];      
69
    }
70
  }  
71
}
72
73
void zaehler()
74
{
75
  if(t==50)
76
  {
77
    if(d1 == 9)
78
    {
79
      d2++;
80
      d1 = 0;
81
      
82
    }
83
    else
84
    {
85
      d1++;
86
      
87
    }
88
    if(d2 == 6)
89
    {
90
      d3++;
91
      d2 = 0;
92
    }
93
    if(d3==9 && d2 == 5 && d3 == 9)
94
    {
95
      d1 = 0;
96
      d2 = 0;
97
      d3 = 0;
98
    }
99
    t=0;
100
  }
101
  else
102
  {
103
    zeit_t2_1s();
104
  }
105
}
106
107
void zeit_t2_1s()
108
{
109
  t++;
110
}
111
112
113
114
SIGNAL(SIG_OVERFLOW2)  
115
{
116
  zaehler();  
117
}
118
119
SIGNAL(SIG_OVERFLOW0)
120
{
121
  if (PIND & (1<<PIND4))
122
  {
123
    d1 = 0;
124
    d2 = 0;
125
    d3 = 0;  
126
  }
127
  
128
}