旋转时钟

准备制作一个旋转时钟,构思了一下,旋转时钟主要包括以下几个部分:

指针板、基板、电机、耦合线圈,用于电力的无线传输、无线串口,用于调试、显示和控制。


2013-10-10

至今天已经完成:

1.AVR单片机对时钟芯片DS1302的读写等操作

2.串口传输部分代码编写完成

准备完成:

1.红外遥控器编码的解码

2.程序匠人的程序原理深入了解,编写LED显示程序

3.购买旋转时钟配件,完成电源的无线传输电路设计与测试,LED板设计。

存在问题:

设置INT0中断为上升沿触发,每触发一次中断,将触发间隔的时间内累加计数传出来。但是用手触碰接收头时,串口会有数据传出。

项目进展:

1.DS1302时钟芯片的读写。

C语言文件:

#include "common.h"

/*-----------------------------------------------------------------
函数名称: void ds1302_init(void)
函数功能: ds1302总线初始化
参    数: 无
返 回 值: 无
-----------------------------------------------------------------*/
void ds1302_init(void)
{
 	RST_CLR;			 
	SCK_CLR;			 
	RST_OUT;			 
	SCK_OUT;
}
/*-----------------------------------------------------------------
函数名称: void ds1302_write_byte(unsigned int addr,unsigned int data)
函数功能: 向DS1302目标地址中写入一字节数据
参    数: 目标地址 一字节数据
返 回 值: 无
-----------------------------------------------------------------*/
void ds1302_write_byte(unsigned int addr,unsigned int data)
{
 	 unsigned int i;
	 RST_CLR;
	 SCK_CLR;
 	 RST_SET;//启动DS1302总线
	 //传输目标地址
	 IO_OUT;
	 addr&=0xfe;
	 for(i=0;i<8;i++)
	 {
	  if(addr&0x01)
	    {IO_SET;My_Putchar(0x31);}
	  else
	    {IO_CLR;My_Putchar(0x30);}
	 SCK_CLR;
	 SCK_SET;	 
	 addr=addr>>1;
	 }
	 //向目标地址中写入数据
	 IO_OUT;
	 My_Putstr("data:");
	 for(i=0;i<8;i++)
	 {
	  if(data&0x01)
	    {IO_SET;My_Putchar(0x31);}
		
	  else
	    {IO_CLR;My_Putchar(0x30);}
	 SCK_CLR;
	SCK_SET; 
	 data=data>>1;
	 }
	 RST_CLR;//禁止DS1302总线
}


/*-----------------------------------------------------------------
函数名称: int ds1302_read_byte(unsigned int addr)
函数功能: 从DS1302目标地址中读取一字节数据
参    数: 目标地址
返 回 值:  一字节数据
-----------------------------------------------------------------*/
unsigned int ds1302_read_byte(unsigned int addr)
{
 	unsigned int i,temp;
	temp=0x00;
	RST_CLR;
	SCK_CLR;
 	RST_SET;//启动DS1302总线
	//写入目标地址
 	IO_OUT;
 	addr=addr|0x01;
 	for(i=0;i<8;i++)
 	{
	 SCK_CLR;
 	 if(addr&0x01)
 	   IO_SET;
 	    else
 	   IO_CLR;
	 SCK_SET;
	 addr=addr>>1;
 	 }
	 //读取目标地址数据
	 IO_IN;
	 for(i=0;i<8;i++)
	 {	  
	  if(IO_R)
	   temp=temp|0x80;
	  else
	   temp=temp&0x7f;
	  SCK_SET;SCK_CLR;
	  temp=temp>>1;
	 }
	 RST_CLR;//禁止DS1302总线
	 return temp;
}

/*-----------------------------------------------------------------
函数名称: void ds1302_write_time(unsigned int *time_data)
函数功能: 将日期信息写入DS1302中
参    数: 数组中的时间信息
返 回 值: 无
-----------------------------------------------------------------*/
void ds1302_write_time(unsigned int *time_data)
{
    ds1302_write_byte(ds1302_control_addr,0x00);//解除写禁止;最高位WP清零
    ds1302_write_byte(ds1302_sec_addr,0x10);//暂停时钟;CH位置位
 	time_data++;
	ds1302_write_byte(ds1302_year_addr,*time_data++);	//只写入后面两位 08
	ds1302_write_byte(ds1302_month_addr,*time_data++);	//月 
	ds1302_write_byte(ds1302_date_addr,*time_data++);    //日  
	ds1302_write_byte(ds1302_hr_addr,*time_data++);		//时 
	ds1302_write_byte(ds1302_min_addr,*time_data++);		//分
	ds1302_write_byte(ds1302_sec_addr,*time_data++);		//秒
	ds1302_write_byte(ds1302_day_addr,*time_data);		//周 
	ds1302_write_byte(ds1302_control_addr,0x80);			//打开写保护 
}

/*-----------------------------------------------------------------
函数名称: void ds1302_read_time(unsigned char *time_data)
函数功能: 从DS1302中读取日期时间信息
参    数: 日期时间信息存放数组的地址
返 回 值: 无
-----------------------------------------------------------------*/
void ds1302_read_time(unsigned int *time_data)  
{ 
    time_data++;
	*time_data=ds1302_read_byte(ds1302_year_addr);	    //只读出后面两位08
	time_data++;
	*time_data=ds1302_read_byte(ds1302_month_addr);	    //月 
	time_data++;
	*time_data=ds1302_read_byte(ds1302_date_addr);		//日 
	time_data++;
	*time_data=ds1302_read_byte(ds1302_hr_addr);		    //时 
	time_data++;
	*time_d
  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 HTML 时钟示例: ```html <!DOCTYPE html> <html> <head> <title>HTML 时钟</title> <style> .clock { display: block; margin: 50px auto; width: 200px; height: 200px; border-radius: 50%; border: 10px solid #333; position: relative; } .hour-hand { position: absolute; top: 50%; left: 50%; transform-origin: bottom; height: 40px; width: 6px; background: #333; margin-left: -3px; } .minute-hand { position: absolute; top: 50%; left: 50%; transform-origin: bottom; height: 60px; width: 4px; background: #333; margin-left: -2px; } .second-hand { position: absolute; top: 50%; left: 50%; transform-origin: bottom; height: 80px; width: 2px; background: red; margin-left: -1px; z-index: 1; } .dot { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 12px; height: 12px; border-radius: 50%; background: #333; z-index: 2; } </style> </head> <body> <div class="clock"> <div class="hour-hand"></div> <div class="minute-hand"></div> <div class="second-hand"></div> <div class="dot"></div> </div> <script> function updateClock() { let now = new Date(); let hour = now.getHours(); let minute = now.getMinutes(); let second = now.getSeconds(); let hourHand = document.querySelector(".hour-hand"); let minuteHand = document.querySelector(".minute-hand"); let secondHand = document.querySelector(".second-hand"); let hourDegree = hour * 30 + minute * 0.5; let minuteDegree = minute * 6; let secondDegree = second * 6; hourHand.style.transform = `rotate(${hourDegree}deg)`; minuteHand.style.transform = `rotate(${minuteDegree}deg)`; secondHand.style.transform = `rotate(${secondDegree}deg)`; } setInterval(updateClock, 1000); </script> </body> </html> ``` 这个时钟由一个圆形的表盘和三个时针组成,使用 CSS 进行样式设置,并使用 JavaScript 每秒更新时针的旋转角度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值