stc12C5A60S2 及以上的15系列 PCA捕獲,測量占空比,頻率怎么使用?下面是我寫的,寫到一半寫不下去了,求高人指點!!
#include <STC12C5A60S2.H>
#define uchar unsigned char
#define uint unsigned int
uchar t1,th1;
uint value;
void delay(uint a1);
void SendStr(unsigned char *s);
void SendByte(unsigned char dat);
void InitUART (void)
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xFD;
TR1 = 1;
EA = 1;
//ES = 1;
}
uint read(void)
{
uchar t1,th1;
uint value;
CCON=0;
CMOD=0x0A;
CCAPM1=0x20;
CR=1;
th1 = CCAP1H;
t1 = CCAP1L;
value = th1*256 + t1;
return value;
}
/******************************************/
void main()
{
InitUART();
read();
SendByte(CCAP1L);
SendByte(CCAP1H);
delay(600);
}
void SendByte(unsigned char dat)
{
SBUF = dat;
while(!TI);
TI = 0;
}
void SendStr(unsigned char *s)
{
while(*s!='\0')
{
SendByte(*s);
s++;
}
}
void delay(uint a1)
{
unsigned char a,b,c;
for(c=a1;c>0;c--)
for(b=142;b>0;b--)
for(a=120;a>0;a--);
}
|