P5M0 = 0x00;
P5M1 = 0x00;
P1M0 = 0x00; //Set P1.0 as ADC input
P1M1 = 0x01;
P_SW2 |= 0x80;
ADCTIM = 0x3f; //Set ADC internal timing
P_SW2 &= 0x7f;
ADCCFG = 0x0f; //Set the ADC clock to the system clock/2/16
ADC_CONTR = 0x80; //Enable ADC module
ADC_CONTR |= 0x40; //Start AD conversion
_nop_();
_nop_();
while (!(ADC_CONTR & 0x20)); //Query ADC completion flag
ADC_CONTR &= ~0x20; //Clear completion flag
ADCCFG = 0x00; //Set result to align left
ACC = ADC_RES; //A stores the upper 8 bits of the ADC
’
s 10-bit result
B = ADC_RESL; //B[7: 6] stores the lower 2 bits of the 10-bit ADC result, B [5: 0] is 0
// ADCCFG = 0x20; //Set result to align right
// ACC = ADC_RES; // A [1: 0] stores the upper 2 bits of the 10-bit result of the ADC, and A [7: 2] is 0
// B = ADC_RESL; //B stores the lower 8 bits of the ADC’s 10-bit result
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ADC_CONTR DATA 0BCH
ADC_RES DATA 0BDH
ADC_RESL DATA 0BEH
ADCCFG DATA 0DEH
P_SW2 DATA 0BAH
ADCTIM XDATA 0FEA8H
P0M1 DATA 093H
P0M0 DATA 094H
P1M1 DATA 091H
P1M0 DATA 092H
P2M1 DATA 095H
P2M0 DATA 096H
P3M1 DATA 0B1H
P3M0 DATA 0B2H
P4M1 DATA 0B3H
P4M0 DATA 0B4H
P5M1 DATA 0C9H
P5M0 DATA 0CAH
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH