⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds1302.c

📁 Demo HZ256 Cluster LCD2 CW31 SH v1 ICD
💻 C
字号:
//ds1302 program
#include "H256Port.h" 
 //PORTB|=0x40;
 // DDRB|=0x40;
//pb5--sck
//pb4--io
//pb3--rst 



void delayMS(unsigned int delayData) 
  {
   unsigned int i,j;
   for(j=0;j<delayData;j++)
    {
       for(i=0;i<100;i++)
              ;
    }
   
  }




/*write a byte */
void inputByte1302(unsigned char data)
  { 
  unsigned char i,j;
  j=0x01;
  for(i=0;i<8;i++)
    {
        if((j&data)==j)
            PORTB|=0x10;
        
        else 
            PORTB&=0xef;
        PORTB|=0x08;;  
        delayMS(1);       //clk
        PORTB&=0xf7;
        delayMS(1);
        j=j<<1;
      
    } 
  }
/*read a byte */  
unsigned char outputByte1302(void)  
  {
    unsigned char i,j=0;
    DDRB&=0xef;
    for(i=0;i<8;i++)   //?????????????
      {
        j=j>>1;
        if((PORTB&0x10)==0x10)
           j|=0x80;
        PORTB|=0x08;; //clk
        delayMS(1);
        PORTB&=0xf7;
        delayMS(1);
          
        
      }
      DDRB|=0x10;
    return j;  
      
  }
 //write address and data to 1302 
  void write1302(unsigned char addr,unsigned char data)
    {
        PORTB&=0xdf;
        delayMS(1);
        PORTB&=0xf7;
        delayMS(1);
        PORTB|=0x20;
        delayMS(1);
        inputByte1302(addr);
        inputByte1302(data);
        //PORTB|=0x20;  ???????????????????/
        delayMS(1);
        PORTB&=0xdf; 
      
    }
//read data from adress od 1302
unsigned char read1302(unsigned char addr)
  {
    unsigned char data ;
    PORTB&=0xdf;
    delayMS(1);
    PORTB&=0xf7;
    delayMS(1);
    PORTB|=0x20;
    delayMS(1);
    inputByte1302(addr);
    data=outputByte1302();
   // PORTB|=0x20;    ??????????????????//
    delayMS(1);
    PORTB&=0xdf; 
    return data; 
    
  }
  
  //set start time 1302
  void setInitial1302(unsigned char *pClock)
    {
      unsigned char i;
      unsigned char addr=0x80;
      
     
      write1302(0x8e,0x00);     //wp=0,write operation
      write1302(0x80,0x00);  //?????????????/
      
      for(i=0;i<7;i++)
        {
           write1302(addr,*pClock);//second,minute,hour,........
           pClock++;
           addr+=2;
        }
        write1302(0x8e,0x80);//wp=1;write protect
    }
  //get current time 1302
  void get1302(unsigned char currTime[])
    {
      unsigned char i;
      unsigned char addr=0x81;//????????????????//
      
       
      
      for(i=0;i<7;i++)    //??????????????????/
        {
          currTime[i]=read1302(addr);
          addr+=2;
        }
        
     
     
    }
  
  
  
  
  
  
  
  
  
  
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -