PORTC |= (1 << PORTC7)
PORTC &= ~(1 << PORTC5)
DDRB |= (1 << DDB7)
DDRB &= ~(1 << DDB5)
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg, *out;
if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
out = portOutputRegister(port);
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out &= ~bit;
SREG = oldSREG;
}
else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
}
else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
}
byte state = (PIND >> PIND3) & 0x1
byte x = (PINC >> PIND7) & 0x1
#ifndef _AVR_IO_H_
#define _AVR_IO_H_
#include
#if defined (__AVR_AT94K__)
# include
#elif defined (__AVR_AT43USB320__)
# include
#elif defined (__AVR_AT43USB355__)
# include
#elif defined (__AVR_AT76C711__)
# include
#elif defined (__AVR_AT90PWM3__)
# include
#elif defined (__AVR_AT90PWM3B__)
# include
#elif defined (__AVR_AT90PWM216__)
# include
#elif defined (__AVR_AT90PWM316__)
# include
#elif defined (__AVR_AT90PWM161__)
# include
#elif defined (__AVR_AT90PWM81__)
# include
#elif defined (__AVR_ATmega8U2__)
# include
*****
#define PINB _SFR_IO8(0x03)
#define PINB0 0
#define PINB1 1
#define PINB2 2
#define PINB3 3
#define PINB4 4
#define PINB5 5
#define PINB6 6
#define PINB7 7
#define DDRB _SFR_IO8(0x04)
#define DDB0 0
#define DDB1 1
#define DDB2 2
#define DDB3 3
#define DDB4 4
#define DDB5 5
#define DDB6 6
#define DDB7 7
#define PORTB _SFR_IO8(0x05)
#define PORTB0 0
#define PORTB1 1
#define PORTB2 2
#define PORTB3 3
#define PORTB4 4
#define PORTB5 5
#define PORTB6 6
#define PORTB7 7
//PORT B Als voorbeeld
#define PORTB _SFR_IO8(0x05)
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
//So PORTB expands to:
(*(volatile uint8_t *)((0x05) + 0x20))
//Which becomes: (*(volatile uint8_t *)0x25)
PORTC |= (1 << PORTC7)
PORTC &= (1 << PORTC5)
0x28 |= (1 << PORTC7)
0x28 &= (1 << PORTC5)
void setup(){
DDRD |= 1 << DDRD6;
}
void loop(){
_delay_ms(500);
PORTD ^= 1 << PORTD6;
}
ADMUX |= (1 << REFS0);
ADMUX |= ((1 << MUX1) | (1 << MUX0));
ADEN | ADC Enable |
ADSC | ADC Start Conversion |
ADATE | ADC Auto Trigger Enable |
ADIF | ADC Interrupt Flag |
ADIE | ADC Interrupt Enable |
ADPS2-0 | ADC Prescaler bit |
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
ADCSRA |= (1 << ADEN);
ADCSRA |= (1 << ADSC);
ADCSRA |= (1 << ADATE);
ADCSRA |= (1 << ADEN);
ADCSRA |= (1 << ADSC);
Serial.println(ADCL | (ADCH << 8));
void setup() {
Serial.begin(9600);
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
ADMUX |= (1 << REFS0);
ADCSRA |= (1 << ADEN);
ADCSRA |= (1 << ADSC);
while ((ADCSRA & (1 << ADSC)));
Serial.println((ADCH << 8) | ADCL);
Serial.println("DONE");
}
void loop() {
Serial.println(ADCL | (ADCH << 8));
}