Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // wiring_digital.c
- void digitalWrite(uint8_t pin, uint8_t val)
- {
- uint8_t timer = digitalPinToTimer(pin);
- uint8_t bit = digitalPinToBitMask(pin);
- uint8_t port = digitalPinToPort(pin);
- volatile uint8_t *out;
- if (port == NOT_A_PIN) return;
- // If the pin that support PWM output, we need to turn it off
- // before doing a digital write.
- if (timer != NOT_ON_TIMER) turnOffPWM(timer);
- out = portOutputRegister(port);
- uint8_t oldSREG = SREG;
- cli();
- if (val == LOW) {
- *out &= ~bit;
- } else {
- *out |= bit;
- }
- SREG = oldSREG;
- }
- // Arduino.h
- #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
- #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
- #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement