#include <mega8.h>
#include <delay.h>
#include <LCDlib.h>
#define T1 PINC.1
#define UP PINC.2
#define DOWN PINC.3
#define Licht PORTD.4
#define CR 0x0D
bit Taste, Flanke, Merker, RUN;
bit UP_OLD, DOWN_OLD;
unsigned char count;
interrupt [TIM2_OVF] void timer2_ovf_isr(void) // Timer 2 overflow interrupt service routine
{
Licht = 0;
}
interrupt [TIM2_COMP] void timer2_comp_isr(void)// Timer 2 output compare interrupt service routine
{
if (RUN)
Licht = 1;
}
void InitSFRs();
void main(void)
{
InitSFRs();
#asm("sei")
while (1)
{
// Flankenerkennung für Licht EIN/AUS
Taste = !T1;
delay_ms(30);
Taste &= !T1;
Flanke = Taste & !Merker;
Merker = Taste;
if (Flanke)
RUN = !RUN;
// Flankenerkennung für Erhöhung der Helligkeit
if (!UP && UP_OLD)
{
if (count<10)
{
count ++;
}
}
UP_OLD = UP;
delay_ms(10);
// Flankenerkennung für Verringerung der Helligkeit
if (!DOWN && DOWN_OLD)
{
if (count>0)
{
count --;
}
}
DOWN_OLD = DOWN;
delay_ms(10);
} // while
} // main
void InitSFRs()
{
// Portkonfiguaration
DDRC = 0x30;
PORTC = 0x0E;
DDRD = 0x10;
PORTD = 0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 500,000 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x04;
TCNT2=0x00;
OCR2=0x80;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0xC0;
}
Lesezeichen