LED點陣數(shù)字鐘溫度計_第1頁
LED點陣數(shù)字鐘溫度計_第2頁
LED點陣數(shù)字鐘溫度計_第3頁
LED點陣數(shù)字鐘溫度計_第4頁
LED點陣數(shù)字鐘溫度計_第5頁
已閱讀5頁,還剩46頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、LED點陣數(shù)字鐘與溫度計系統(tǒng)設(shè)計方案本LED點陣數(shù)字鐘基于STC89C52RC單片機設(shè)計,使用5片6*7的LED點陣作為顯示屏。通過設(shè)計系統(tǒng)可以完成顯示時間,日期,并增加了用DS18B20溫度傳感器顯示溫度的功能。同時,通過程序的改變可以為點陣數(shù)字鐘擴充例如鬧鐘,字幕滾屏等功能。 LED點陣數(shù)字鐘通過單片機來完成計時,設(shè)定,溫度測量等功能。顯示部分通過74HC595通用移位寄存器,完成點陣屏幕與單片機連接從而完成顯示部分的功能。其系統(tǒng)組成框圖如下:按鍵1按鍵2按鍵3STC89C52RCDS1302274HC595LED點陣圖1單元電路設(shè)計1.MCU控制部分單片機的時鐘周期由外部12M晶振,時間

2、信息則通過DS1302產(chǎn)生。DS1302通過串行方式與單片機進行數(shù)據(jù)傳送,能夠向單片機提供包括秒、分、時、日、月、年等在內(nèi)的實時時間信息,并可對月末日期、閏年天數(shù)自動進行調(diào)整;它還擁有用于主電源和備份電源的雙電源引腳,在主電源關(guān)閉的情況下,也能保持時鐘的連續(xù)運行。從而完成斷電計時的功能。其中DS1302采用32.768KHz的晶振提供時鐘周期(原理圖見附錄1)2.LED點陣顯示部分 74HC595通用移位寄存器并行輸出端具有輸出鎖存功能。與單片機連接簡單方便,只須三個I/O口即可。而且通過芯片的Q7引腳和SER引腳,可以級聯(lián)。點陣屏幕由5片6*7的LED點陣組成。采用74HC595來實現(xiàn)時鐘的

3、動態(tài)顯示。點陣屏幕段選碼由4片74HC595控制,段選數(shù)據(jù)由74HC595的SER引腳串行輸入,由于輸出使能時鐘RCLK并接在一起,因此,4片74HC595并行輸出端同時輸出。而5個點陣位選信號也并接在一起,因此,一次可以同時點亮4列此過程類似于靜態(tài)顯示。每片74HC595并行輸出端并接到點陣的每一位的引腳,用于掃描輸出,此過程類似于動態(tài)掃描過程。此方法運用4片74HC595,7條位選信號,從而實現(xiàn)LED點陣的顯示.其中位選控制端為通過經(jīng)三極管放大后的P2口輸出信號控制。(原理圖見附錄2)3.電源部分采用普通電源接口和USB接口,可以使用5V,400mA電源供電,亦可使用電腦USB供電。預(yù)設(shè)備

4、用電源紐扣電池接口,保證時鐘斷電后繼續(xù)走時。程序設(shè)計定義字符#include "reg52.h"#define uchar unsigned char #define uint unsigned int/74HC595管腳定義sbit S_DIO = P30; sbit S_CLK = P31; sbit R_CLK = P32;/按鍵管腳定義sbit KEY_1 = P11; sbit KEY_2 = P12; sbit KEY_3 = P10;/蜂鳴器管腳定義sbit BEEP = P27;/DS18B20管腳定義sbit DQ = P34;uchar temp_val

5、ue; unsigned char tempL=0; /設(shè)全局變量unsigned char tempH=0; unsigned int sdata;/測量到的溫度的整數(shù)部分unsigned char xiaoshu1;/小數(shù)第一位unsigned char xiaoshu2;/小數(shù)第二位unsigned char xiaoshu;/兩位小數(shù)bit fg=1; /溫度正負標(biāo)志,等于0時為負數(shù)/DS1302管腳定義sbit T_CLK = P35; sbit T_IO = P36; sbit T_RST = P37; sbit ACC0 = ACC0;sbit ACC1 = ACC1;sbit

