You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.9 KiB
88 lines
2.9 KiB
#include "hash_pin.h"
|
|
|
|
#define BIT(n) (1u << (n))
|
|
|
|
static void hash_write_port(volatile uint8_t *port, uint8_t mask, uint8_t on)
|
|
{
|
|
if (on) *port |= mask;
|
|
else *port &= (uint8_t)~mask;
|
|
}
|
|
|
|
static void hash_set_output_pm(volatile uint8_t *pm, uint8_t mask)
|
|
{
|
|
*pm &= (uint8_t)~mask; // PM bit=0 -> output
|
|
}
|
|
|
|
void hash_init(void)
|
|
{
|
|
// #1~#4 : P15.3~P15.0
|
|
hash_set_output_pm(&PM15, (uint8_t)(BIT(0)|BIT(1)|BIT(2)|BIT(3)));
|
|
|
|
// #5 : P12.0
|
|
hash_set_output_pm(&PM12, (uint8_t)BIT(0));
|
|
|
|
// #6 : P12.5
|
|
hash_set_output_pm(&PM12, (uint8_t)BIT(5));
|
|
|
|
// #7 : P0.1
|
|
hash_set_output_pm(&PM0, (uint8_t)BIT(1));
|
|
|
|
// #8 : P12.6
|
|
hash_set_output_pm(&PM12, (uint8_t)BIT(6));
|
|
|
|
// #9 : P12.7
|
|
hash_set_output_pm(&PM12, (uint8_t)BIT(7));
|
|
|
|
// #10 : P0.2
|
|
hash_set_output_pm(&PM0, (uint8_t)BIT(2));
|
|
|
|
// #11~#14 : P10.3~P10.0
|
|
hash_set_output_pm(&PM10, (uint8_t)(BIT(0)|BIT(1)|BIT(2)|BIT(3)));
|
|
|
|
// #15~#20 : P9.7,6,5,4,3,2
|
|
hash_set_output_pm(&PM9, (uint8_t)(BIT(7)|BIT(6)|BIT(5)|BIT(4)|BIT(3)|BIT(2)));
|
|
|
|
hash_all_off();
|
|
}
|
|
|
|
void hash_all_off(void)
|
|
{
|
|
// P15.0~3 OFF
|
|
P15 &= (uint8_t)~(BIT(0)|BIT(1)|BIT(2)|BIT(3));
|
|
// P12.0,5,6,7 OFF
|
|
P12 &= (uint8_t)~(BIT(0)|BIT(5)|BIT(6)|BIT(7));
|
|
// P0.1,2 OFF
|
|
P0 &= (uint8_t)~(BIT(1)|BIT(2));
|
|
// P10.0~3 OFF
|
|
P10 &= (uint8_t)~(BIT(0)|BIT(1)|BIT(2)|BIT(3));
|
|
// P9.2~7 OFF
|
|
P9 &= (uint8_t)~(BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7));
|
|
}
|
|
|
|
void hash_pin(uint8_t ch, uint8_t on)
|
|
{
|
|
switch (ch)
|
|
{
|
|
case 1: hash_write_port(&P15, BIT(3), on); break; // #1 : P153
|
|
case 2: hash_write_port(&P15, BIT(2), on); break; // #2 : P152
|
|
case 3: hash_write_port(&P15, BIT(1), on); break; // #3 : P151
|
|
case 4: hash_write_port(&P15, BIT(0), on); break; // #4 : P150
|
|
case 5: hash_write_port(&P12, BIT(0), on); break; // #5 : P120
|
|
case 6: hash_write_port(&P12, BIT(5), on); break; // #6 : P125
|
|
case 7: hash_write_port(&P0, BIT(1), on); break; // #7 : P01
|
|
case 8: hash_write_port(&P12, BIT(6), on); break; // #8 : P126
|
|
case 9: hash_write_port(&P12, BIT(7), on); break; // #9 : P127
|
|
case 10: hash_write_port(&P0, BIT(2), on); break; // #10: P02
|
|
case 11: hash_write_port(&P10, BIT(3), on); break; // #11: P103
|
|
case 12: hash_write_port(&P10, BIT(2), on); break; // #12: P102
|
|
case 13: hash_write_port(&P10, BIT(1), on); break; // #13: P101
|
|
case 14: hash_write_port(&P10, BIT(0), on); break; // #14: P100
|
|
case 15: hash_write_port(&P9, BIT(7), on); break; // #15: P97
|
|
case 16: hash_write_port(&P9, BIT(6), on); break; // #16: P96
|
|
case 17: hash_write_port(&P9, BIT(5), on); break; // #17: P95
|
|
case 18: hash_write_port(&P9, BIT(4), on); break; // #18: P94
|
|
case 19: hash_write_port(&P9, BIT(3), on); break; // #19: P93
|
|
case 20: hash_write_port(&P9, BIT(2), on); break; // #20: P92
|
|
default: /* ignore */ break;
|
|
}
|
|
}
|
|
|