2015-02-26 11:19:10 +01:00
|
|
|
/* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2015-02-28 13:21:33 +01:00
|
|
|
|
2015-02-26 11:19:10 +01:00
|
|
|
#include <stdint.h> // Standard Integer Types
|
|
|
|
#include <stdio.h> // Standard IO facilities
|
|
|
|
#include <stdlib.h> // General utilities
|
|
|
|
#include <stdbool.h> // Boolean
|
|
|
|
#include <string.h> // Strings
|
|
|
|
|
|
|
|
#include <avr/io.h> // AVR device-specific IO definitions
|
|
|
|
#include <util/delay.h> // Convenience functions for busy-wait delay loops
|
|
|
|
#include <avr/interrupt.h> // Interrupts
|
|
|
|
#include <avr/wdt.h> // Watchdog timer handling
|
|
|
|
#include <avr/pgmspace.h> // Program Space Utilities
|
|
|
|
#include <avr/sleep.h> // Power Management and Sleep Modes
|
|
|
|
|
|
|
|
#include "uart.h" // basic UART functions
|
|
|
|
#include "main.h" // main definitions
|
|
|
|
|
|
|
|
/* switch off LED */
|
|
|
|
void led_off(void)
|
|
|
|
{
|
2015-02-28 13:21:33 +01:00
|
|
|
LED_PORT &= ~(1<<LED_IO); // remove power to LED
|
2015-02-26 11:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* switch on LED */
|
|
|
|
void led_on(void)
|
|
|
|
{
|
2015-02-28 13:21:33 +01:00
|
|
|
LED_PORT |= (1<<LED_IO); // provide power to LED
|
2015-02-26 11:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* toggle LED */
|
|
|
|
void led_toggle(void)
|
|
|
|
{
|
2015-02-28 13:21:33 +01:00
|
|
|
LED_PIN |= (1<<LED_IO);
|
2015-02-26 11:19:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* disable watchdog when booting */
|
|
|
|
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
|
|
|
|
void wdt_init(void)
|
|
|
|
{
|
|
|
|
MCUSR = 0;
|
|
|
|
wdt_disable();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize GPIO */
|
|
|
|
void io_init(void)
|
|
|
|
{
|
|
|
|
/* use UART as terminal */
|
|
|
|
uart_init();
|
|
|
|
stdout = &uart_output;
|
|
|
|
stdin = &uart_input;
|
|
|
|
|
|
|
|
/* gpio */
|
|
|
|
/* LED */
|
2015-02-28 13:21:33 +01:00
|
|
|
LED_DDR |= (1<<LED_IO); // LED is driven by pin (set as output)
|
2015-02-26 11:19:10 +01:00
|
|
|
led_off();
|
|
|
|
|
|
|
|
sei(); /* enable interrupts */
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
io_init(); // initialize IOs
|
|
|
|
|
|
|
|
while (true) { // endless loop for micro-controller
|
2015-02-26 13:55:25 +01:00
|
|
|
/* blinking LED example */
|
|
|
|
led_toggle();
|
|
|
|
_delay_ms(500);
|
2015-02-26 11:19:10 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|