6、ACC2 = ACC2;sbit ACC3 = ACC3;sbit ACC4 = ACC4;sbit ACC5 = ACC5;sbit ACC6 = ACC6;sbit ACC7 = ACC7;bit distime,disdate,disyear,distweek,diswendu,setyear,setdate,settime,setalarm,setweek;unsigned char code Bmp74= 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0

7、xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, ;unsigned char code font7= 0x38,0x44,0x64,0x54,0x4C,0x44,0x38,/0xF8,0x88,0x88,0x88,0x88,0x88,0xF8, /-'0' 0x10,0x18,0x10,0x10,0x10,0x10,0x38,/0x20,0x30,0x28,0x20,0x20,0x20,0xF8, /-'1' 0x38,0x44,0x40,0x20,0x10,0x08,0x7C,/0xF8,0x8

8、0,0x80,0xF8,0x08,0x08,0xF8, /-'2' 0x7C,0x20,0x10,0x20,0x40,0x44,0x38,/0xF8,0x80,0x80,0xF8,0x80,0x80,0xF8, /-'3' 0x20,0x30,0x28,0x24,0x7C,0x20,0x20,/0x48,0x48,0x48,0x48,0xF8,0x40,0x40, /-'4' 0x7C,0x04,0x3C,0x40,0x40,0x44,0x38,/0xF8,0x08,0x08,0xF8,0x80,0x80,0xF8, /-'5'

9、0x70,0x08,0x04,0x3C,0x44,0x44,0x38,/0xF8,0x08,0x08,0xF8,0x88,0x88,0xF8, /-'6' 0x7C,0x40,0x20,0x10,0x08,0x08,0x08,/0xF8,0x80,0x80,0x80,0x80,0x80,0x80, /-'7' 0x38,0x44,0x44,0x38,0x44,0x44,0x38,/0xF8,0x88,0x88,0xF8,0x88,0x88,0xF8, /-'8' 0x38,0x44,0x44,0x78,0x40,0x20,0x1C,/0xF8,0

10、x88,0x88,0xF8,0x80,0x80,0x80, /-'9' 0x00,0x30,0x30,0x00,0x30,0x30,0x00, /-10-':' 0x78,0x48,0x78,0x48,0x78,0x48,0x64, /-11-'月'0x78,0x48,0x48,0x78,0x48,0x48,0x78, /-12-'日'0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /-13-'' 0x00,0x00,0x00,0x00,0x00,0x00,0x00, /-14-'

11、' 0x3C,0x44,0x44,0x44,0x44,0x44,0x3C, /-15-' D'0x44,0x44,0x44,0x28,0x10,0x10,0x10, /-16-' Y' 0x08,0xF8,0x24,0xF8,0x28,0xFC,0x20, /-17-'年'0x88,0xA8,0xA8,0xA8,0xA8,0xF8,0x70, /-18-' W'0x88,0x48,0x28,0x18,0x28,0x48,0x88,/-19-' K'0x00,0x00,0x00,0x38,0x00,0x00,

12、0x00,/-20-'-'0x00,0x00,0x00,0x00,0x00,0x30,0x30, /-21-'.'0xE8,0x10,0x10,0x10,0x10,0x10,0xE0, /-22-''· ;unsigned char idata DisTemp57;unsigned char idata Dis5;/時鐘數(shù)據(jù)(7字節(jié)BCD碼)格式為: 秒 分 時 日 月星期 年Unsigned char idata Time7; /=0x30,0x42,0x23,0x18,0x06,0x04,0x09;unsigned char ida

