Программа:
Спойлер
Код: Выделить всё
//Date : 16.03.2014
//Chip type : ATtiny13
//Clock frequency : 9,600000 MHz
#include <tiny13.h>
bit old_SA1, SA1;
long unsigned int counter;
unsigned char data;
flash long unsigned int number[]= {32955,65909,98864,131819,164774,197729,230684,263639};
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// опрос позиции
old_SA1= SA1;
SA1= PINB.2;
if(old_SA1 && !SA1)
{
PORTB.4= 0; // при достижении позиции останавливаем двигатель
//опрос кнопок
data= 4*PINB.3 + 2*PINB.0 + PINB.1;
// старт таймера
counter= number[data];
}
// отсчет таймера
if(counter) --counter;
// старт двигателя
if(counter== 1) PORTB.4= 1;
}
void main(void)
{
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Port B initialization
PORTB=0b00001111;
DDRB= 0b00010000;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 9,375 kHz
// Mode: Normal top=FFh
// OC0A output: Disconnected
// OC0B output: Disconnected
TCCR0A=0x00;
TCCR0B=0x05;
TCNT0=0x00;
OCR0A=0x00;
OCR0B=0x00;
// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PCINT0-5: Off
GIMSK=0x00;
MCUCR=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x02;
// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;
ADCSRB=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
};
}И прошивка.
Но думаю у уважаемого Soir'а поинтереснее будет.
- Вложения
-
- timer.hex
- (1.19 КБ) 622 скачивания


