Вт окт 16, 2018 21:42:39
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/delay.h>
typedef unsigned char byte;
unsigned char trig, count;
unsigned short pushtime;
SIGNAL(SIG_INTERRUPT0)
{
disable_int0();
}
int main()
{
count = 0;
while(1)
{
if ((PINB & (1<<PB1))==0)
{
pushtime++;
if ( pushtime>15)
{
pushtime=0;
while ((PINB & (1<<PB1))==0)
{
delay_ms(10);
}
sleep_power_down();
}
}
else
{
if (pushtime>2 & pushtime<=15)
{
PORTB |= _BV(PB2);
delay_ms(500);
PORTB &= ~_BV(PB2);
delay_ms(100);
PORTB |= _BV(PB2);
delay_ms(500);
PORTB &= ~_BV(PB2);
}
pushtime=0;
}
if(count==10)
{
PORTB |= _BV(PB0);
}
if (count==20)
{
PORTB &= ~_BV(PB0);
count=0;
}
count++;
delay_ms(100);
}
}
avr-gcc.exe -mmcu=attiny13 -o "./Debug.elf" "main.o"
main.o: In function `main':
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:35: undefined reference to `delay_ms'
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:37: undefined reference to `sleep_power_down'
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:46: undefined reference to `delay_ms'
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:48: undefined reference to `delay_ms'
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:50: undefined reference to `delay_ms'
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:67: undefined reference to `delay_ms'
main.o: In function `__vector_1':
C:\Users\nikollor\AppData\Local\Temp\d2d5e583d4a14410bb8265b98c3f5f3c\ATtiny13\Debug/../main.c:13: undefined reference to `disable_int0'
make: *** [Debug.elf] Error 1
Error code 2
Ср окт 17, 2018 05:29:50
Ср окт 17, 2018 13:41:45
#define F_CPU 1000000UL
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <util/delay.h>
typedef unsigned char byte;
unsigned int trig, count;
unsigned short pushtime;
ISR(PCINT0_vect) //мигаем лампочкой sleep
{
PORTB &= ~_BV(PB4);
_delay_ms(100);
PORTB |= _BV(PB4);
_delay_ms(200);
PORTB &= ~_BV(PB4);
_delay_ms(100);
PORTB |= _BV(PB4);
_delay_ms(200);
PORTB &= ~_BV(PB4);
}
int main()
{
DDRB=0b00011101;
PORTB=0b00000010;
count = 0;
while(1)
{
if ((PINB & (1<<PB1))==0)
{
pushtime++;
if ( pushtime>15) //длинное нажатие - уход в сон
{
pushtime=0;
while ((PINB & (1<<PB1))==0)
{
_delay_ms(10);
}
PORTB |= _BV(PB4); //все лампочки выключаем, лампочку sleep включаем
PORTB &= ~_BV(PB2);
PORTB &= ~_BV(PB0);
GIMSK |= (1<<PCIE); // Enable Pin Change Interrupts
PCMSK |= (1 << PB1);
sei ();
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable ();
sleep_cpu ();
sleep_disable ();
cli ();
}
_delay_ms(10);
}
else
{
if (pushtime>2 & pushtime<=15) //короткое нажатие
{
PORTB |= _BV(PB2); //мигаем лампочкой кнопки
_delay_ms(500);
PORTB &= ~_BV(PB2);
_delay_ms(100);
PORTB |= _BV(PB2);
_delay_ms(500);
PORTB &= ~_BV(PB2);
}
pushtime=0;
}
if(count==10) //перемигиваемся светодиодом "работа"
{
PORTB |= _BV(PB0);
}
if (count>=20)
{
PORTB &= ~_BV(PB0);
count=0;
}
count++;
_delay_ms(100);
}
}