#include "anaout.h" #define BIT(n) (1u << (n)) static void write_port(volatile uint8_t *port, uint8_t mask, uint8_t on) { if (on) *port |= mask; else *port &= (uint8_t)~mask; } /* ?? -> (?? ??, ???) ??? */ static volatile uint8_t * const s_port[21] = { 0, &P6, &P6, &P6, &P6, // 1~4 &P4, &P4, &P4, &P4, // 5~8 &P5, &P5, &P5, // 9~11 &P6, &P6, // 12~13 &P7, &P7, &P7, &P7, &P7, &P7, // 14~19 &P13 // 20 }; static const uint8_t s_mask[21] = { 0, (uint8_t)BIT(4), (uint8_t)BIT(5), (uint8_t)BIT(6), (uint8_t)BIT(7), // P64~P67 (uint8_t)BIT(4), (uint8_t)BIT(3), (uint8_t)BIT(2), (uint8_t)BIT(1), // P44,P43,P42,P41 (uint8_t)BIT(0), (uint8_t)BIT(1), (uint8_t)BIT(2), // P50,P51,P52 (uint8_t)BIT(0), (uint8_t)BIT(1), // P60,P61 (uint8_t)BIT(2), (uint8_t)BIT(3), (uint8_t)BIT(5), (uint8_t)BIT(4), (uint8_t)BIT(6), (uint8_t)BIT(7), // P72~P77 (uint8_t)BIT(0) // P130 }; void ANAOUT_Set(uint8_t ch, uint8_t on) { if (ch < 1 || ch > 20) return; write_port(s_port[ch], s_mask[ch], on); } void ANAOUT_AllOff(void) { uint8_t ch; for (ch = 1; ch <= 20; ch++) { ANAOUT_Set(ch, 0); } } void ANAOUT_Select(uint8_t ch) { if (ch < 1 || ch > 20) return; ANAOUT_AllOff(); ANAOUT_Set(ch, 1); } void anaout_pin(uint8_t ch, uint8_t on) { if (ch < 1 || ch > 20) return; if (on) { // on=1?? "??" ???? ??(??? 1?? ??) ANAOUT_Select(ch); } else { // off? ?? ??? OFF ANAOUT_Set(ch, 0); } } void anaout_all_off(void) { ANAOUT_AllOff(); }