亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码

標(biāo)題: 利用ds302的時(shí)候,用數(shù)碼管顯示,數(shù)碼管顯示不正常 [打印本頁(yè)]

作者: 無(wú)良的魚(yú)    時(shí)間: 2020-2-19 23:23
標(biāo)題: 利用ds302的時(shí)候,用數(shù)碼管顯示,數(shù)碼管顯示不正常

以下為源程序:
——————————————————————————————————————————————————————
#include<reg52.h>
#include<intrins.h>
sbit SCK=P1^7;  
sbit SDA=P2^3;  
sbit RST=P1^3;
unsigned char we[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
/*單字節(jié)寫(xiě)入一字節(jié)數(shù)據(jù)*/
void Write_Ds1302_Byte(unsigned char dat)
{
unsigned char i;
SCK = 0;
for (i=0;i<8;i++)
{
  if (dat & 0x01)  // 等價(jià)于if((addr & 0x01) ==1)
  {
   SDA=1;
  }
  else
  {
   SDA=0;
  }   
  SCK=1;
  SCK=0;  
  dat = dat >> 1;
}
}
/********************************************************************/
/*單字節(jié)讀出一字節(jié)數(shù)據(jù)*/
unsigned char Read_Ds1302_Byte(void)
{
unsigned char i, dat=0;
for (i=0;i<8;i++)
{
  dat = dat >> 1;
  if (SDA)  
  {
   dat |= 0x80;
  }
  else
  {
   dat &= 0x7F;
  }
  SCK=1;
  SCK=0;
}
return dat;
}
/********************************************************************/
/*向DS1302 單字節(jié)寫(xiě)入一字節(jié)數(shù)據(jù)*/
void Ds1302_Single_Byte_Write(unsigned char addr, unsigned char dat)
{
RST=0;   /*RST腳置低,實(shí)現(xiàn)DS1302的初始化*/
SCK=0;   /*SCK腳置低,實(shí)現(xiàn)DS1302的初始化*/
RST=1;   /*啟動(dòng)DS1302總線,RST=1電平置高 */
  
Write_Ds1302_Byte(addr); /*寫(xiě)入目標(biāo)地址:addr,保證是寫(xiě)操作,寫(xiě)之前將最低位置零*/
Write_Ds1302_Byte(dat);  /*寫(xiě)入數(shù)據(jù):dat*/
RST=0;     /*停止DS1302總線*/
}
/********************************************************************/
/*從DS1302單字節(jié)讀出一字節(jié)數(shù)據(jù)*/
unsigned char Ds1302_Single_Byte_Read(unsigned char addr)
{
unsigned char temp;
RST=0;   /*RST腳置低,實(shí)現(xiàn)DS1302的初始化*/
SCK=0;   /*SCK腳置低,實(shí)現(xiàn)DS1302的初始化*/
RST=1; /*啟動(dòng)DS1302總線,RST=1電平置高 */
        
Write_Ds1302_Byte(addr); /*寫(xiě)入目標(biāo)地址:addr,保證是讀操作,寫(xiě)之前將最低位置高*/
temp=Read_Ds1302_Byte(); /*從DS1302中讀出一個(gè)字節(jié)的數(shù)據(jù)*/  
RST=0; /*停止DS1302總線*/
return temp;
}
unsigned char dat_bcd(date)
{
unsigned char dat1,dat2;
dat1=date/10;
dat2=date%10;
dat2=dat2+dat1*16;
return dat2;

}
unsigned char bcd_dat(date)
{
unsigned char dat1,dat2;
dat1=date/16;
dat2=date%16;
dat2=dat2+dat1*10;
return dat2;
}
void Delay1ms()  //@11.0592MHz
{
unsigned char i, j;
_nop_();
i = 2;
j = 199;
do
{
  while (--j);
} while (--i);
}

void display(unsigned char sec,unsigned char min,unsigned char hour)
{
P2=0xc0;P0=we[0];P2=0x00;P2=0xe0;P0=~duan[hour/10];P2=0x00;Delay1ms();
P2=0xc0;P0=we[1];P2=0x00;P2=0xe0;P0=~duan[hour%10];P2=0x00;Delay1ms();
P2=0xc0;P0=we[2];P2=0x00;P2=0xe0;P0=0xff;P2=0x00;Delay1ms();
P2=0xc0;P0=we[3];P2=0x00;P0 = 0xff;P2=0xe0;P0=~duan[min/10];P2=0x00;Delay1ms();
P2=0xc0;P0=we[4];P2=0x00;P0 = 0xff;P2=0xe0;P0=~duan[min%10];P2=0x00;Delay1ms();
P2=0xc0;P0=we[5];P2=0x00;P2=0xe0;P0=0xff;P2=0x00;Delay1ms();
P2=0xc0;P0=we[6];P2=0x00;P0 = 0xff;P2=0xe0;P0=~duan[sec/10];P2=0x00;Delay1ms();
P2=0xc0;P0=we[7];P2=0x00;P0 = 0xff;P2=0xe0;P0=~duan[sec%10];P2=0x00;Delay1ms();
}
void main()
{
unsigned char sec,min,hour;
Ds1302_Single_Byte_Write(0x8e,0x00);
Ds1302_Single_Byte_Write(0x80,dat_bcd(45));//秒
Ds1302_Single_Byte_Write(0x82,dat_bcd(49));//分
Ds1302_Single_Byte_Write(0x84,dat_bcd(16));//時(shí)
Ds1302_Single_Byte_Write(0x8e,0x80);
while(1)
{
  
  sec=bcd_dat(Ds1302_Single_Byte_Read(0x81));
  min=bcd_dat(Ds1302_Single_Byte_Read(0x83));
  hour=bcd_dat(Ds1302_Single_Byte_Read(0x85));
  
  display(sec,min,hour);
  
}

}


作者: wulin    時(shí)間: 2020-2-20 07:10
樓主沒(méi)有提供硬件電路,不易準(zhǔn)確判斷問(wèn)題所在,但有一點(diǎn)可以看出ds1302的SDA使用了P2.3,數(shù)碼管段碼和位碼鎖存器的使能端使用了P2的某兩個(gè)端口。在顯示程序中明顯看出樓主對(duì)P2操作不當(dāng)。
作者: 無(wú)良的魚(yú)    時(shí)間: 2020-2-20 10:43
wulin 發(fā)表于 2020-2-20 07:10
樓主沒(méi)有提供硬件電路,不易準(zhǔn)確判斷問(wèn)題所在,但有一點(diǎn)可以看出ds1302的SDA使用了P2.3,數(shù)碼管段碼和位碼 ...

請(qǐng)問(wèn)能和否告訴我哪里錯(cuò)了呢,百思不得其解





歡迎光臨 (http://www.denmoz.com/bbs/) Powered by Discuz! X3.1