用STC12C5201AD单片机就可以了,16脚的!
#include <STC12C5A60S2_H.h>
#include <string.h>
#include <stdio.h>
#include <absacc.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ADC_FLAG 0x10
#define ADC_START 0x08
uchar datt1=0;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=250;y>0;y--);
}
uchar GetADCResult(uchar ch)
{
ADC_CONTR =0x80 | ch | ADC_START;
_nop_();
_nop_();
_nop_();
_nop_();
while (!(ADC_CONTR & ADC_FLAG));
ADC_CONTR &= ~ADC_FLAG;
return ADC_RES;
}
void Txbyte(unsigned char i)
{
ES=0;TI=0;SBUF=i;
while(!TI);
TI=0;ES=1;
}
void Serial_Int(void) interrupt 4
{
if(RI==1)
{
RI=0;
}
void LcmInit( void )
{
SCON=0X50; //串口方式1,允许接收
TMOD=0X20; //定时器1 定时方式2 T0 is mode 1
TH1=0xfd; // t1 // 9600
TL1=0xfd;
PCON|=0x00;
TR1=1; //启动定时器
REN=1;
ES = 1; //开串口中断
EA = 1; //开总中断
CLK_DIV = 0x01;
ADC_RES = 0;
ADC_CONTR=0x80;
}
void Main( void )
{
LcmInit();
while(1)
{
delay(10);
dat1=GetADCResult(0);
Txbyte(dat1);
}
}
温馨提示:答案为网友推荐,仅供参考