STC8A8K64D4 Series Manual
ShowLED();
if (++cnt_250ms >= 5)
{
cnt_250ms = 0;
AutoZero();
}
}
}
void delay_ms(u8 ms)
{
unsigned int i;
do
{
i = MAIN_Fosc / 13000;
while(--i) ;
} while(--ms);
}
void ADC_init(void)
{
P1M0 = 0x00;
P1M1 = 0xff;
ADC_CONTR = 0x80;
}
u16 Get_ADC10bitResult(u8 channel)
{
ADC_RES = 0;
ADC_RESL = 0;
ADC_CONTR = 0x80 | ADC_90T | ADC_START | channel;
_nop_();
_nop_();
_nop_();
_nop_();
while((ADC_CONTR & ADC_FLAG) == 0) ;
ADC_CONTR = 0x80;
return(((u16)ADC_RES << 2) | ((u16)ADC_RESL & 3));
}
void AutoZero(void)
// This is detected using the sum of the absolute values of the differences between two adjacent samples.
{
u8 i;
u16 j,k;
for(i=0; i<TOUCH_CHANNEL; i++)
{
j = adc[i];
k = j - adc_prev[i];
F0 = 0;
if(k & 0x8000) F0 = 1, k = 0 - k;
if(k >= 20)
{
TouchZeroCnt[i] = 0;
if(F0) TouchZero[i] = j;
}
//Process 0-point auto-tracking every 250ms
//8 channels ADC
//Enable ADC
//Trigger ADC
//Wait for ADC conversion complement
//Clear flag
//Return ADC result
//Call once every 250ms
//Process 8 channels
// Subtract previous reading
//Pressed
//Release, get the difference between two samples
// Big change
// If the change is large, clear the counter
// If it is released, and the change is relatively large, then directly replace
- 505 -
Need help?
Do you have a question about the micro STC8A8K64D4 Series and is the answer not in the manual?
Questions and answers