标题: stc12C5A60S2及以上的15系列单片机PCA捕获,测量占空比,频率怎么使用? [打印本页]

作者: 诗语凌枫    时间: 2018-8-3 11:25
标题: stc12C5A60S2及以上的15系列单片机PCA捕获,测量占空比,频率怎么使用?
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--);
}




作者: wulin    时间: 2018-8-4 13:16






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1