Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #define delay(x) _delay_ms(x)
- #define delayMicroseconds(x) _delay_us(x)
- static void pinMode(int pin, int setting) {
- if (pin >= 0 && pin <= 7) {
- if (setting > 0) { // Set to OUTPUT
- DDRD |= (1<<pin);
- } else { // Set to INPUT
- DDRD &= ~(1<<pin);
- }
- } else if (pin >= 8 && pin <= 13) {
- if (setting > 0) { // Set to OUTPUT
- DDRC |= (1<<pin);
- } else { // Set to INPUT
- DDRC &= ~(1<<pin);
- }
- }
- return;
- }
- static void analogWrite(int pin, int data) { return; }
- static int analogRead(int pin) { return 0; }
- static void digitalWrite(int pin, int data) {
- if (pin >= 0 && pin <= 7) {
- if (data > 0) { // Set to HIGH
- PORTD |= (1<<pin);
- } else { // Set to LOW
- PORTD &= ~(1<<pin);
- }
- } else if (pin >= 8 && pin <= 13) {
- if (data > 0) { // Set to HIGH
- PORTC |= (1<<pin);
- } else { // Set to LOW
- PORTC &= ~(1<<pin);
- }
- }
- }
- static int digitalRead(int pin) {
- if (pin >= 0 && pin <= 7) {
- return PIND & (1<<pin);
- } else if (pin >= 8 && pin <= 13) {
- return PINC & (1<<pin);
- } else {
- return 0;
- }
- }
- static void serial_init(int baud) {
- // Set baud rate
- unsigned int bittimer = F_CPU / baud / 16;
- UBRR0H = (unsigned char) (bittimer >> 8);
- UBRR0L = (unsigned char) bittimer;
- // Set framing to 8N1
- UCSR0C = (3 << UCSZ00);
- UCSR0B = (1 << RXEN0) | (1 << TXEN0);
- return;
- }
- static void serial_write(unsigned char c) {
- while ( !(UCSR0A & (1 << UDRE0)) )
- ;
- UDR0 = c;
- return;
- }
- static void serial_print(char *str) {
- int i = 0;
- while (1) {
- serial_write(str[i++])
- if (str[i] == '\0') { // NUL termination
- break;
- }
- }
- return;
- }
- int main(void) {
- setup();
- while(1)
- loop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement