|
https://v.youku.com/v_show/id_XNDE3OTAzMjc2OA==.html?x&sharefrom=android&sharekey=c76503937c785df7b02933df8c154c891
有重力感应,不管你正放还是反放都能正常显示,可以diy显示,显示号码,就是停车号码牌。温度,时间,月份交替显示。可以自定义显示,有倒计时,计分器,模拟电梯,闹钟,自定义图片文字显示功能。
电路原理图如下:
元件清单
PCB截图
制作步骤:将原理图绘制成PCB,PCB发给厂家打板,根据原件清单购买元器件,焊接,编程调试
焊接注意事项:单片机方向、DS1302时钟芯片方向,二极管方向。不要有虚焊、漏焊。
成品赏析
部分程序
- #include "STC15.H"
- #define _REAL_TIMER_DS1302_2003_7_21_
- sbit DS1302_CLK = P5^4; //实时时钟时钟线引脚
- sbit DS1302_IO = P5^5; //实时时钟数据线引脚
- sbit DS1302_RST = P2^3; //实时时钟复位线引脚
- sbit ACC0 = ACC^0;
- sbit ACC7 = ACC^7;
- sbit col1 = P0^0;//点阵上第22脚
- sbit col2 = P0^1;//点阵上第21脚
- sbit col3 = P0^2;//点阵上第2脚
- sbit col4 = P0^3;//点阵上第19脚
- sbit col5 = P0^4;//点阵上第5脚
- sbit col6 = P0^5;//点阵上第6脚或17脚
- sbit col7 = P0^6;//点阵上第16脚
- sbit col8 = P0^7;//点阵上第8脚
- sbit col9 = P2^0;//点阵上第13脚
- sbit col10 = P2^1;//点阵上第10脚
- sbit col11= P2^2;//点阵上第11脚
- sbit col12 = P1^0;//点阵上第22脚
- sbit col13 = P1^1;//点阵上第21脚
- sbit col14 = P1^2;//点阵上第2脚
- sbit col15 = P1^3;//点阵上第19脚
- sbit col16 = P1^4;//点阵上第5脚
- sbit col17 = P1^5;//点阵上第6脚或17脚
- sbit col18 = P1^6;//点阵上第16脚
- sbit col19 = P1^7;//点阵上第8脚
- sbit col20 = P2^4;//点阵上第13脚
- sbit col21 = P2^5;//点阵上第10脚
- sbit col22 = P2^6;//点阵上第11脚
- #define AM(X) X
- #define PM(X) (X+12) // 转成24小时制
- #define DS1302_SECOND 0x80
- #define DS1302_MINUTE 0x82
- #define DS1302_HOUR 0x84
- #define DS1302_WEEK 0x8A
- #define DS1302_DAY 0x86
- #define DS1302_MONTH 0x88
- #define DS1302_YEAR 0x8C
- #define DS1302_RAM(X) (0xC0+(X)*2) //用于计算 DS1302_RAM 地址的宏
- #define t_hour CurrentTime.TimeString[0]*10+CurrentTime.TimeString[1]
- #define t_min CurrentTime.TimeString[2]*10+CurrentTime.TimeString[3]
- #define t_sec CurrentTime.TimeString[4]*10+CurrentTime.TimeString[5]
- #define t_year CurrentTime.DateString[0]*10+CurrentTime.DateString[1]
- #define t_month CurrentTime.DateString[2]*10+CurrentTime.DateString[3]
- #define t_day CurrentTime.DateString[4]*10+CurrentTime.DateString[5]
- typedef struct __SYSTEMTIME__
- {
- unsigned char Second;
- unsigned char Minute;
- unsigned char Hour;
- unsigned char Week;
- unsigned char Day;
- unsigned char Month;
- unsigned char Year;
- unsigned char DateString[8];
- unsigned char TimeString[6];
- }SYSTEMTIME; //定义的时间类型
- unsigned int time=0;
- unsigned char disp[22],*pdisp;
- /******************************DS1302时钟模块***************************************/
- void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数)
- {
- unsigned char i;
- ACC = d;
- for(i=8; i>0; i--)
- {
- DS1302_IO = ACC0; //相当于汇编中的 RRC
- DS1302_CLK = 1;
- DS1302_CLK = 0;
- ACC = ACC >> 1;
- }
- }
- unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数)
- {
- unsigned char i;
- for(i=8; i>0; i--)
- {
- ACC = ACC >>1; //相当于汇编中的 RRC
- ACC7 = DS1302_IO;
- DS1302_CLK = 1;
- DS1302_CLK = 0;
- }
- return(ACC);
- }
- void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据
- {
- DS1302_RST = 0;
- DS1302_CLK = 0;
- DS1302_RST = 1;
- DS1302InputByte(ucAddr); // 地址,命令
- DS1302InputByte(ucDa); // 写1Byte数据
- DS1302_CLK = 1;
- DS1302_RST = 0;
- }
- unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据
- {
- unsigned char ucData;
- DS1302_RST = 0;
- DS1302_CLK = 0;
- DS1302_RST = 1;
- DS1302InputByte(ucAddr|0x01); // 地址,命令
- ucData = DS1302OutputByte(); // 读1Byte数据
- DS1302_CLK = 1;
- DS1302_RST = 0;
- return(ucData);
- }
- void DS1302_SetProtect(bit flag) //是否写保护
- {
- if(flag)
- Write1302(0x8E,0x10);
- else
- Write1302(0x8E,0x00);
- }
- void DS1302_SetTime(unsigned char Address, unsigned char Value) // 设置时间函数
- {
- DS1302_SetProtect(0);
- Write1302(Address, ((Value/10)<<4 | (Value%10)));
- }
- void DS1302_GetTime(SYSTEMTIME *Time)
- {
- unsigned char ReadValue;
- ReadValue = Read1302(DS1302_SECOND);
- Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //八进制转换成十进制
- ReadValue = Read1302(DS1302_MINUTE);
- Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_HOUR);
- Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_DAY);
- Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_WEEK);
- Time->Week = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_MONTH);
- Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- ReadValue = Read1302(DS1302_YEAR);
- Time->Year = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
- }
- void DateToStr(SYSTEMTIME *Time) //
- {
- Time->DateString[0] = Time->Year/10 ; //分离出个位和十位
- Time->DateString[1] = Time->Year%10 ;
- Time->DateString[2] = Time->Month/10;
- Time->DateString[3] = Time->Month%10 ;
- Time->DateString[4] = Time->Day/10 ;
- Time->DateString[5] = Time->Day%10 ;
- Time->DateString[6] = Time->Week/10 ;
- Time->DateString[7] = Time->Week%10 ;
- }
- void TimeToStr(SYSTEMTIME *Time)
- {
- Time->TimeString[0] = Time->Hour/10 ;
- Time->TimeString[1] = Time->Hour%10 ;
- Time->TimeString[2] = Time->Minute/10 ;
- Time->TimeString[3] = Time->Minute%10 ;
- Time->TimeString[4] = Time->Second/10;
- Time->TimeString[5] = Time->Second%10 ;
- }
- bit Initial_DS1302(void)
- {
- unsigned char Second=Read1302(DS1302_SECOND);
- if(Second&0x80)
- {
- DS1302_SetTime(DS1302_SECOND,0);
- return 1;
- }
- return 0;
- }
- /*****************************************************************************/
- /************************点阵显示函数**************************/
- code char num_font1[]={
- 0x3E,0x51,0x45,0x3E,//"0"
- 0x00,0x21,0x7F,0x01,//"1"
- 0x23,0x45,0x49,0x31,//"2"
- 0x22,0x49,0x59,0x2E,//"3"
- 0x0C,0x14,0x24,0x7F,//"4"
- 0x72,0x51,0x51,0x4E,//"5"
- 0x0E,0x19,0x29,0x46,//"6"
- 0x40,0x4F,0x50,0x60,//"7"
- 0x36,0x49,0x49,0x36,//"8"
- 0x32,0x49,0x49,0x3E,//"9"
- 0x00,0x36,0x36,0x00,//"::"
- };
- void buf_data(char num1,char num2)
- {
- char i;
- pdisp=&disp[0];
- for(i=0;i<4;i++)
- {
- *pdisp = num_font1[4*(num1/10)+i];
- pdisp++;
- }
- *pdisp = 0x00;
- pdisp++;
- for(i=0;i<4;i++)
- {
- *pdisp = num_font1[4*(num1%10)+i];
- pdisp++;
- }
- for(i=0;i<4;i++)
- {
- *pdisp = num_font1[40+i];
- pdisp++;
- }
- for(i=0;i<4;i++)
- {
- *pdisp = num_font1[4*(num2/10)+i];
- pdisp++;
- }
- *pdisp = 0x00;
- pdisp++;
- for(i=0;i<4;i++)
- {
- *pdisp = num_font1[4*(num2%10)+i];
- pdisp++;
- }
- }
- void delay(unsigned int xms)//延时函数,大概延时时间
- {
- unsigned int i,j;
- for(i=xms;i>0;i--) //i=xms即延时约xms毫秒
- for(j=125;j>0;j--);
- }
- void led_clear()//清屏
- {
- P4 &= 0x80;
- P1 |= 0xff;
- P0 |= 0xff;
- P2 |= 0x77;
- }
- void display_frame()//显示一帧画面
- {
- char i;
- for(i=0;i<22;i++)
- {
- led_clear();
- switch(i+1)
- {
- case 1: col1=0; break;
- case 2: col2=0; break;
- case 3: col3=0; break;
- case 4: col4=0; break;
- case 5: col5=0; break;
- case 6: col6=0; break;
- case 7: col7=0; break;
- case 8: col8=0; break;
- case 9: col9=0; break;
- case 10: col10=0; break;
- case 11: col11=0; break;
- case 12: col12=0; break;
- case 13: col13=0; break;
- case 14: col14=0; break;
- case 15: col15=0; break;
- case 16: col16=0; break;
- case 17: col17=0; break;
- case 18: col18=0; break;
- case 19: col19=0; break;
- case 20: col20=0; break;
- case 21: col21=0; break;
- case 22: col22=0; break;
- default:break;
- }
- P4=disp[i];
- if(time>500)
- {
- col11 = 1;
- col12 = 1;
- }
- if(time>1000)
- {
- time=0;
- }
- delay(5);
- }
- }
- /*****************************************************************/
- void Timer0Init(void) //1毫秒@11.0592MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0xCD; //设置定时初值
- TH0 = 0xD4; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- }
- void init()//初始化设置,推挽输出(强上拉输出,可达20mA)
- {
- P1M1 = 0X00;
- P1M0 = 0Xff;
- P2M1 = 0X00;
- P2M0 = 0Xff;
- P4M1 = 0X00;
- P4M0 = 0Xff;
- }
- void main()
- {
- SYSTEMTIME CurrentTime;
- init();
- led_clear();
- Timer0Init();
- EA=1; //总中断打开
- ET0=1; //定时器中断打开
-
- DS1302_SetTime(DS1302_YEAR,0); // 设置年月日为2000年1月1日
- DS1302_SetTime(DS1302_MONTH,1);
- DS1302_SetTime(DS1302_DAY,1);
- DS1302_SetTime(DS1302_HOUR,0); //设置的时间是01:00:00
- DS1302_SetTime(DS1302_MINUTE,0);
- DS1302_SetTime(DS1302_SECOND,0);
-
- while(1)
- {
- DS1302_GetTime(&CurrentTime);//获取当前时间
- DateToStr(&CurrentTime);
- TimeToStr(&CurrentTime);
- buf_data(t_min,t_sec);
- display_frame();
- }
- }
- void Timer0_isr(void) interrupt 1
- {
- time++;
- }
复制代码
全部资料51hei下载地址:
创意时钟2.rar
(5.07 MB, 下载次数: 61)
|
评分
-
查看全部评分
|