Download Print this page

STC micro STC8A8K64D4 Series Reference Manual page 522

Advertisement

STC8A8K64D4 Series Manual
else
{
if(++TouchZeroCnt[i] >= 20)
{
TouchZeroCnt[i] = 0;
TouchZero[i] = adc_prev[i];
}
adc_prev[i] = j;
}
}
u8 check_adc(u8 index)
{
u16 delta;
adc[index] = 1023 - Get_ADC10bitResult(index);
if(adc[index] < TouchZero[index]) return 0;
delta = adc[index] - TouchZero[index];
if(delta >= 40) return 1;
if(delta <= 20) return 0;
return 2;
}
void ShowLED(void)
{
u8 i;
i = check_adc(0);
if(i == 0) P_LED0 = 1;
if(i == 1) P_LED0 = 0;
i = check_adc(1);
if(i == 0) P_LED1 = 1;
if(i == 1) P_LED1 = 0;
i = check_adc(2);
if(i == 0) P_LED2 = 1;
if(i == 1) P_LED2 = 0;
i = check_adc(3);
if(i == 0) P_LED3 = 1;
if(i == 1) P_LED3 = 0;
i = check_adc(4);
if(i == 0) P_LED4 = 1;
if(i == 1) P_LED4 = 0;
i = check_adc(5);
if(i == 0) P_LED5 = 1;
if(i == 1) P_LED5 = 0;
i = check_adc(6);
if(i == 0) P_LED6 = 1;
if(i == 1) P_LED6 = 0;
i = check_adc(7);
if(i == 0) P_LED7 = 1;
if(i == 1) P_LED7 = 0;
}
Assembly code
;Operating frequency for testing is 24MHz
// If the change is relatively small, then creep, track 0-point automatically
// Get ADC value, convert to press the key, ADC value increases
// Continuously detect small changes 20 times/4 = 5 seconds.
// Use slowly changing values as 0 points
// Save this time's sample value
// Get touch information function, called every 50ms
// Judge key is pressed or released with hysteresis control
// A value smaller than 0-point is considered a key release
//Key pressed
//Key released
// Keep the original state
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
//Light off
//Light on
}
- 506 -

Advertisement

loading
Need help?

Need help?

Do you have a question about the micro STC8A8K64D4 Series and is the answer not in the manual?

This manual is also suitable for:

Micro stc8a8k64d4-64pinMicro stc8a8k64d4-48pin