| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 780 人关注过本帖
标题:用51实现断电保护的程序,但断电后还是回到0开始加,麻烦哪位大哥帮忙看下程 ...
取消只看楼主 加入收藏
lhysun_wolf
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-9-15
收藏
 问题点数:0 回复次数:0 
用51实现断电保护的程序,但断电后还是回到0开始加,麻烦哪位大哥帮忙看下程序那里有错误啊!!!
#include<reg52.h>
#define uchar unsigned char
sbit scl=P3^4;
sbit sda=P3^5;
sbit H1=P2^0;
sbit H2=P2^1;
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0xc0,0xf9,0xa4,0xb0

,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar num,a,shi,ge,aa;
void delay2(uint z)
{
    uint x, y;
        for(x=z;x>0;x--)
            for(y=110;y>0;y--);

}
void display(uchar shi,uchar ge)
{
   
            H1=0;
                           
            P0=table[shi];
            delay2(10);
            H2=1;           //ΪʲÃǼÓÒ»¸ö»á±äµÃ²»Ò»ÑùÄØ//  
            H1=1;
                        


                    
                        
            H2=0;
            P0=table[ge];
            delay2(10);
            H1=1;             //ͬÉÏ°¡/?/
            H2=1;
                        
                        
}


void delay()
{
    ; ;
}


void start()
{
    sda=1;
    delay();
    scl=1;
    delay();
    sda=0;
    delay();
      
}

void stop()
{
    sda=0;
    delay();
    scl=1;
    delay();
    sda=1;
    delay();
      
}

void init()
{
    num=0;
    TMOD=0X01;
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    ET0=1;
    EA=1;
    TR0=1;
    sda=1;
    delay();
    scl=1;
    delay();
}

void respons()
{
   uchar i;
    scl=1;
    delay();
    while((sda==1)&&(i<250))i++;
    scl=0;
    delay();
   
}

void write_byte(uchar date)
{
    uchar i,temp;
    temp=date;
   
    for(i=0;i<8;i++)
       {
           temp=temp<<1;                 
           scl=0;           
           delay();                     

           sda=CY;                    
           delay();
           scl=1;
           delay();
       }
      scl=0;
      delay();
      sda=1;
      delay();               



}

uchar read_byte()
{
    uchar i,k;
    scl=0;
    delay();
    sda=1;
    delay();
    for(i=0;i<8;i++)
        {
            scl=1;
            delay();
            k=(k<<1)|sda;            
            scl=0;
            delay();
        }        
          return k;


}

void delay1(uchar z)
{
    uchar a, b;
      for(a=z;a>0;a--)
         for(b=100;b>0;b--);
}

void write_add(uchar address,uchar date)
{
    start();
    write_byte(0xa0);
    respons();
    write_byte(address);
    respons();
    write_byte(date);
    respons();
    stop();

}

uchar read_add(uchar address)
{
    uchar date;
    start();
    write_byte(0xa0);
    respons();
    write_byte(address);
    respons();
    start();
    write_byte(0xa1);
    respons();
    date=read_byte();
    stop();
    return date;
}

void main()
{
     init();
   
    while(1)
      {
           if(a==20)
               {
                       a=0;
                    num++;
                    if(num==99)
                        {num=0;}
                    
                           write_add(23,num);
         
                           delay1(100);
                           aa=read_add(23);
                           P1=read_add(23);
                           shi=aa/10;
                           ge=aa%10    ;
                    
                 }

         
      
             display(shi,ge);
      
      }  
   
      
}


void timeo() interrupt 1
{
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    a++;
}
搜索更多相关主题的帖子: 断电 麻烦 
2010-09-29 22:08
快速回复:用51实现断电保护的程序,但断电后还是回到0开始加,麻烦哪位大哥帮忙 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050323 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved