Created
May 14, 2012 13:41
-
-
Save t3hk0d3/2694041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#include "uart.h" | |
#include "adc.h" | |
#include "console.h" | |
#define sbi(data, bit) (data) |= _BV(bit) | |
#define cbi(data, bit) (data) &= ~_BV(bit) | |
#define delay(ms) _delay_ms(ms); | |
#define SETPORT(PRT, PIN) sbi(DDR##PRT, pin); \ | |
sbi(PORT##PRT, pin); | |
#define GETPORT(PRT, PIN) cbi(DDR##PRT, pin); | |
#define READPORT(PRT, PN) PIN##PRT & (1 << PN) | |
CONSOLE_HANDLER(setpin) { | |
if (argc < 2) { | |
return; | |
} | |
char* port = strlwr(argv[0]); | |
int pin = atoi(argv[1]); | |
switch (port[0]) { | |
case 'a': | |
SETPORT(A, pin); | |
break; | |
case 'b': | |
SETPORT(B, pin); | |
break; | |
case 'c': | |
SETPORT(C, pin); | |
break; | |
case 'd': | |
SETPORT(D, pin); | |
break; | |
default: | |
printf("Unknown port!\n"); | |
return; | |
break; | |
} | |
printf("[set] Port %c set!\n", port[0]); | |
} | |
int main() { | |
uart_init(); | |
adc_init(); | |
console_init(); | |
CONSOLE_REGISTER(setpin); | |
printf("=== Initialized ===\n"); | |
while (1) { | |
console_process(&uart_console); | |
delay(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment