欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機+DS1302寫入年月日程序與Proteus仿真
[打印本頁]
作者:
com456
時間:
2022-5-28 15:06
標題:
單片機+DS1302寫入年月日程序與Proteus仿真
萌新程序,大佬門見諒。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.gif
(84.42 KB, 下載次數: 28)
下載附件
2022-5-29 22:26 上傳
單片機源程序如下:
#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
sbit RST=P1^6;
sbit SCK=P1^4;
sbit IO=P1^5;
uint m,f,h,t,a;
uchar shu1[8]={6,5,4,3,2,7,1};
uchar shu2[8];
void delay_LCD(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void com(uchar com)
{
rs=0;
e=0;
rw=0;
P0=com;
delay_LCD(1);
e=1;
delay_LCD(1);
e=0;
}
void shu(uchar shu)
{
rs=1;
e=0;
rw=0;
P0=shu;
delay_LCD(1);
e=1;
delay_LCD(1);
e=0;
}
void chu( )
{
com(0x38);
com(0x0c);
com(0x01);
com(0x06);
}
ds1302_read(uchar add)
{
uint i,m1,m;
RST=0; _nop_();
SCK=0; _nop_();
RST=1;
for(i=0;i<8;i++)
{
IO=add&0x01;
add=add>>1;
SCK=1;_nop_();
SCK=0;_nop_();
}
for(i=0;i<8;i++)
{
m1=IO;
m=(m>>1)|(m1<<7);
SCK=1;_nop_();
SCK=0;_nop_();
}
RST=0;_nop_();
SCK=1;
_nop_();IO = 0;
_nop_();IO = 1;
_nop_();
return m;
}
void ds1302_write(uchar add,uchar m)
{
uchar i;
RST=0;
_nop_();
SCK=0;
_nop_();
RST=1;
for(i=0;i<8;i++)
{
IO=add&0x01;
add=add>>1;
SCK=1;
_nop_();
SCK=0;
_nop_();
}
for(i=0;i<8;i++)
{
IO=m&0x01;
m=m>>1;
SCK=1;
_nop_();
SCK=0;
_nop_();
}
RST=0;
_nop_();
}
read_ds1302()
{
uchar i;
shu1[6]=ds1302_read(0x81)&0x7f;
shu1[5]=ds1302_read(0x83);
shu1[4]=ds1302_read(0x85);
shu1[3]=ds1302_read(0x87);
shu1[2]=ds1302_read(0x89);
shu1[7]=ds1302_read(0x8b);
shu1[1]=ds1302_read(0x8d);
for(i=1;i<8;i++)
{
shu2[i]=(shu1[i]>>4)*10+(shu1[i]&0x0f);
}
}
void ds1302_init()
{
RST=0;
SCK=0;
ds1302_write(0x8e,0x00);
ds1302_write(0x80,0x14);
ds1302_write(0x82,0x13);
ds1302_write(0x84,0x12);
ds1302_write(0x8a,0x04);
ds1302_write(0x86,0x22);
ds1302_write(0x88,0x02);
ds1302_write(0x8c,0x22);
ds1302_write(0x8e,0x80);
}
//lcd_riqi(uchar ddd1,uchar dat1)
//{
//uchar gw,sw;
//gw=dat1%10;
//sw=dat1/10;
//com(0x80+ddd1);
//shu(0x30+sw);
//shu(0x30+gw);
//}
//lcd_shijian(uchar ddd2,uchar dat2)
//{
//uchar gw,sw;
//gw=dat2%10;
//sw=dat2/10;
//com(0x80+0x40+ddd2);
//shu(0x30+sw);
//shu(0x30+gw);
//}
//lcd_write(uchar *shuju)
//{
//lcd_riqi(0,shuju[0]);
//lcd_riqi(2,shuju[1]);
//lcd_riqi(5,shuju[2]);
//lcd_riqi(8,shuju[3]);
//lcd_shijian(0,shuju[4]);
//lcd_shijian(3,shuju[5]) ;
//lcd_shijian(6,shuju[6]);
// }
void main()
{
chu();
ds1302_init();
while(1)
{
read_ds1302();
com(0x82);
shu(shu2[1]/10+0x30);
shu(shu2[0]%10+0x30);
shu(shu2[1]/10+0x30);
shu(shu2[1]%10+0x30);
shu('-');
shu(shu2[2]/10+0x30);
shu(shu2[2]%10+0x30);
shu('-');
shu(shu2[3]/10+0x30);
shu(shu2[3]%10+0x30);
com(0xc2);
shu(shu2[4]/10+0x30);
shu(shu2[4]%10+0x30);
shu(':');
shu(shu2[5]/10+0x30);
shu(shu2[5]%10+0x30);
shu(':');
shu(shu2[6]/10+0x30);
shu(shu2[6]%10+0x30);
}
}
復制代碼
Keil代碼與Proteus8.8仿真下載:
寫入年月日.zip
(71.92 KB, 下載次數: 18)
2022-5-28 15:04 上傳
點擊文件名下載附件
萌新大佬門多多包涵
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1