backinblack
26.03.2013, 13:55
Hi, habe mich heute ein bisschen an meinen avr gesetzt und möchste stupide die Uhrzeit über 4 7-segment Anzeigen darstellen.
Funktioniert soweit auch Problemlos, nur ist momentan der Zeitgeber eine For-Schleife die den Millisekunden takt vorgibt und das will ich mit interrupts lösen finde nur leider nicht anfang. Wäre über eine kleine Hilfestellung froh!
Vielleicht hat ja jemand lust sich kurz in meinen code reinzudenken.
gruß Daniel.
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
int i,min2,min,millisecond,hour;
void zeith(void)
{
switch(hour) //stunden
{
case 0: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 1: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD2)|(1<<PD7)|(1<<PD3);break;
case 2: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD0)|(1<<PD1)|(1<<PD3);break;
case 3: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 4: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD5)|(1<<PD4)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 5: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 6: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD0)|(1<<PD3);break;
case 7: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 8: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 9: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 10: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 11: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD2)|(1<<PD7)|(1<<PD3);break;
case 12: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD0)|(1<<PD1)|(1<<PD3);break;
case 13: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 14: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD5)|(1<<PD4)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 15: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 16: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD0)|(1<<PD3);break;
case 17: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 18: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 19: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 20: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 21: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD2)|(1<<PD7)|(1<<PD3);break;
case 22: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD0)|(1<<PD1)|(1<<PD3);break;
case 23: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
}
}
void zeits(void)
{
switch(min) //minuten ziffern
{
case 9: DDRA=(1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
case 0: DDRA=(1<<PA2)|(1<<PA7);break;
case 1: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA4)|(1<<PA0)|(1<<PA1);break;
case 2: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA4)|(1<<PA2)|(1<<PA1);break;
case 3: DDRA=(1<<PA5)|(1<<PA4)|(1<<PA7)|(1<<PA2);break;
case 4: DDRA=(1<<PA6)|(1<<PA5)|(1<<PA4)|(1<<PA2)|(1<<PA1);break;
case 5: DDRA=(1<<PA6)|(1<<PA5)|(1<<PA4)|(1<<PA2)|(1<<PA1)|(1<<PA0);break;
case 6: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA2);break;
case 7: DDRA=(1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
case 8: DDRA=(1<<PA1)|(1<<PA2)|(1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
}
}
void zeits2(void)
{
switch(min2) //minuten ganze zahlen
{
case 5: DDRC=(1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
case 0: DDRC=(1<<PC2)|(1<<PC7);break;
case 1: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC4)|(1<<PC0)|(1<<PC1);break;
case 2: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC4)|(1<<PC2)|(1<<PC1);break;
case 3: DDRC=(1<<PC5)|(1<<PC4)|(1<<PC7)|(1<<PC2);break;
case 4: DDRC=(1<<PC6)|(1<<PC5)|(1<<PC4)|(1<<PC2)|(1<<PC1);break;
case 9: DDRC=(1<<PC6)|(1<<PC5)|(1<<PC4)|(1<<PC2)|(1<<PC1)|(1<<PC0);break;
case 6: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC2);break;
case 7: DDRC=(1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
case 8: DDRC=(1<<PC1)|(1<<PC2)|(1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
}
}
int main(void)
{
zeits(); // stellen der uhrzeit
min=1; // minuten ziffern
zeits2();
min2=3; // minuten ganze zahlen
zeith();
hour=12; // stunden
while(1)
{
for(i=0;i <= 1000; i++) // das ist der millisekunden zähler der durch interrupt´abgelöst werden soll
{millisecond++;
_delay_ms(1);
if(millisecond == 50) // hier läuft die uhr
{
zeits();
min++;
millisecond = 0;
}
if(min == 10)
{
min=0;
zeits2();
min2++;
}
if(min2 == 6)
{
min2=0;
zeith();
hour++;
}
if(hour == 24)
{
min=0;
min2=0;
hour=0;
}
}
}
}
Funktioniert soweit auch Problemlos, nur ist momentan der Zeitgeber eine For-Schleife die den Millisekunden takt vorgibt und das will ich mit interrupts lösen finde nur leider nicht anfang. Wäre über eine kleine Hilfestellung froh!
Vielleicht hat ja jemand lust sich kurz in meinen code reinzudenken.
gruß Daniel.
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <inttypes.h>
int i,min2,min,millisecond,hour;
void zeith(void)
{
switch(hour) //stunden
{
case 0: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 1: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD2)|(1<<PD7)|(1<<PD3);break;
case 2: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD0)|(1<<PD1)|(1<<PD3);break;
case 3: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 4: DDRB=(1<<PB0)|(1<<PB1)|(1<<PB2)|(1<<PB5)|(1<<PB6)|(1<<PB7);DDRD=(1<<PD5)|(1<<PD4)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 5: DDRB=(1<<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);break;
case 15: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
case 16: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD5)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD0)|(1<<PD3);break;
case 17: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD2)|(1<<PD3);break;
case 18: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 19: DDRB=(1<<PB2)|(1<<PB7);DDRD=(1<<PD1)|(1<<PD2)|(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 20: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD5)|(1<<PD6)|(1<<PD7)|(1<<PD3);break;
case 21: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD2)|(1<<PD7)|(1<<PD3);break;
case 22: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD0)|(1<<PD1)|(1<<PD3);break;
case 23: DDRB=(1<<PB6)|(1<<PB7)|(1<<PB4)|(1<<PB0)|(1<<PB1);DDRD=(1<<PD6)|(1<<PD7)|(1<<PD4)|(1<<PD2)|(1<<PD1)|(1<<PD3);break;
}
}
void zeits(void)
{
switch(min) //minuten ziffern
{
case 9: DDRA=(1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
case 0: DDRA=(1<<PA2)|(1<<PA7);break;
case 1: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA4)|(1<<PA0)|(1<<PA1);break;
case 2: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA4)|(1<<PA2)|(1<<PA1);break;
case 3: DDRA=(1<<PA5)|(1<<PA4)|(1<<PA7)|(1<<PA2);break;
case 4: DDRA=(1<<PA6)|(1<<PA5)|(1<<PA4)|(1<<PA2)|(1<<PA1);break;
case 5: DDRA=(1<<PA6)|(1<<PA5)|(1<<PA4)|(1<<PA2)|(1<<PA1)|(1<<PA0);break;
case 6: DDRA=(1<<PA6)|(1<<PA7)|(1<<PA2);break;
case 7: DDRA=(1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
case 8: DDRA=(1<<PA1)|(1<<PA2)|(1<<PA4)|(1<<PA5)|(1<<PA6)|(1<<PA7);break;
}
}
void zeits2(void)
{
switch(min2) //minuten ganze zahlen
{
case 5: DDRC=(1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
case 0: DDRC=(1<<PC2)|(1<<PC7);break;
case 1: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC4)|(1<<PC0)|(1<<PC1);break;
case 2: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC4)|(1<<PC2)|(1<<PC1);break;
case 3: DDRC=(1<<PC5)|(1<<PC4)|(1<<PC7)|(1<<PC2);break;
case 4: DDRC=(1<<PC6)|(1<<PC5)|(1<<PC4)|(1<<PC2)|(1<<PC1);break;
case 9: DDRC=(1<<PC6)|(1<<PC5)|(1<<PC4)|(1<<PC2)|(1<<PC1)|(1<<PC0);break;
case 6: DDRC=(1<<PC6)|(1<<PC7)|(1<<PC2);break;
case 7: DDRC=(1<<PC0)|(1<<PC1)|(1<<PC2)|(1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
case 8: DDRC=(1<<PC1)|(1<<PC2)|(1<<PC4)|(1<<PC5)|(1<<PC6)|(1<<PC7);break;
}
}
int main(void)
{
zeits(); // stellen der uhrzeit
min=1; // minuten ziffern
zeits2();
min2=3; // minuten ganze zahlen
zeith();
hour=12; // stunden
while(1)
{
for(i=0;i <= 1000; i++) // das ist der millisekunden zähler der durch interrupt´abgelöst werden soll
{millisecond++;
_delay_ms(1);
if(millisecond == 50) // hier läuft die uhr
{
zeits();
min++;
millisecond = 0;
}
if(min == 10)
{
min=0;
zeits2();
min2++;
}
if(min2 == 6)
{
min2=0;
zeith();
hour++;
}
if(hour == 24)
{
min=0;
min2=0;
hour=0;
}
}
}
}