From 62fabba1faff9133a7a307369a3d2eb4752ee74c Mon Sep 17 00:00:00 2001 From: bartool Date: Fri, 16 May 2025 23:17:57 +0200 Subject: [PATCH] leds test --- src/defs.h | 37 +++++++++++++++++++++++++++++++++++++ src/main.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/defs.h diff --git a/src/defs.h b/src/defs.h new file mode 100644 index 0000000..c197beb --- /dev/null +++ b/src/defs.h @@ -0,0 +1,37 @@ +#pragma once + +#define LED12_SW_PIN PB2 +#define LED12_SW_DDR DDRB +#define LED12_SW_PORT PORTB + +#define LED34_SW_PIN PA7 +#define LED34_SW_DDR DDRA +#define LED34_SW_PORT PORTA + +#define LED_PWM_PIN PA6 +#define LED_PWM_DDR DDRA +#define LED_PWM_PORT PORTA + +#define PROBE_OUT_PIN PB1 +#define PROBE_OUT_DDR DDRB +#define PROBE_OUT_PORT PORTB + +#define ESTOP_OUT_PIN PB0 +#define ESTOP_OUT_DDR DDRB +#define ESTOP_OUT_PORT PORTB + +#define PROBE_INT_PIN PA0 +#define PROBE_INT_DDR DDRA +#define PROBE_INT_PORT PORTA + +#define ESTOP_IN_PIN PA1 +#define ESTOP_IN_DDR DDRA +#define ESTOP_IN_PORT PORTA + +#define CONN_EXT_PIN PA2 +#define CONN_EXT_DDR DDRA +#define CONN_EXT_PORT PORTA + +#define PROBE_EXT_PIN PA3 +#define PROBE_EXT_DDR DDRA +#define PROBE_EXT_PORT PORTA \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1199e48..eab3ed8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,11 +1,56 @@ +#define __DELAY_BACKWARD_COMPATIBLE__ #include +#include +#include +#include "defs.h" + +void led_pwm(void); int main(void) { - // Main loop + LED12_SW_DDR |= (1 << LED12_SW_PIN); + LED34_SW_DDR |= (1 << LED34_SW_PIN); + + // LED12_SW_PORT |= (1 << LED12_SW_PIN); + // LED34_SW_PORT |= (1 << LED34_SW_PIN); + led_pwm(); + + // uint8_t i = 0; while (1) { - // Do nothing + if (PINA & (1 << PROBE_INT_PIN)) + { + LED12_SW_PORT |= (1 << LED12_SW_PIN); + LED34_SW_PORT |= (1 << LED34_SW_PIN); + } + else + { + LED12_SW_PORT &= ~(1 << LED12_SW_PIN); + LED34_SW_PORT &= ~(1 << LED34_SW_PIN); + } + + if (!(PINA & (1 << ESTOP_IN_PIN))) + { + TCCR1A &= ~(1 << COM1A1); // Wyłącz PWM + LED_PWM_PORT &= ~(1 << LED_PWM_PIN); + } + else + { + TCCR1A |= (1 << COM1A1); // Włącz PWM + // LED_PWM_PORT |= (1 << LED_PWM_PIN); + } } return 0; +} +void led_pwm(void) +{ + // Ustaw pin PB1 (OC1A) jako wyjście + LED_PWM_DDR |= (1 << LED_PWM_PIN); + + // Ustaw Timer1 w trybie Fast PWM, 8-bit (WGM13:0 = 0b0101) + TCCR1A = (1 << COM1A1) | (1 << WGM10); // Clear OC1A on compare match + TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // Prescaler 64 + + // Ustaw wartość w rejestrze OCR1A (wypełnienie PWM) + OCR1A = 2; // 50% wypełnienia (dla 8-bit: 128/255) } \ No newline at end of file