13、ta alarm2=0x30,0x06;uchar alarm_hh,alarm_ss,alarm_fg,alarm_off,flag;/鬧鐘unsigned char idata CSRow7=0x01,0x02,0x04,0x08,0x10,0x20,0x40;unsigned char idata second,minute,hour,day,month,week,year,time_revise;unsigned char idata keyvalue;unsigned long int idata Disbuf5;unsigned long int idata Disbuftemp7

14、;unsigned int ss,i,TimeT1;/* * 函數(shù)名: Delay * 功能描述:延時(帶參數(shù)) */ void Delay(unsigned int i) unsigned int j;for(j=0;j<i;j+);/* * 函數(shù)名: KeyOff * 功能描述: */void KeyOff() if(keyvalue=2|keyvalue=1|keyvalue=3)alarm_off=1;/* * 函數(shù)名: OutData * 功能描述:發(fā)送數(shù)據(jù) */ void OutData(unsigned char Data) SBUF=Data; while(TI=0);

15、/判斷是否發(fā)送完畢 TI=0;/* * 函數(shù)名: BCD2HEX * 功能描述: */ unsigned char BCD2HEX(unsigned char BCDChar) unsigned char temp; temp=(BCDChar/16*10+BCDChar%16); return temp; /* * 函數(shù)名: HEX2BCD * 功能描述: */ unsigned char HEX2BCD(unsigned char HEXChar) unsigned char temp; temp=(HEXChar/10*16+HEXChar%10); return temp; /* *

16、函數(shù)名: WriteByteDS1302 * 功能描述: */ void WriteByteDS1302(unsigned char Data) unsigned char i; ACC = Data; for(i=8; i>0; i-) T_IO = ACC0; T_CLK = 1; T_CLK = 0; ACC = ACC >> 1; /* * 函數(shù)名: ReadByteDS1302 * 功能描述: */ unsigned char ReadByteDS1302(void) unsigned char i; for(i=8; i>0; i-) ACC = ACC &

17、gt;>1; ACC7 = T_IO; T_CLK = 1; T_CLK = 0; return(ACC); /* * 函數(shù)名: WriteDS1302 * 功能描述: */ void WriteDS1302(unsigned char Addr,unsigned char Data) T_RST = 0; T_CLK = 0; T_RST = 1; WriteByteDS1302(Addr); WriteByteDS1302(Data); T_CLK = 1; T_RST = 0;/* * 函數(shù)名: ReadDS1302 * 功能描述: */ unsigned char ReadDS1

18、302(unsigned char Addr) unsigned char Data; T_RST = 0; T_CLK = 0; T_RST = 1; WriteByteDS1302(Addr); Data = ReadByteDS1302(); T_CLK = 1; T_RST = 0; return(Data);/* * 函數(shù)名: Set * 功能描述:設(shè)置 * */ void Set(unsigned char sel,unsigned char selby) unsigned char address,item; unsigned char max,min; if(sel=0) ad

19、dress=0x80; max=59;min=0; /秒 if(sel=1) address=0x82; max=59;min=0; /分鐘 if(sel=2) address=0x84; max=23;min=0; /小時 if(month=2)if(flag=1)if(sel=3) address=0x86; max=28;min=1; elseif(sel=3) address=0x86; max=27;min=1;else if(month=1|month=3|month=5|month=7|month=8|month=10|month=12) if(sel=3) address=0x

20、86; max=31;min=1;if(month=4|month=6|month=9|month=11) if(sel=3) address=0x86; max=30;min=1;if(sel=4) address=0x88; max=12;min=1; /月 if(sel=5) address=0x8a; max=7; min=1; /星期 if(sel=6) address=0x8c; max=99;min=0; /年 if(sel=7) address=0xc0; max=59;min=0; /鬧鐘分鐘 if(sel=8) address=0xc2; max=23;min=0; /鬧鐘

21、小時 item=ReadDS1302(address+1)/16*10+ReadDS1302(address+1)%16; if (selby=0) item+; else item-; if(item>max) item=min; if(item<min) item=max; WriteDS1302(0x8e,0x00); WriteDS1302(address,item/10*16+item%10); WriteDS1302(0x90,0xa5); WriteDS1302(0x8e,0x80); /* * 函數(shù)名: SetTime * 功能描述: */ void SetTime

