Split LED functionality in seperate headers/sources
This commit is contained in:
parent
3fc7ad4c8d
commit
f04723704e
10
include/io.h
10
include/io.h
@ -1,10 +0,0 @@
|
||||
#ifndef PORTS_H
|
||||
#define PORTS_H
|
||||
|
||||
/* DS18B20+ is configured in DS18B20 library */
|
||||
|
||||
/* Signal LEDs */
|
||||
#define LED_1 PD3
|
||||
#define LED_2 PD4
|
||||
|
||||
#endif
|
10
include/led.h
Normal file
10
include/led.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef LED_H
|
||||
#define LED_H
|
||||
|
||||
#define LED_DDR DDRD
|
||||
#define LED_1_BIT PD3
|
||||
#define LED_2_BIT PD4
|
||||
|
||||
void init_leds(void);
|
||||
|
||||
#endif /* LED_H */
|
@ -11,8 +11,6 @@
|
||||
#include "debug.h"
|
||||
#endif /* DEBUG */
|
||||
|
||||
void init_led(void);
|
||||
void read_temp(void);
|
||||
uint16_t read_adc(uint8_t channel);
|
||||
|
||||
#endif
|
||||
|
9
src/led.c
Normal file
9
src/led.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <avr/io.h>
|
||||
#include "common.h"
|
||||
#include "led.h"
|
||||
|
||||
void init_leds(void)
|
||||
{
|
||||
SET(LED_DDR, LED_1_BIT);
|
||||
SET(LED_DDR, LED_2_BIT);
|
||||
}
|
32
src/main.c
32
src/main.c
@ -2,23 +2,10 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include "ds18b20.h"
|
||||
#include "led.h"
|
||||
#include "servos.h"
|
||||
#include "sonar.h"
|
||||
#include "main.h"
|
||||
#include "io.h"
|
||||
|
||||
void init_led(void)
|
||||
{
|
||||
DDRD |= 1 << LED_1;
|
||||
DDRD |= 1 << LED_2;
|
||||
}
|
||||
|
||||
void init_adc(void)
|
||||
{
|
||||
ADCSRA |= 1 << ADPS0 | 1 << ADPS1; // Prescaler = 8 => ADC clock = 125Hz
|
||||
ADMUX |= 1 << REFS0; // AVcc with external cap as reference voltage
|
||||
ADCSRA |= 1 << ADEN | 1 << ADSC;
|
||||
}
|
||||
|
||||
void read_temp(void)
|
||||
{
|
||||
@ -28,29 +15,18 @@ void read_temp(void)
|
||||
for (;;) {
|
||||
d = ds18b20_gettemp();
|
||||
if (d >= 23)
|
||||
SET(PORTD, LED_1);
|
||||
;
|
||||
else
|
||||
CLR(PORTD, LED_1);
|
||||
;
|
||||
|
||||
_delay_ms(500);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t read_adc(uint8_t channel)
|
||||
{
|
||||
ADMUX &= 0xF0;
|
||||
ADMUX |= channel;
|
||||
SET(ADCSRA, ADSC); // Start conversion
|
||||
while (CHK(ADCSRA, ADSC)); // Wait for conversion to finish
|
||||
|
||||
return ADCW;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
init_led();
|
||||
init_leds();
|
||||
init_servos();
|
||||
init_adc();
|
||||
|
||||
run_servos();
|
||||
read_temp();
|
||||
|
Loading…
Reference in New Issue
Block a user