Пн мар 08, 2021 20:32:49
// пределитель на 1024, (1024*256)/8000000 = 0.032768 мкс
// 1000ms/32,768 = 30тиков = за 1 сек
TCCR0 = (1 << CS02) | (1 << CS00);
TIMSK = (1 << TOIE0);
TCNT0 = 256;
// пределитель на 1
TCCR1A = (1 << COM1B1) | (1 << WGM11);
TCCR1B = (1 << CS10) | 0x19;
ICR1 = 256; // frequency = 8000000/256 = 31.129 kHz,
Пн мар 08, 2021 20:56:00
Пн мар 08, 2021 21:00:29
Пн мар 08, 2021 21:03:13
Пн мар 08, 2021 21:05:51
Пн мар 08, 2021 21:17:25
Пн мар 08, 2021 21:30:42
ISR (TIMER0_OVF_vect) {
static uint8_t conterTimer = 0;
static uint8_t long_counter = 0;
static uint8_t short_counter = 0;
static uint8_t press_long = 0;
static uint8_t press_short = 0;
static uint8_t c = 0;
c++;
if (button_pressed ()) {
if (conterTimer < 255) conterTimer++;
if (conterTimer == 40) {
long_counter++;
if (press_long == 0) {
press_long = 1;
}
conterTimer = 0;
}
} else {
if ((conterTimer > 0) && (conterTimer < 22)) {
short_counter++;
if (press_short == 0) {
press_short = 1;
}
conterTimer = 0;
press_long = 0;
}
}
send_putc(13);
send_str("ON: ");
send_int(long_counter);
send_putc(13);
if (short_counter == 5) short_counter = 0;
if (long_counter == 3) long_counter = 0;
TCNT0 = 256;
}
Пн мар 08, 2021 21:36:48
Пн мар 08, 2021 21:40:04
Пн мар 08, 2021 21:44:46
Пн мар 08, 2021 21:49:46
Пн мар 08, 2021 21:50:42
TCNT0 = 256;
Пн мар 08, 2021 21:59:46
Пн мар 08, 2021 22:38:36
Пн мар 08, 2021 22:49:04
поместить двухбайтное число в один байт - это примерно, как в литровую банку налить 2 литра воды.beoro писал(а):TCNT0 = 256;
Пн мар 08, 2021 23:13:25
Вт мар 09, 2021 06:33:52
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "com_io.h"
#include "button_lib.h"
ISR (TIMER0_OVF_vect) {
static uint8_t conterTimer = 0;
static uint8_t long_counter = 0;
static uint8_t short_counter = 0;
static uint8_t press_long = 0;
static uint8_t press_short = 0;
static uint8_t c = 0;
BtnExe();
c++;
// if (button_pressed ()) {
if (BtnGet() == BTN_LONG1) {
if (conterTimer < 255) conterTimer++;
if (conterTimer == 40) {
long_counter++;
if (press_long == 0) {
press_long = 1;
}
conterTimer = 0;
}
} else {
if ((conterTimer > 0) && (conterTimer < 22)) {
short_counter++;
if (press_short == 0) {
press_short = 1;
}
conterTimer = 0;
press_long = 0;
}
}
putchar(13);
printf("ON: ");
printf("long_counter=%d", long_counter);
putchar(13);
if (short_counter == 5) short_counter = 0;
if (long_counter == 3) long_counter = 0;
TCNT0 = 256;
}
int main()
{
// Write your code here
BtnInit();
// пределитель на 1024, (1024*256)/8000000 = 0.032768 мкс
// 1000ms/32,768 = 30тиков = за 1 сек
TCCR0 = (1 << CS02) | (1 << CS00);
TIMSK = (1 << TOIE0);
TCNT0 = 256;
DDRB |= (1<<PINB2);
// пределитель на 1
TCCR1A = (1 << COM1B1) | (1 << WGM11);
TCCR1B = (1 << CS10) | 0x19;
ICR1 = 256; // frequency = 8000000/256 = 31.129 kHz,
OCR1B = 125;
sei();
printf("\nHello, world!\n\r");
while (1)
;
return 0;
}
#define BTN_LONG_TIME 1000 /* время фиксации длинного нажатия в милисекундах (1000 - 2500) */
ON: long_counter=0
Program: 2058 bytes
(.text + .data + .bootloader)
Data: 69 bytes
(.data + .bss + .noinit)
Вт мар 09, 2021 10:20:22
Что и требовалось доказать.Dimon456 писал(а): что с ШИМ что без ШИМ
Вт мар 09, 2021 20:00:28
Что и требовалось доказать.Dimon456 писал(а): что с ШИМ что без ШИМ
Вт мар 09, 2021 20:04:09