导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→利用51的计数器T0外部计数测频,怎么误差很大 [讨论][淮工王大师]

 *第9013篇: 利用51的计数器T0外部计数测频,怎么误差很大 [讨论]

  
楼 主:淮工王大师 2008年10月27日08:35
 利用51的计数器T0外部计数测频,怎么误差很大 [讨论]
#include  <reg51.h>   
#include  <1602.h>   
 bit flag=1; 
 int count ; 
 unsigned l,h; 
 char msg[4]="0000"; 
 void uchar2string(int cons) 
{    
    int b,a; 
        msg[3]=cons%10+'0'; 
        b=cons/10; 
        msg[2]=b%10+'0'; 
    a=b/10; 
        msg[1]=a%10+'0'; 
    msg[0]=a/10+'0'; 

  void main() 

  TMOD=0X15; 
  TH1=0X0; 
  TL1=0X0; 
  TH0=0X0; 
  TL0=0X0; 
  ET1=1; 
  EA=1; 
  TR1=1; 
  TR0=1; 
  while(1) 
   { 
    if(flag==1) 
        { 
    flag=0; 
    uchar2string(count); 
  InitLcd(); 
  DisplayMsg(msg); 
   } 
   } 

void t1() interrupt 3 

   
  h=TH0; 
  l=TL0; 
  count=h*256+l; 
  flag=1; 
  TH0=0X0; 
  TL0=0X0; 
   


1602.h 
#ifndef       _1602L_ 
#define       _1602L_ 

sbit E=P3^5; 
sbit RW=P3^6; 
sbit RS=P3^7; 
#define uchar unsigned char  
//------------------------------------- 
void Delay(unsigned int t)    // delay 40us 

for(;t!=0;t--) ; 

//============================================= 
void SendCommandByte(unsigned char ch) 

    RS=0; 
    RW=0; 
    P1=ch; 
    E=1; 
     Delay(1); 
    E=0; 
    Delay(100);   //delay 40us 

//------------------------------------------------------- 
void SendDataByte(unsigned char ch) 
{   RS=1; 
    RW=0; 
    P1=ch; 
    E=1; 
        Delay(1); 
    E=0; 
    Delay(100); //delay 40us 

//------------------------------------------------- 
void InitLcd() 
{SendCommandByte(0x30); 
SendCommandByte(0x30); 
SendCommandByte(0x30); 
SendCommandByte(0x38); //设置工作方式 
SendCommandByte(0x0c); //显示状态设置 
SendCommandByte(0x01); //清屏 
SendCommandByte(0x06); //输入方式设置 

//============================================= 
void DisplayMsg( uchar *p) 

unsigned char count; 
SendCommandByte(0x80);   //设置DDRAM地址 
for(count=0;count  <4;count++) 
     {SendDataByte(*p++); 
     } 

#endif 

.h应该没有问题,用了好久了,小弟让t1定时中断,没有用1s(直接65536us中断,读出此时的1602上面的显示2844),我测得是40K标准方波,晕用2844/65536us,结果是43.4khz,改了好长时间,请大家帮我看看,51的测频应该哦很准的吧


>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:【奥科电子】OK300E+ 51单片机开发板300元+视频+赠品+三年质保+技术支持

[下一篇主题]:台湾义隆电子单片机(ELAN)