多功能时钟程序.pdf
《多功能时钟程序.pdf》由会员分享,可在线阅读,更多相关《多功能时钟程序.pdf(35页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、多功能时钟程序:#include#include#define SoundSpace 3/4 unsigned char sec,min,hour,hour1,day,month,year,cen,week,shishi,fenfen;/秒,分,小时,公历日期,月份,年份,世纪,星期unsigned char LunarMonth,LunarDay,LunarYear;/阴历日期,月份,年份bit c_moon;/大小月标志位bit cenbit=0;/世纪标志,为1,则表示 20 世纪,为 0,则表示 21 世纪bit w,liu,xiao,wei;/调时状态标志位unsigned char
2、 next,s2num,bp,ha;/*定义 LCD12864 的数据线和相关函数*/sbit LCD_RS=P10;/模式位,低电平输入指令,高电平输入数据sbit LCD_RW=P11;/读写位,低电平读,高电平写sbit LCD_E=P12;/LCD12864 使能位,低电平无效,高电平使能sbit PSB=P21;#define Busy 0 x80#define LCD_Data P0/LCD12864 的 8 位数据总线,单片机的P0 端口void WriteDataLCD(unsigned char WDLCD);/给 LCD12864 写数据void WriteCommandL
3、CD(unsigned char WCLCD);/给 LCD12864 写指令void LCDInit(void);/LCD12864 初始化void LCDClear(void);/LCD12864 清屏void CheckBusy(void);/忙检测void LCDSendWord(unsigned char*p);/向 LCD 发送一个字符串void LCDTestWord(bit i,unsigned char word);void DisplaySec(void);/在 LCD 上显示秒钟void DisplayMin(void);/在 LCD 上显示分钟void DisplayH
4、our(void);/在 LCD 上显示小时void DisplayDay(void);/在 LCD 上显示日期void DisplayYear(void);/在 LCD 上显示年份void DisplayMonth(void);/在 LCD 上显示月份void DisplayWeek(void);/在 LCD 上显示星期void Holidays(void);/在 LCD 上显示节日/*定义时间芯片DS1302 的数据线及相关函数*/sbit DS1302_CLK=P22;/DS1302 的时钟信号线sbit DS1302_IO=P23;/DS1302 的数据端口线sbit DS1302_R
5、ST=P24;/DS1302 的片选信号线void WriteDs1302byte(unsigned char temp);/给 DS1302 写一个字节void WriteDs1302(unsigned char address,unsigned char dat);/给 DS1302 写入时间,先确定地址,再确定要写入的数据unsigned char ReadDs1302(unsigned char address);/读取 DS1302 的数据void InitDS1302();/*定义温度传感器DS18B20 的数据线和相关函数*/sbit DS18B20=P25;/DS18B20 的
6、数据线int temp;void DS18B20Init(void);/DS18B20 初始化函数int GetTemp(void);void TempWriteByte(unsigned char dat);unsigned char TempRead(void);bit TempReadBit(void);void delayb(unsigned int count);void TempChange(void);void Conversion(bit cen_m,unsigned char year,unsigned char month,unsigned char day);bit Ge
7、tMoonDay(unsigned char month_p,unsigned int TableAddr);void DisplayShengXiao(void);void DelayMs(unsigned int a);void Delay(unsigned char num);/*定义开关按键,及蜂鸣器的数据线*/sbit SetKey=P32;/按键功能:设置sbit SureKey=P35;/按键功能:确认sbit PlusKey=P36;/按键功能:加sbit ReduceKey=P37;/按键功能:减sbit qiehuan=P30;/1224 sbit naozhong=P31
8、;/naozhong void Key(void);code unsigned char tablemin=0 x00,0 x01,0 x02,0 x03,0 x04,0 x05,0 x06,0 x07,0 x08,0 x09,0 x10,0 x11,0 x12,0 x13,0 x14,0 x15,0 x16,0 x17,0 x18,0 x19,0 x20,0 x21,0 x22,0 x23,0 x24,0 x25,0 x26,0 x27,0 x28,0 x29,0 x30,0 x31,0 x32,0 x33,0 x34,0 x35,0 x36,0 x37,0 x38,0 x39,0 x40,
9、0 x41,0 x42,0 x43,0 x44,0 x45,0 x46,0 x47,0 x48,0 x49,0 x50,0 x51,0 x52,0 x53,0 x54,0 x55,0 x56,0 x57,0 x58,0 x59;#define Fosc 12000000/定义晶振频率12000000HZ#define jiepai 3/4/定义普通音符演奏的长度分率,/每 4 分音符间隔sbit Speaker=P33;/定义输出管脚unsigned int code FreTab12=262,277,294,311,330,349,369,392,415,440,466,494;/C 调歌曲
10、 12 个半音的频率unsigned char code PositTab7=0,2,4,5,7,9,11;/17在频率表中的位置unsigned char code LengthTab7=1,2,4,8,16,32,64;unsigned char SoundTempTH0,SoundTempTL0;/音符定时器初值暂存unsigned char SoundTempTH1,SoundTempTL1;/音长定时器初值暂存void SpeakerDiDi(void);void SpeakerDiDi(void)unsigned char i;for(i=0;i220;i+)文档编码:CC8I7J
11、2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3
12、HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10
13、N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q
14、4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K
15、4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S
16、5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:
17、CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5 Speaker=0;DelayMs(10);Speaker=1;DelayMs(10);void InitialSound(void)Speaker=1;SoundTempTH1=(655
18、35-(1/1200)*Fosc)/256;/计算 TL1 应装入的初值(10ms 的初装值)SoundTempTL1=(65535-(1/1200)*Fosc)%256;/计算 TH1 应装入的初值TH1=SoundTempTH1;/装入初值TL1=SoundTempTL1;TMOD|=0 x11;/定时器 1、2 都工作在定时器模式,工作方式1 ET0=1;/定时器 0 开中断ET1=0;/定时器 1 关中断TR0=0;/不启动定时器TR1=0;/不启动定时器EA=1;/开启 CPU 中断 void Speakertimer(void)interrupt 1/音符发生中断 Speaker=
19、!Speaker;/取反TH0=SoundTempTH0;/定时器 0 重新装初值TL0=SoundTempTL0;void PlayMusic(unsigned char*SoundName,unsigned char diaohao,unsigned shengjiang,unsigned int Speed)/SoundName 为演奏歌曲歌名diaohao 是指乐曲升多少个半音演奏/shengjiang 1:降八度,2:不升不降,3:升八度;Speed歌曲演奏速度 unsigned int NewFreTab12;/新的频率表unsigned char i,j;unsigned int
20、 Point,yinfuchang,yipai,LDiv1,LDiv2,sifenyifu,CurrentFre,TempCounter,SoundLength;/Point 指针索引值LDiv 音符演奏的长度(多少个 10ms)yipai 1 分音符的长度(几个 10ms)即一个节拍/sifenyifu 4分 音 符 的 长 度CurrentFre 查 出 对 应 音 符 的 频 率SoundLength 歌曲长度TempCounter 计算计数器初值文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q
21、4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K
22、4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S
23、5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:
24、CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J
25、2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3 HR4R10N10H2Q4 ZT8K4Y9Z2S5文档编码:CC8I7J2D3B3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 多功能 时钟 程序
限制150内