mirror of
https://github.com/Kugelschieber/arduino-c.git
synced 2026-01-18 11:00:26 +00:00
Initial commit with basic C code to write to pins.
This commit is contained in:
53
pins.c
Normal file
53
pins.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "pins.h"
|
||||
#include <avr/io.h>
|
||||
|
||||
const unsigned char LOW = 0x00;
|
||||
const unsigned char HIGH = 0x01;
|
||||
|
||||
void digitalWrite(unsigned char pin, unsigned char value){
|
||||
if(pin > 13){
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO turn off pwm
|
||||
|
||||
if(pin < 8){
|
||||
// pin 0-7
|
||||
DDRD |= _BV(DDD0+pin);
|
||||
|
||||
if(value == HIGH){
|
||||
PORTD |= _BV(DDD0+pin);
|
||||
}
|
||||
else{
|
||||
PORTD &= ~_BV(DDD0+pin);
|
||||
}
|
||||
}
|
||||
else{
|
||||
// pin 8-13
|
||||
DDRB |= _BV(DDB0+pin);
|
||||
|
||||
if(value == HIGH){
|
||||
PORTB |= _BV(DDB0+pin);
|
||||
}
|
||||
else{
|
||||
PORTB &= ~_BV(DDB0+pin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void analogWrite(unsigned char pin, unsigned char value){
|
||||
if(pin > 7){
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO turn off pwm
|
||||
|
||||
DDRC |= _BV(DDC0+pin);
|
||||
|
||||
if(value == HIGH){
|
||||
PORTC |= _BV(DDC0+pin);
|
||||
}
|
||||
else{
|
||||
PORTC &= ~_BV(DDC0+pin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user