74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
|
/*
|
||
|
* Door.cpp
|
||
|
*
|
||
|
* Created: 04.09.2014 22:06:23
|
||
|
* Author: netz
|
||
|
*/
|
||
|
|
||
|
#define F_CPU 8000000
|
||
|
#include <avr/io.h>
|
||
|
#include <util/delay.h>
|
||
|
|
||
|
void Init_AIN()
|
||
|
{
|
||
|
// Analog Comparator initialization
|
||
|
// Analog Comparator: On
|
||
|
// The Analog Comparator's positive input is
|
||
|
// connected to the AIN0 pin
|
||
|
// The Analog Comparator's negative input is
|
||
|
// connected to the AIN1 pin
|
||
|
// Analog Comparator Input Capture by Timer/Counter 1: Off
|
||
|
ACSR=(0<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
|
||
|
// Digital input buffer on AIN0: Off
|
||
|
// Digital input buffer on AIN1: Off
|
||
|
DIDR=(1<<AIN0D) | (1<<AIN1D);
|
||
|
}
|
||
|
|
||
|
void Init_Output()
|
||
|
{
|
||
|
DDRB |= (1<<PINB2);
|
||
|
DDRD |= (1<<PIND5);
|
||
|
}
|
||
|
|
||
|
void Init_Timer()
|
||
|
{
|
||
|
// Timer/Counter 0 initialization
|
||
|
// Clock source: System Clock
|
||
|
// Clock value: 8000,000 kHz
|
||
|
// Mode: Phase correct PWM top=0xFF
|
||
|
// OC0A output: Non-Inverted PWM
|
||
|
// OC0B output: Inverted PWM
|
||
|
// Timer Period: 0,06375 ms
|
||
|
// Output Pulse(s):
|
||
|
// OC0A Period: 0,06375 ms Width: 0,25 us
|
||
|
// OC0B Period: 0,06375 ms Width: 0,06325 ms
|
||
|
TCCR0A=(1<<COM0A1) | (0<<COM0A0) | (1<<COM0B1) | (1<<COM0B0) | (0<<WGM01) | (1<<WGM00);
|
||
|
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (1<<CS00);
|
||
|
TCNT0=0x00;
|
||
|
OCR0A=0x00;
|
||
|
OCR0B=0x00;
|
||
|
}
|
||
|
|
||
|
int main(void)
|
||
|
{
|
||
|
Init_AIN();
|
||
|
Init_Output();
|
||
|
Init_Timer();
|
||
|
while(1)
|
||
|
{
|
||
|
if(ACSR & (1<<ACO)) {
|
||
|
if(OCR0A != 0) {
|
||
|
OCR0A--;
|
||
|
OCR0B--;
|
||
|
_delay_ms(1);
|
||
|
}
|
||
|
} else {
|
||
|
if(OCR0A != 0xFF) {
|
||
|
OCR0A++;
|
||
|
OCR0B++;
|
||
|
_delay_ms(6);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|