読者です 読者をやめる 読者になる 読者になる

arduinoのdigitalWriteっぽい関数を作る.

#include <avr/io.h>

#define HIGH 1
#define LOW 0

int main(void)
{
	write_pin("A1", HIGH);

	while(1);
}

void write_pin(char *chr, int d)
{
	if(d==HIGH){
		if(*chr == 'A'){
			PORTA |= (1<<(chr[1]-'0'));
		}else if(*chr == 'B'){
			PORTB |= (1<<(chr[1]-'0'));
		}else if(*chr == 'C'){
			PORTC |= (1<<(chr[1]-'0'));
		}else if(*chr == 'D'){
			PORTD |= (1<<(chr[1]-'0'));
		}
	}else{
		if(*chr == 'A'){
			PORTA &= (~(1<<(chr[1]-'0')));
		}else if(*chr == 'B'){
			PORTB &= (~(1<<(chr[1]-'0')));
		}else if(*chr == 'C'){
			PORTC &= (~(1<<(chr[1]-'0')));
		}else if(*chr == 'D'){
			PORTD &= (~(1<<(chr[1]-'0')));
		}
	}
}