Advertisement
Guest User

Untitled

a guest
May 15th, 2022
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include "atmega328p.h"
  3.  
  4.  
  5. extern  void pin_config_output(pin_t pin)
  6. {
  7.     pin.base_register[1] |= pin.pin_bitmask;
  8. }
  9.  
  10. extern  void pin_config_input(pin_t pin)
  11. {
  12.     pin.base_register[1] &= ~pin.pin_bitmask;
  13. }
  14.  
  15. extern  void pin_set_output_value(pin_t pin, bool output_value)
  16. {
  17.     if (output_value)
  18.     {
  19.         pin.base_register[2] |= pin.pin_bitmask;
  20.     }
  21.     else
  22.     {
  23.         pin.base_register[2] &= ~pin.pin_bitmask;
  24.     }
  25. }
  26.  
  27. extern  bool pin_get_input_value(pin_t pin)
  28. {
  29.     return (pin.base_register[0] & pin.pin_bitmask);
  30. }
  31.  
  32. void pin_pullup_enable(pin_t pin)
  33. {
  34.     pin.base_register[0] &= ~(pin.pin_bitmask); // Set as input
  35.     pin.base_register[1] |= (pin.pin_bitmask);  // Output HIGH to enable pullup.
  36. }
Advertisement
RAW Paste Data Copied
Advertisement