tak zdroják je:
#define __AVR_ATmega48
//#define OPTIMIZE
/nastaveni pro f_osc 8000000/
#define F_CPU 8000000
#include <avr/io.h>
#include <avr\interrupt.h>
#include <util\Delay.h>
int ba, b, c, d, e, f, g, x, yy;
int setup (void) {
_delay_ms (100);
DDRB=0B11000000;
DDRC=0B00111111;
DDRD=0B01111111;
PORTB=0;
PORTC=0;
PORTD=0;
ba=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
x=0;
}
int zapis (void) {
PORTC=PORTC | 0B00000010;
_delay_ms (100);
}
int zapis1 (void) {
PORTC=PORTC | 0B00000010;
_delay_us (50);
}
int LCD (void) {
PORTC=0B00100100;
zapis ();
_delay_ms (4);
PORTC=0B00100100;
zapis ();
PORTC=0B00100100;
zapis ();
PORTC=0B00100000;
zapis ();
PORTC=0B00100000;
zapis ();
PORTC=0B00010000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00010000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00000100;
zapis();
_delay_ms (1);
PORTC=0B00000000;
zapis ();
PORTC=0B00101000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00011000;
zapis ();
}
int hodiny (void) {
yy=yy++;
if (yy>9) {
ba=ba++;
yy=0;
if (ba>9) {
b=b++;
ba=0;
if (b>5) {
c=c++;
b=0;
if (c>9) {
d=d++;
c=0;
if (d>5) {
e=e++;
g=g++;
d=0;
if (e>9) {
f=f++;
e=0;
if (g>23) {
e=0;
f=0;
g=0;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
int predcisli (void) {
PORTC=37;
zapis1 ();
}
int tabulka_cisel (void) {
switch (x) {
case 0: PORTC=1, zapis1(); break;
case 1: PORTC=5, zapis1(); break;
case 2: PORTC=33, zapis1(); break;
case 3: PORTC=37, zapis1(); break;
case 4: PORTC=9, zapis1(); break;
case 5: PORTC=13, zapis1(); break;
case 6: PORTC=41, zapis1(); break;
case 7: PORTC=45, zapis1(); break;
case 8: PORTC=17, zapis1(); break;
case 9: PORTC=21, zapis1(); break;
}
}
int dvojtecka (void) {
predcisli();
PORTC=49;
zapis1();
}
int zobrazeni_hodin (void) {
// ADRESA 04h nastavení začátku
PORTC=0B00010000;
zapis1 ();
PORTC=0B00001000;
zapis1 ();
// zobrazení hodin
x=f;
predcisli();
tabulka_cisel();
x=e;
predcisli();
tabulka_cisel();
dvojtecka ();
x=d;
predcisli();
tabulka_cisel();
x=c;
predcisli();
tabulka_cisel();
dvojtecka ();
x=b;
predcisli();
tabulka_cisel();
x=ba;
predcisli();
tabulka_cisel();
}
int casovac (void) {
TCCR1A |= (1<<WGM11) | (1<<WGM10);
TCCR1B |= (1<<WGM13) | (1<<WGM12);
TCCR1B |= (1<<CS11) | (1<<CS10);
ICR1H=0B00110000;
ICR1L=0B11010011;
TIMSK1 |= 1<<TOIE1;
}
ISR (TIMER1_OVF_vect) {
TIFR1=0;
hodiny ();
}
int main() {
setup ();
LCD ();
_delay_ms(1000);
//casovac ();
do {
hodiny();
_delay_ms(100);
zobrazeni_hodin ();
}
while(1);
}
mám to napojení na LCD displej. hodiny() - počítá čas teď to přez zpoždění _delay_ms(100) to mi funguje
A teď jsem chtěl přičítat do hodin() když mi to skočí do přerušení. To mi ale nefunguje
#define __AVR_ATmega48
//#define OPTIMIZE
/nastaveni pro f_osc 8000000/
#define F_CPU 8000000
#include <avr/io.h>
#include <avr\interrupt.h>
#include <util\Delay.h>
int ba, b, c, d, e, f, g, x, yy;
int setup (void) {
_delay_ms (100);
DDRB=0B11000000;
DDRC=0B00111111;
DDRD=0B01111111;
PORTB=0;
PORTC=0;
PORTD=0;
ba=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
x=0;
}
int zapis (void) {
PORTC=PORTC | 0B00000010;
_delay_ms (100);
}
int zapis1 (void) {
PORTC=PORTC | 0B00000010;
_delay_us (50);
}
int LCD (void) {
PORTC=0B00100100;
zapis ();
_delay_ms (4);
PORTC=0B00100100;
zapis ();
PORTC=0B00100100;
zapis ();
PORTC=0B00100000;
zapis ();
PORTC=0B00100000;
zapis ();
PORTC=0B00010000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00010000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00000100;
zapis();
_delay_ms (1);
PORTC=0B00000000;
zapis ();
PORTC=0B00101000;
zapis ();
PORTC=0B00000000;
zapis ();
PORTC=0B00011000;
zapis ();
}
int hodiny (void) {
yy=yy++;
if (yy>9) {
ba=ba++;
yy=0;
if (ba>9) {
b=b++;
ba=0;
if (b>5) {
c=c++;
b=0;
if (c>9) {
d=d++;
c=0;
if (d>5) {
e=e++;
g=g++;
d=0;
if (e>9) {
f=f++;
e=0;
if (g>23) {
e=0;
f=0;
g=0;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
else return;
}
int predcisli (void) {
PORTC=37;
zapis1 ();
}
int tabulka_cisel (void) {
switch (x) {
case 0: PORTC=1, zapis1(); break;
case 1: PORTC=5, zapis1(); break;
case 2: PORTC=33, zapis1(); break;
case 3: PORTC=37, zapis1(); break;
case 4: PORTC=9, zapis1(); break;
case 5: PORTC=13, zapis1(); break;
case 6: PORTC=41, zapis1(); break;
case 7: PORTC=45, zapis1(); break;
case 8: PORTC=17, zapis1(); break;
case 9: PORTC=21, zapis1(); break;
}
}
int dvojtecka (void) {
predcisli();
PORTC=49;
zapis1();
}
int zobrazeni_hodin (void) {
// ADRESA 04h nastavení začátku
PORTC=0B00010000;
zapis1 ();
PORTC=0B00001000;
zapis1 ();
// zobrazení hodin
x=f;
predcisli();
tabulka_cisel();
x=e;
predcisli();
tabulka_cisel();
dvojtecka ();
x=d;
predcisli();
tabulka_cisel();
x=c;
predcisli();
tabulka_cisel();
dvojtecka ();
x=b;
predcisli();
tabulka_cisel();
x=ba;
predcisli();
tabulka_cisel();
}
int casovac (void) {
TCCR1A |= (1<<WGM11) | (1<<WGM10);
TCCR1B |= (1<<WGM13) | (1<<WGM12);
TCCR1B |= (1<<CS11) | (1<<CS10);
ICR1H=0B00110000;
ICR1L=0B11010011;
TIMSK1 |= 1<<TOIE1;
}
ISR (TIMER1_OVF_vect) {
TIFR1=0;
hodiny ();
}
int main() {
setup ();
LCD ();
_delay_ms(1000);
casovac ();
do {
_delay_ms(10);
zobrazeni_hodin ();
}
while(1);
}