UHR.c
#include <stdio.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include <math.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h> //interrupts einbeziehen
#define LCD_DDR DDRB
void delay_ms(unsigned int period);
extern const prog_uint8_t Font1[], Font2[];
extern const prog_uint16_t *Bitmap;
volatile uint16_t seconds;
//volatile uint8_t minutes
//volatile uint8_t hours
ISR(TIMER0_OVF_vect) //Wenn Interrupt von Timer0 ausgelöst wird mache folgendes:
{
seconds++;
}
void starten(void)
{
ASSR |= (1<<AS0); //Timer0 asynchron mit Externen Quarz an TOSC1/TOSC2
TCCR0 |= ((1<<CS02) | (1<<CS00)); //Vorteiler von Timer0 auf 128 --> ergibt 256hz Takt
TIMSK |= (1<<TOIE0); //Interrupt für timer0 aktivieren wenn overflow (wenn 255 im Zähler erreicht)
}
int main(void)
{
char str[] = "123";
DDRD = 0x00; //Port D als Ausgang
PORTD = 0xff; //alle Pullup von D aktiv
sei(); //Interrupts aktivieren
starten();
LCD_Init();
PORTB |= (1<<PB7); // Pin B.7 Ausgang und high für Displaybeleuchtung
Orientation = Portrait180;
LCD_Cls(blue);
delay_ms(1000);
LCD_Print("Soweit so gut hehe", 1, 60, 1, 1, 1, white, black);
delay_ms(1000);
LCD_Cls(black);
while(1)
{
if(PD_7 == 0)
{
LCD_Print("WOHO", 1, 70, 1, 1, 1, white, black);
}
if(PD_4 == 0)
{
LCD_Print("WOHO", 30, 20, 1, 1, 1, white, black);
}
if(PD_1 == 0) //Displaybeleuchtung mit taste D1 ausschalten
{
PORTB &= ~(1<<PB7);
}
if(PD_6 == 0) //Displaybeleuchtung mit taste D6 einschalten
{
PORTB |= (1<<PB7);
}
if(PD_5 == 0) //Display reset
{
LCD_Cls(black);
}
LCD_Print("Nichts los....", 1, 60, 1, 1, 1, white, black);
sprintf(str,"sekunde %d ",(int) seconds);
LCD_Print(str, 0, 20, 1, 1, 1, white, black);
}
return 0;
}
// Enhanced delay-routine (wait) as as the standard delay routine (_delay_ms) is not able to delay
// more than 17 ms maximum as of the used 8-bit-timer (depending on used crystal)
void delay_ms(uint16_t period) //delay routine (milliseconds)
{
for(unsigned int i=0; i<=period; i++)
_delay_ms(1);
}