Skip to content

Instantly share code, notes, and snippets.

@t3hk0d3
Created May 14, 2012 13:41
Show Gist options
  • Save t3hk0d3/2694041 to your computer and use it in GitHub Desktop.
Save t3hk0d3/2694041 to your computer and use it in GitHub Desktop.
#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