EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 512

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

Table of Contents

Related product manuals