qaqawer 2018-03-14 11:57 采纳率: 0%
浏览 1821
已结题

STC89C52连接HC-SR04超声波模块用数码管显示,只能显示一次正确距离,然后就只显示0了

数码管只显示一次正确距离,然后数码管显示0,再无反应。
代码在这:

/***********************************************************************************************************/

#include

#include
sbit RX = P2^1;
sbit TX = P2^2;
sbit du = P2^6;
sbit we = P2^7;
unsigned int time=0;
unsigned int timer=0;
unsigned char posit=0;
unsigned long S=0;
bit flag =0;
unsigned char const discode[] ={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x01/*-*/};
unsigned char const positon[3]={ 0xf7,0xef,0xdf};
unsigned char disbuff[4] ={ 0,0,0,0,};
/********************************************************/
void Display(void)

{

 P0=discode[disbuff[posit]];
    du = 1;
    du = 0;
  P0=positon[posit];
    we = 1;
  we = 0;
  if(++posit>=3)
  posit=0;
}

/********************************************************/
void Conut(void)
{
time=TH0*256+TL0;
TH0=0;
TL0=0;

 S=(time*1.7)/100;     
    //S++;
 if((S>=700)||flag==1)
 {   
  flag=0;
  disbuff[0]=10;      
  disbuff[1]=10;     
  disbuff[2]=10;     

 }
 else
 {
  disbuff[0]=S%1000/100;
  disbuff[1]=S%1000%100/10;
  disbuff[2]=S%1000%10 %10; 
 }
}

/********************************************************/
void zd0() interrupt 1

{
flag=1;

}
/********************************************************/
void zd3() interrupt 3

{
TH1=0xf8;
TL1=0x30;
Display();
timer++;
if(timer>=40)
{
timer=0;
TX=1;

nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
TX=0;
}
}
/*********************************************************/

void  main(  void  )

{

TMOD=0x11;

TH0=0;
TL0=0;

TH1=0xf8;

TL1=0x30;
ET0=1;

ET1=1;

TR1=1;

EA=1;

while(1) 
{
 while(!RX);        
 TR0=1;          
 while(RX);     
 TR0=0;         

Conut();
//S++;
}

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-03-14 15:46
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料