leds test

This commit is contained in:
2025-05-16 23:17:57 +02:00
parent 6097fce596
commit 62fabba1fa
2 changed files with 84 additions and 2 deletions

37
src/defs.h Normal file
View File

@@ -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

View File

@@ -1,11 +1,56 @@
#define __DELAY_BACKWARD_COMPATIBLE__
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "defs.h"
void led_pwm(void);
int main(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) 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; 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)
} }