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

📄 ds.c

📁 基于51单片机ds1302温度测量源码加仿真
💻 C
字号:
#include <at89x51.h>
#include "lcd_h.h"
const char LCDnum[10]="0123456789";
sbit rst=P2^5;
sbit sclk=P2^7;
sbit io=P2^6;
void write_8bit(unsigned char dat)
{
	 unsigned char i=0;
	 sclk=0;
	 for (i=0;i<8;i++)
	 {
	 	 if (dat&0x01) io=1;
		 else io=0;
		 sclk=1;
		 sclk=0;
		 dat=dat>>1;
	 }
}
void write_data(unsigned char address,unsigned char dat)
{
	 rst=0;
	 sclk=0;
	 rst=1;
	 write_8bit(address);
	 write_8bit(dat);
	 sclk=1;
	 rst=0;
}
unsigned char read_8bit(void)
{
	 unsigned char receive=0,i=0;
	 sclk=0;
	 for (i=0;i<8;i++)
	 {
	 	 receive=receive>>1;
		 if (io==1) receive=receive|0x80;
		 sclk=1;
		 sclk=0;
	 }
	 return (receive);
}
unsigned char read_dat(unsigned char address)
{
	 unsigned char receive1=0,i=0;
	 rst=0;
	 sclk=0;
	 rst=1;
	 write_8bit(address);
	 io=1;
	 receive1=read_8bit();
	 sclk=1;
	 rst=0;
	 return (receive1);
}
void ds1302(void)
{
	 rst=0;
	 sclk=0;
	 rst=1;
	 write_8bit(0x8e);
  	 write_8bit(0);
	 //sclk=1;
	 rst=0;
	 write_8bit(0x90);
  	 write_8bit(0xa5);
	 rst=0;
	 write_data(0x80,0);
	 write_data(0x82,0);
	 rst=0;
	 sclk=0;
	 rst=1;
	 write_8bit(0x8e);
     write_8bit(0x80);
	 //sclk=1;
	 rst=0;
}
void main(void)
{
	 unsigned char second[2]={0,0};
	 delayms(50);
	 
	 init_LCD();
	 clear_LCD();
	 movexy(1,1);
	 do
	 {
			if (P2_0==0)
			{
				ds1302();
				while(P2_0!=1);
			 }
			second[0]=read_dat(0x81);

			second[1]=second[0];
			second[0]=second[0]&0x0f;

			second[1]=second[1]&0x70;
			second[1]=second[1]>>4;
			movexy(1,0);

			write_LCD_data(LCDnum[second[1]]);
			write_LCD_data(LCDnum[second[0]]);

	 }while(1);
}

⌨️ 快捷键说明

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