打印

继续求教~~问题依然没有解决。。。

[复制链接]
1275|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zwfj2418|  楼主 | 2008-9-22 16:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

void start_stop_key_scan()         
{
     if(start==0)
     {
          display();                                
          if(start==0)
          {
              d[]=1;
              start_key=~start_key;                   
              while(!start)                         
                 {
                   display();                         
                   if(start==1)                    
                      {
                       start_key=~start_key;
                        if(start_key)             
                           {
                            time_m=0;
                            time_s=5;       
                            start_stop_flag=1;   
                            start_djs_flag=1;    
                            d[]=0;              
                            TR0=1;                
                          // TR1=1;
                               }
                         else                          
                               {
                            start_stop_flag=0;  
                            //time_s=0;
                             //time_m=0;
                             d[]=0;    
                                             
                                }
                          
                         }
               }
          }
     } 
}


此段函数,在程序的开头该如何定义
曾经尝试很多办法多无法有效的定义它。。。。

相关帖子

沙发
gjg191| | 2008-9-22 16:39 | 只看该作者

o

你把整个程序发上来我回家帮你在keil上试试看

使用特权

评论回复
板凳
zwfj2418|  楼主 | 2008-9-22 16:43 | 只看该作者

你有邮箱吗 我贴上去 你好复制吗?

使用特权

评论回复
地板
gjg191| | 2008-9-22 19:43 | 只看该作者

o

我复制就好了阿

使用特权

评论回复
5
zwfj2418|  楼主 | 2008-9-23 15:02 | 只看该作者

全部程序都在这了

这就是全部程序了 我想定义的就是最后的这个

#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
//static unsigned char start;
uchar time_s,time_m;
//uint start_key;
sbit d1=P1^7;
sbit d2=P1^6;
sbit d3=P1^5;
sbit d4=P1^4;
sbit d5=P1^3;                            //风扇、雾化片、负离子
sbit d6=P1^2;                            //加热口
sbit a1=P3^7;                            //水位传感器检测
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
unsigned int a;
void init();
extern void start_stop_key_scan();


void main()
{             
        init();
      start_stop_key_scan();            
        P3=0xff;            
        while(1)
        {
                if(a1==0)                  //水位检测端口信号
                    {
                        key1=0;
                        key2=0;
                    }
                else
                    {    
                        key1=1;
                        key2=1;
                    }

                if(key1==0)                //key1键功能控制
                    {
                       a=50000;
                         d1=0;
                       while(a--);
                       d1=1;
                    a=50000;
                    while(a--);
                      if(key4==0)
                       d1=0;
                        d5=0;
                       key2=1;
                    }
                else 
                    {
                        key2=0;d1=1;
                    }
                    
                
                if(key2==0)                //key2键功能控制
                    {
                        a=50000;
                        d2=0;    
                        while(a--);
                        d2=1;
                        a=50000;
                        while(a--);
                        if(key4==0)
                        d2=0;
                        d5=0;
                        key1=1;
                    }
                else 
                    {    
                        key1=0;d2=1;
                    }

                if(key4==0)               //key4键功能控制
                    {
                        key3=0;             //key3键功能选择
                            d3=0;
                            d6=0;
                            d5=0;
                    }
                else
                    {    
                        key3=1;
                     d3=1;
                            d6=1;
                            d5=1;
                    }
                
                
        }
}

void init()                          //定时器初始化
{
    TMOD=0x01;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    EA=1;
    ET0=1;
    
    if(key4==0)
        TR0=1;
    else
        TR0=0;
}

void timer0() interrupt 1          
{
    uchar time1_conuter_s;            
    uchar time1_conuter;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    time1_conuter_s++;
    time1_conuter++;

      if(time1_conuter_s==40)
            {
                time1_conuter_s=0;        
            time_s++;

            if(time_s==60)
             {
                    time_s=0;
                    time_m++;

              if(time_m==30)
                 {          
                        time_m=0;
                        key4=1;
                 }
                }
        }
}

void start_stop_key_scan()           //按键检测
{
     if(start==0)
     {
          display();                         //消抖函数                
          if(start==0)
          {
               d[]=1;
              start_key=~start_key;                   
               while(!start)                         
                   {
                    display();                         
                    if(start==1)                    
                         {
                         start_key=~start_key;
                          if(start_key)             
                               {
                                time_m=0;
                                time_s=5;       
                                start_stop_flag=1;   
                                start_djs_flag=1;    
                                d[]=0;              
                                TR0=1;                
                              // TR1=1;
                               }
                              else                          
                                {
                             start_stop_flag=0;  
                                //time_s=0;
                                 //time_m=0;
                                 d[]=0;    
                                             
                                }
                          
                         }
               }
          }
     } 
}

使用特权

评论回复
6
winovs| | 2008-9-23 15:08 | 只看该作者

需要样品的看过来,超级便宜