22、(unsigned char *pClock) unsigned char h; unsigned char Addr=0x80; WriteDS1302(0x8e,0x00); for(h=7; h>0; h-) WriteDS1302(Addr,*pClock); pClock+; Addr+=2; WriteDS1302(0x90,0xa5); WriteDS1302(0x8e,0x80); /* * 函數(shù)名: ReadTime * 功能描述: */ void ReadTime() Second = BCD2HEX(Time0=ReadDS1302(0x81); minute =

23、BCD2HEX(Time1=ReadDS1302(0x83);hour = BCD2HEX(Time2=ReadDS1302(0x85);day = BCD2HEX(Time3=ReadDS1302(0x87);month = BCD2HEX(Time4=ReadDS1302(0x89);year = BCD2HEX(Time5=ReadDS1302(0x8d); week = BCD2HEX(Time6=ReadDS1302(0x8b);alarm_ss = BCD2HEX(alarm0=ReadDS1302(0xc1);alarm_hh = BCD2HEX(alarm1=ReadDS130

24、2(0xc3); /* * 函數(shù)名: WriteTime * 功能描述: */ void WriteTime()WriteDS1302(0x8e,0x00); WriteDS1302(0x80,HEX2BCD(second);WriteDS1302(0x82,HEX2BCD(minute);WriteDS1302(0x84,HEX2BCD(hour);WriteDS1302(0x86,HEX2BCD(day);WriteDS1302(0x88,HEX2BCD(month);WriteDS1302(0x8A,HEX2BCD(week);WriteDS1302(0x8C,HEX2BCD(year)

25、;WriteDS1302(0xc0,HEX2BCD(alarm_ss);WriteDS1302(0xc2,HEX2BCD(alarm_hh); WriteDS1302(0x90,0xa5); WriteDS1302(0x8e,0x80);/* * 函數(shù)名: StopTime * 功能描述: */ void StopTime() second = BCD2HEX(Time0=ReadDS1302(0x81); WriteDS1302(0x8e,0x00); WriteDS1302(0x80,HEX2BCD(second)|0x80); WriteDS1302(0x90,0xa5); WriteD

26、S1302(0x8e,0x80);/* * 函數(shù)名: StartTime * 功能描述: */ void StartTime() WriteDS1302(0x8e,0x00); WriteDS1302(0x80,HEX2BCD(second)&0x7f); WriteDS1302(0x90,0xa5); WriteDS1302(0x8e,0x80);/溫度處理程序/*ds18b20延遲子函數(shù)(晶振12MHz )*/ void delay_18B20(unsigned int i)while(i-);/*ds18b20初始化函數(shù)*/void Init_DS18B20(void) unsi

27、gned char x=0; DQ = 1; /DQ復(fù)位 delay_18B20(16); /稍做延時 DQ = 0; /單片機將DQ拉低 delay_18B20(160); /精確延時 大于 480us DQ = 1; /拉高總線 delay_18B20(28); x=DQ; /稍做延時后 如果x=0則初始化成功 x=1則初始化失敗 delay_18B20(40);/*ds18b20讀一個字節(jié)*/ unsigned char ReadOneChar(void)uchar i=0;uchar dat = 0;for (i=8;i>0;i-) DQ = 0; / 給脈沖信號 dat>

28、>=1; DQ = 1; / 給脈沖信號 if(DQ) dat|=0x80; delay_18B20(8); return(dat);/*ds18b20寫一個字節(jié)*/ void WriteOneChar(uchar dat) unsigned char i=0; for (i=8; i>0; i-) DQ = 0; DQ = dat&0x01; delay_18B20(10); DQ = 1; dat>>=1; /*讀取ds18b20當(dāng)前溫度*函數(shù)名:ReadTemperature(void)*功能描述:讀溫度值(低位放tempL;高位放tempH;)*/ vo

29、id ReadTemp(void) Init_DS18B20(); /初始化 WriteOneChar(0xcc); /跳過讀序列號的操作 WriteOneChar(0x44); /啟動溫度轉(zhuǎn)換 delay_18B20(200); /轉(zhuǎn)換需要一點時間,延時 Init_DS18B20(); /初始化 WriteOneChar(0xcc); /跳過讀序列號的操作 WriteOneChar(0xbe); /讀溫度寄存器(頭兩個值分別為溫度的低位和高位) tempL=ReadOneChar(); /讀出溫度的低位LSB tempH=ReadOneChar(); /讀出溫度的高位MSB if(tempH

30、>0x7f) /最高位為1時溫度是負 tempL=tempL+1; /補碼轉(zhuǎn)換,取反加一 tempH=tempH; fg=0; /讀取溫度為負時fg=0 else fg=1;sdata = tempL/16+tempH*16; /整數(shù)部分xiaoshu1 = (tempL&0x0f)*10/16; /小數(shù)第一位xiaoshu2 = (tempL&0x0f)*100/16;/小數(shù)第二位xiaoshu=xiaoshu1*10+xiaoshu2; /小數(shù)兩位/溫度處理程序結(jié)束/* * 函數(shù)名: DisPlay * 功能描述: */ void DisPlay() unsigned

31、 char i,j; for(i=0;i<7;i+) P2=0xFF; for(j=0;j<4;j+) OutData(unsigned char *)&Disbuftempi)3-j); R_CLK=1;R_CLK=0;P2=CSRowi; BEEP=1; Delay(250); P2=0xff;/* * 函數(shù)名: SetDis * 功能描述:設(shè)置顯示內(nèi)容菜單 */ void SetDis() if(distime=1)/時分顯示,秒針閃動 if(hour/10)=0) Dis0=14;else Dis0=hour/10; Dis1=hour%10; Dis3=minut

32、e/10; Dis4=minute%10; if(second%10)%2) Dis2=14; else Dis2=10; else if(disdate=1)/月、日顯示 Dis0=month/10; Dis1=month%10; Dis3=day/10; Dis4=day%10; Dis2=20; else if(disyear=1)/年顯示 Dis0=2; Dis1=0; Dis2=year/10; Dis3=year%10; Dis4=17; else if(distweek=1)/星期顯示 Dis0=18; Dis1=19; Dis2=14; Dis3=14; Dis4=week%1

33、0; else if(diswendu=1)/顯示溫度 if(fg=0) Dis0=20;elseDis0=sdata/10; Dis1=sdata%10; Dis2=21; Dis3=xiaoshu1; Dis4=22; else if(settime=1)/設(shè)定時間顯示、秒不閃動 if(hour/10)=0) Dis0=14;else Dis0=hour/10; Dis1=hour%10; Dis3=minute/10; Dis4=minute%10; Dis2=10; else if(setalarm=1)/設(shè)定鬧鐘時分 if(alarm_hh/10)=0) Dis0=14;else D

34、is0=alarm_hh/10; Dis1=alarm_hh%10; Dis3=alarm_ss/10; Dis4=alarm_ss%10; Dis2=10; else if(setdate=1)/月、日顯示 Dis0=month/10; Dis1=month%10; Dis3=day/10; Dis4=day%10; Dis2=20; else if(setyear=1)/年顯示 Dis0=2; Dis1=0; Dis2=year/10; Dis3=year%10; Dis4=17; else if(setweek=1)/星期顯示 Dis0=18; Dis1=19; Dis2=14; Dis3=14; Dis4=week%10; /* * 函數(shù)名: DisProcess * 功能描述:裝載顯示數(shù)據(jù) */ void DisProcess() unsigned char i,j; for(i=0;i<5;i+) for(j=0;j<7;j+) DisTempij=fontDisij; for(i=0;i<7;i+) Disbuf0=DisTemp4i; Disbuf1=DisTemp3i; Disbuf2=DisTemp2i; Disbuf3=DisTemp1i; Disbuf4=DisTemp0i; Disbu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論