implemented simple function to test peripherals

This commit is contained in:
King Kévin 2013-10-13 11:46:53 +02:00
parent f3b8b2d8e9
commit 76eccc6c3a
2 changed files with 158 additions and 9 deletions

View File

@ -10,24 +10,157 @@
static void ioinit(void)
{
DDRD = (1<<LED); /* set LED pin as output */
uart_init(); /* initialize UART */
/* 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 */
uint8_t i;
char input;
puts("Hello world!");
/* blink LED */
for (i = 0; i < 100; i++) {
PIND |= (1<<LED); /* toggle LED */
_delay_ms(1000);
_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;

View File

@ -1,3 +1,19 @@
#define LED PD6 /* LED port */
/* ports */
#define LED PD6 /* status LED */
#define IR PB0 /* IR receiver */
#define FAN PC5 /* FAN output */
#define PWR_OK PB1 /* ATX power OK */
#define nPS_ON PB2 /* ATX power supply ON switch */
/* LEDs */
#define CH1_1 PC0
#define CH1_2 PC1
#define CH1_3 PC2
#define CH1_4 PC3
#define CH1_5 PC4
#define CH2_1 PD2
#define CH2_2 PD3
#define CH2_3 PD4
#define CH2_4 PD5
#define CH2_5 PD7
static void ioinit(void);