|
程序功能实现AD采集正弦波实现串口输出驱动LED灯,使用单片机STC15f2k60s2芯片。能否在仿真软件运行吗?
#include<reg51.h>
#include<intrins.h>
#define BYTE unsigned char
typedef unsigned int WORD;
#define URMD 0
sfr T2H=0xd6;
sfr T2L=0xd7;
sfr AUXR=0x8e;
sfr ADC_CONTR=0xBC;
sfr ADC_RES=0xBD;
sfr ADC_LOW2=0xBE;
sfr P1ASF=0x9D;
#define ADC_POWER 0x80
#define ADC_FLAG 0x10
#define ADC_START 0x08
#define ADC_SPEEDLL 0x00
#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()interrupt 5 using 1
{
ADC_CONTR&=!ADC_FLAG;
SendData(ADC_RES);
ADC_CONTR=0xea;
}
void InitADC()
{
P1ASF=0xff;
ADC_RES=0;
ADC_CONTR=ADC_POWER|ADC_SPEEDHH|ADC_START|ch;
Delay(2);
}
void InitUart()
{
SCON=0x5a;
T2L=0xea;
T2H=0xff;
AUXR=0x14;
AUXR|=0x01;
}
void SendData(BYTE dat)//void SengData(BYTE dat)
{
while(!TI);
TI=0;
SBUF=dat;
}
void Delay(WORD n)
{
WORD x;
while(n--)
{
x=5000;
while(x--);
}
}
|
|