STC8A8K64D4 Series Manual
sfr
P_SW2
=
#define
ADCTIM
(*(unsigned char volatile xdata *)0xfea8)
#define
ADCEXCFG
(*(unsigned char volatile xdata *)0xfead)
sfr
P1M1
=
sfr
P1M0
=
sfr
P0M1
=
sfr
P0M0
=
sfr
P2M1
=
sfr
P2M0
=
sfr
P3M1
=
sfr
P3M0
=
sfr
P4M1
=
sfr
P4M0
=
sfr
P5M1
=
sfr
P5M0
=
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x01;
P_SW2 |= 0x80;
ADCTIM = 0x3f;
//
ADCEXCFG = 0x04;
//
ADCEXCFG = 0x05;
ADCEXCFG = 0x06;
//
ADCEXCFG = 0x07;
P_SW2 &= 0x7f;
ADCCFG = 0x0f;
ADC_CONTR = 0x80;
while (1)
{
ADC_CONTR |= 0x40;
_nop_();
_nop_();
while (!(ADC_CONTR & 0x20));
ADC_CONTR &= ~0x20;
P2 = ADC_RES;
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
0xba;
0x91;
0x92;
0x93;
0x94;
0x95;
0x96;
0xb1;
0xb2;
0xb3;
0xb4;
0xc9;
0xca;
// Set P1.0 as ADC input
// Set ADC internal timing
//Set the ADC to convert 2 times to take the average automatically
//Set the ADC to convert 4 times to take the average automatically
//Set the ADC to convert 8 times to take the average automatically
//Set the ADC to convert 16 times to take the average automatically
// Set the ADC clock to the system clock/2/16
// Enable ADC module
// Start AD conversion
// Query ADC completion flag
// Clear completion flag
//Read ADC result
- 496 -
Need help?
Do you have a question about the micro STC8A8K64D4 Series and is the answer not in the manual?