168 lines
3.3 KiB
C
168 lines
3.3 KiB
C
#include <stdint.h> /* Standard Integer Types */
|
|
#include <stdio.h> /* Standard IO facilities */
|
|
#include <stdlib.h> /* General utilities */
|
|
#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 "main.h"
|
|
#include "uart.h"
|
|
|
|
static void ioinit(void)
|
|
{
|
|
/* configure power */
|
|
DDRB = ~(1<<PWR_OK)|(1<<nPS_ON); /* PWR_OK is input, nPS_ON is output */
|
|
PORTB |= (1<<nPS_ON); /* witch off power supply */
|
|
|
|
/* configure peripherals */
|
|
DDRD |= (1<<LED); /* LED is output */
|
|
DDRB &= ~(1<<IR); /* IR receiver is input */
|
|
DDRC &= ~(1<<FAN); /* FAN is input */
|
|
|
|
/* configure channels (used for powering LEDs using an nMOS) */
|
|
DDRC |= (1<<CH1_1)|(1<<CH1_2)|(1<<CH1_3)|(1<<CH1_4)|(1<<CH1_5); /* CH1_x is output */
|
|
PORTC &= ~((1<<CH1_1)|(1<<CH1_2)|(1<<CH1_3)|(1<<CH1_4)|(1<<CH1_5)); /* switch off CH1_x */
|
|
DDRD |= (1<<CH2_1)|(1<<CH2_2)|(1<<CH2_3)|(1<<CH2_4)|(1<<CH2_5); /* CH2_x is output */
|
|
PORTD &= ~((1<<CH2_1)|(1<<CH2_2)|(1<<CH2_3)|(1<<CH2_4)|(1<<CH2_5)); /* switch off CH2_x */
|
|
|
|
/* use UART as terminal */
|
|
uart_init();
|
|
stdout = &uart_output;
|
|
stdin = &uart_input;
|
|
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
ioinit(); /* initialize IOs */
|
|
|
|
char input;
|
|
|
|
puts("Hello world!");
|
|
_delay_ms(1000);
|
|
while(1) {
|
|
input = getchar();
|
|
printf("%c\n", input);
|
|
switch (input) {
|
|
case 'l':
|
|
PIND |= (1<<LED);
|
|
printf("LED: ");
|
|
if (PIND&(1<<LED)) {
|
|
puts("off");
|
|
} else {
|
|
puts("on");
|
|
}
|
|
break;
|
|
case 'a':
|
|
PINB |= (1<<nPS_ON);
|
|
printf("power supply: ");
|
|
if (PINB&(1<<nPS_ON)) {
|
|
puts("off");
|
|
} else {
|
|
puts("on");
|
|
}
|
|
break;
|
|
case 's':
|
|
printf("power: ");
|
|
if (PINB&(1<<PWR_OK)) {
|
|
puts("ok");
|
|
} else {
|
|
puts("ko");
|
|
}
|
|
break;
|
|
case '1':
|
|
PINC |= (1<<CH1_1);
|
|
printf("CH1_1: ");
|
|
if (PINC&(1<<CH1_1)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '2':
|
|
PINC |= (1<<CH1_2);
|
|
printf("CH1_2: ");
|
|
if (PINC&(1<<CH1_2)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '3':
|
|
PINC |= (1<<CH1_3);
|
|
printf("CH1_3: ");
|
|
if (PINC&(1<<CH1_3)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '4':
|
|
PINC |= (1<<CH1_4);
|
|
printf("CH1_4: ");
|
|
if (PINC&(1<<CH1_4)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '5':
|
|
PINC |= (1<<CH1_5);
|
|
printf("CH1_5: ");
|
|
if (PINC&(1<<CH1_5)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '6':
|
|
PIND |= (1<<CH2_1);
|
|
printf("CH2_1: ");
|
|
if (PIND&(1<<CH2_1)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '7':
|
|
PIND |= (1<<CH2_2);
|
|
printf("CH2_2: ");
|
|
if (PIND&(1<<CH2_2)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '8':
|
|
PIND |= (1<<CH2_3);
|
|
printf("CH2_3: ");
|
|
if (PIND&(1<<CH2_3)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '9':
|
|
PIND |= (1<<CH2_4);
|
|
printf("CH2_4: ");
|
|
if (PIND&(1<<CH2_4)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
case '0':
|
|
PIND |= (1<<CH2_5);
|
|
printf("CH2_5: ");
|
|
if (PIND&(1<<CH2_5)) {
|
|
puts("on");
|
|
} else {
|
|
puts("off");
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|