Technical information
CSI to SPI Peripheral Communication in V850ES Microcontrollers
}
/* unsigned char sw_chk(void) */
/* return input from switches, undebounced */
unsigned char sw_chk(void)
{
return P9L & 0x30;
}
/* void sw_set_debounce(unsigned char count) */
/* set the debounce counter value */
void sw_set_debounce(unsigned char count)
{
sw_deb_value = count; /* set new debounce counter value */
sw_deb_count = count; /* set counter to max */
}
/* unsigned char sw_get(void) */
/* return debounced switch input */
unsigned char sw_get(void)
{
return sw_last;
}
/* void sw_isr( void ) */
/* this routine called by periodic timer interrupt to poll and debounce
switches */
/* after a new value has been seen steadily for sw_deb_value times, sw_last
is updated */
void sw_isr( void )
{
unsigned char val;
val = sw_chk(); /* get current value */
/* if value is the same as before, no change; reset debounce and return
*/
if (val == sw_last) {
sw_deb_count = sw_deb_value; /* reset debounce counter to max */
return;
}
/* val != sw_last, there is a new input */
/* if it's not the same as the previous new one, */
/* set the NEW new one, reset the debounce counter and return */
if (val != sw_new) {
sw_new = val;
sw_deb_count = sw_deb_value;
return;
}
/* val != sw_last, val == sw_new */
/* count down the debounce counter */
sw_deb_count--;
72