EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 521

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 505 -
ShowLED();
if (++cnt_250ms >= 5)
{
cnt_250ms = 0;
AutoZero(); //Process 0-point auto-tracking every 250ms
}
}
}
void delay_ms(u8 ms)
{
unsigned int i;
do
{
i = MAIN_Fosc / 13000;
while(--i) ;
} while(--ms);
}
void ADC_init(void)
{
P1M0 = 0x00; //8 channels ADC
P1M1 = 0xff;
ADC_CONTR = 0x80; //Enable ADC
}
u16 Get_ADC10bitResult(u8 channel)
{
ADC_RES = 0;
ADC_RESL = 0;
ADC_CONTR = 0x80 | ADC_90T | ADC_START | channel; //Trigger ADC
_nop_();
_nop_();
_nop_();
_nop_();
while((ADC_CONTR & ADC_FLAG) == 0) ; //Wait for ADC conversion complement
ADC_CONTR = 0x80; //Clear flag
return(((u16)ADC_RES << 2) | ((u16)ADC_RESL & 3)); //Return ADC result
}
void AutoZero(void) //Call once every 250ms
// 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++) //Process 8 channels
{
j = adc[i];
k = j - adc_prev[i]; // Subtract previous reading
F0 = 0; //Pressed
if(k & 0x8000) F0 = 1, k = 0 - k; //Release, get the difference between two samples
if(k >= 20) // Big change
{
TouchZeroCnt[i] = 0; // If the change is large, clear the counter
if(F0) TouchZero[i] = j; // If it is released, and the change is relatively large, then directly replace
}

Table of Contents

Related product manuals