http://store.taobao.com/shop/view_shop-ba2bd5df34961821c2c59087a1dcd683.htm

使用特权

评论回复
7
gjg191| | 2008-9-23 15:21 | 只看该作者

o

晚上帮你看啊

使用特权

评论回复
8
zwfj2418|  楼主 | 2008-9-23 15:56 | 只看该作者

呵呵

谢谢了啊~~~

使用特权

评论回复
9
gjg191| | 2008-9-23 19:49 | 只看该作者

错误多是没有定义的变量

display()子程序那里去了 还有以前跟你说的不要用start做变量你也没改我改成start1就ok了,还有d[]这个也没有定义,建议你找本c语言的书好好看看
注意变量是一定要定义才可以用的.
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar start1;
uchar time_s,time_m;
uchar start_stop_flag;
uint start_key;
uchar start_djs_flag;
sbit d1=P1^7;
sbit d2=P1^6;
sbit d3=P1^5;
sbit d4=P1^4;
sbit d5=P1^3;                            //风扇、雾化片、负离子
sbit d6=P1^2;                            //加热口
sbit a1=P3^7;                            //水位传感器检测
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
unsigned int a;
void init();
extern void start_stop_key_scan();


void main()
{             
        init();
      start_stop_key_scan();            
        P3=0xff;            
        while(1)
        {
                if(a1==0)                  //水位检测端口信号
                    {
                        key1=0;
                        key2=0;
                    }
                else
                    {    
                        key1=1;
                        key2=1;
                    }

                if(key1==0)                //key1键功能控制
                    {
                       a=50000;
                         d1=0;
                       while(a--);
                       d1=1;
                    a=50000;
                    while(a--);
                      if(key4==0)
                       d1=0;
                        d5=0;
                       key2=1;
                    }
                else 
                    {
                        key2=0;d1=1;
                    }
                    
                
                if(key2==0)                //key2键功能控制
                    {
                        a=50000;
                        d2=0;    
                        while(a--);
                        d2=1;
                        a=50000;
                        while(a--);
                        if(key4==0)
                        d2=0;
                        d5=0;
                        key1=1;
                    }
                else 
                    {    
                        key1=0;d2=1;
                    }

                if(key4==0)               //key4键功能控制
                    {
                        key3=0;             //key3键功能选择
                            d3=0;
                            d6=0;
                            d5=0;
                    }
                else
                    {    
                        key3=1;
                     d3=1;
                            d6=1;
                            d5=1;
                    }
                
                
        }
}

void init()                          //定时器初始化
{
    TMOD=0x01;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    EA=1;
    ET0=1;
    
    if(key4==0)
        TR0=1;
    else
        TR0=0;
}

void timer0() interrupt 1          
{
    uchar time1_conuter_s;            
    uchar time1_conuter;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    time1_conuter_s++;
    time1_conuter++;

      if(time1_conuter_s==40)
            {
                time1_conuter_s=0;        
            time_s++;

            if(time_s==60)
             {
                    time_s=0;
                    time_m++;

              if(time_m==30)
                 {          
                        time_m=0;
                        key4=1;
                 }
                }
        }
}

void start_stop_key_scan()           //按键检测
{
     if(start1==0)
     {
          //display();没有子程序怎么引用                         //消抖函数                
          if(start1==0)
          {
               //d[]=1;没有定义变量怎么引用
              start_key=~start_key;                   
               while(!start1)                         
                   {
                    //display();  没有子程序怎么引用                       
                    if(start1==1)                    
                         {
                         start_key=~start_key;
                          if(start_key)             
                               {
                                time_m=0;
                                time_s=5;       
                                start_stop_flag=1;  
                                start_djs_flag=1;    
                                //d[]=0; 没有定义变量怎么引用             
                                TR0=1;                
                              // TR1=1;
                               }
                              else                          
                                {
                             start_stop_flag=0;  
                                //time_s=0;
                                 //time_m=0;
                                 //d[]=0; 没有定义变量怎么引用   
                                             
                                }
                          
                         }
               }
          }
     } 
}

使用特权

评论回复
10
zwfj2418|  楼主 | 2008-9-24 07:43 | 只看该作者

程序还没写完。。

display()这个我还没写呢,难道这个没写和前面的定义有关系,这个程序还没写完,我只是想看看这个函数有没有错误。。。

使用特权

评论回复
11
zwfj2418|  楼主 | 2008-9-24 07:46 | 只看该作者

呵呵 还是谢谢你啊

真不好意思啊,谢谢你了啊

使用特权

评论回复
12
gjg191| | 2008-9-24 08:16 | 只看该作者

o

写完了最后再查错,不要打断自己的思路

使用特权

评论回复
13
zwfj2418|  楼主 | 2008-9-24 08:29 | 只看该作者

哦。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

21

主题

97

帖子

0

粉丝