以下是我的编码,请教是否有问题
#include <STC12C5A60S2.H>
#include <intrins.h>
#include <stdio.h>
void UART_init()
{
PCON = 0x00;
SCON = 0x5a;//0101 0000
TMOD = 0x20;
TH1 = 0xFD;//9600bps
TL1 = 0xFD;
ET1 = 0;
ES = 0;
TR1 = 1;
TI = 1;puts("MCU 51 start...");
//puts("[PcTo] not(1-2),close led");
//printf("[Test]...P1 = %x\r\n",cs_zt);
}
void ys1ms(void){
unsigned int i=255;
while(i--){
}
}
void ysnms(unsigned int n){
while(n--){
ys1ms();
}
}
void ADC_init(void)
{
P1ASF = 0XFF;
ADC_RES = 0;
ADC_CONTR = 0X80 | 0X00;
ysnms(2);
}
unsigned int ADC_get(unsigned int ch)
{
ADC_CONTR = 0X80 | 0X00 | 0X08 | ch;
_nop_();_nop_();_nop_();_nop_();
while( !(ADC_CONTR & 0X10) );
ADC_CONTR &= ~0X10;
return ADC_RES;
}
void main(void)
{
unsigned char ch = 0;
UART_init();
ADC_init();ysnms(1000);
while(1){
ysnms(100);
printf("MAIN,ADC ch =%u\r\n",(unsigned int)ch);
printf("MAIN,ADC res =%u\r\n",ADC_get(ch));
ysnms(100);
}
}
|