标题: 单片机门铃程序哪里有错啊,找不出来 [打印本页]

作者: 电工遭不住了    时间: 2020-6-15 18:45
标题: 单片机门铃程序哪里有错啊,找不出来
#include<AT89X51.H>
unsigned char t5hz;
unsigned char t7hz;
unsigned int tcnt;
bit stop;
bit flag;
void main(void)
{
        unsigned char i,j;
        TMOD=0x02;
        TH0=0x06;
        ET0=1;
        EA=1;
        while(1)
        {
                if(P3_7==0)
                {
                        for(i=10;i>0;i--)
                        for(j=248;j>0;j--)
                        if(P3_7==0)
                        {
                                t5hz=0;
                                t7hz=0;
                                tcnt=0;
                                flag=0;
                                stop=0;
                                TR0=1;
                                while(stop==0);
                        }
                 }
         }
  }
  void t0(void) interrupt 1 using 0
  {
          tcnt++;
        if(tcnt==2000)
          {
                tcnt=0;
                if(flag==0)
                {
                        flag=~flag;
                }
                else
                {
                         stop=1;
                         TR0=0;
                }
        }
        if(flag==0)
        t7hz++;
        if(t7hz==3)
        {
                t7hz=0;
                P1_0=~P1_0;
        }
  }
  else
  {
          t5hz++;
        if(t5hz==4)
        {
                t5hz=0;
                P1_0=~P1_0;
        }
  }


作者: 电工遭不住了    时间: 2020-6-15 18:58
编译提示说有两个警告,找不出来
作者: xianfajushi    时间: 2020-6-15 19:06
P3_7在哪里定义按键?P1_0在哪里定义蜂鸣器?
作者: taotie    时间: 2020-6-15 20:03
第二个else语句下花括弧取消。在程序最后添加右花括弧
作者: c00156155    时间: 2020-6-15 20:26
else
  {
          t5hz++;
        if(t5hz==4)
        {
                t5hz=0;
                P1_0=~P1_0;
        }
  }

你把上面这个去掉就没告警了呀,是由于你的else前面没有相应的IF的呀
作者: epson009    时间: 2020-6-15 22:10
else前面的 } 位置不对。
作者: TTQ001    时间: 2020-6-16 08:01
那两个ELSE没有与它之前IF配对。 重组花括号符号以将IF与ELSE配对。
作者: 电工遭不住了    时间: 2020-6-17 15:26
谢谢各位大哥,改好啦
作者: 草草111111    时间: 2020-7-21 15:32
引脚没有定义




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