#include"reg51.h"
#include"intrins.h"
#define FOSC 18432000L
#define BAUD 9600
typedef unsigned char BYTE;
typedef unsigned int WORD;
sfr ADC_CONTR = 0XBC;
sfr ADC_RES = 0XBD;
sfr P1ASF = 0X9D;
#define ADC_POWER 0X80
#define ADC_FLAG 0X10
#define ADC_START 0X08
#define ADC_SPEEDLL0X00
#define ADC_SPEEDL 0X20
#define ADC_SPEEDH 0X40
#define ADC_SPEEDHH 0X60
void InitUart()
void SENDdata(BYTE dat);
void Delay(WORD n);
void InitADC();
BYTE ch = 0;
void main()
{
InitUart();
InitADC();
IE = 0xa0;
while(1);
}
void adc_isr()interruprt 5 using 1;
{
ADC_CONTR &=!ADC_FLAG;
SendData(ch);
SendData(ADC_RES);
if(++ch>7)ch=0;
ADC_CONTR = ADC_POWER|ADC_SPEEDLL|ADC_START|ch;
}
void InitADC()
{
P1ASF = 0Xff;
ADC_RES =0;
ADC_CONTR =ADC_POWER|ADC_SPEEDLL|ADC_START|ch;
Delay(2);
}
void InitUart()
{
SCON =0x5a;
TMOD =0x20;
TH1 =TL1=-(FOSC/12/32/BAUD);
TR1 =1;
}
void SendData(BYTE dat)
{
while(!
ti);
TI =0;
SBUF =dat;
}
void Delay(WORD n)
{
WORD x;
while (n--)
{
x =5000;
while(x--);
}
}
一周热门 更多>