湖南大学基于ADUC848单片机多功能定时装置(电子时钟)设计.doc

上传人:wux****ua 文档编号:9436138 上传时间:2020-04-05 格式:DOC 页数:40 大小:485.50KB
返回 下载 相关 举报
湖南大学基于ADUC848单片机多功能定时装置(电子时钟)设计.doc_第1页
第1页 / 共40页
湖南大学基于ADUC848单片机多功能定时装置(电子时钟)设计.doc_第2页
第2页 / 共40页
湖南大学基于ADUC848单片机多功能定时装置(电子时钟)设计.doc_第3页
第3页 / 共40页
点击查看更多>>
资源描述
湖南大学电气与信息工程学院本科生课程设计 题目: 电子时钟 课程:单片机课程设计 专业:电子信息工程 班级: 学号: 姓名: 指导老师: 设计时间: 第一章 绪论1.1 课程设计目的学习单片机原理,并设计电子时钟。1.2 课程任务设计的电子时钟具有以下功能:(1) 、选择LCD显示,可显示年、月、日、时、分、秒。(2) 、会使用实时钟芯片DS1307。(3) 、选择蜂鸣器电路,实现闹钟设置和报警功能。(4) 、选择按键功能,设计实现时钟校正功能。(5) 、上电或RESET后能自动显示当前时间(时:分:秒)。1.3 课程设计要求(1)、画出硬件原理图。(2)、采用单片机C语言或汇编语言进行编程。(3)、完成硬件与软件调试综合调试,实现预定功能,并写出 课程设计报告。1.4 课程设计意义通过自己动手设计制作单片及组成的器件,深入了解了单片机的实际应用,能更深地理解课堂上所学的内容,使得单调的理论知识与实际联系起来,帮助我们更好的理解。第2章 设计原理及总体方案选择2.1 基本功能简述电子时钟,通过DS1307芯片提供实时时钟,并通过LCD12864显示。DS1307是低功耗、两线制串行读写接口、日历和时钟数据按BCD码存取得时钟/日历芯片。它提供秒、分、小时、星期、日期、月和年等时钟日历数据。除此之外,还具有跑表和闹钟的功能。跑表是通过中断实现,闹钟由蜂鸣器实现并以歌曲为闹铃实现。本电子时钟是由ADUC848芯片、时钟与复位电路、选择按键输入电路、音频发生器、音频放大器和扬声器、LCD显示模块和DS1307芯片这七部分组成。图2.1 电子时钟设计框图 2.2 乐理基础与发声原理简述 在音乐中使用的各个固定频率的音叫音级。常用符号C、D、E、F、G、A、B、c、d、e、a1、b1、c2、d2表示,它们对应于钢琴上的白键。两音之间音高的距离叫音程。在上述音级中,E与F、B与C之间音高的距离仅为其它相邻音级之间距离的一半,称它们之间的音程为半音音程,而称其它相邻各音之间的距离为全音音程。在这些全音音程之间又加入新的半音音级,用符号C、D、F、G、A、c、d、f、表示,对应于钢琴上的黑键。音持续时间的长短即时值,一般用拍数表示。休止符表示暂停发音。表2.1 各音符及对应频率音符低DO低#DO低RE低#RE低MI低EA简谱码DO_LDO#_LRE_LRE#_LMI_LFA_L频率262HZ277HZ294HZ311HZ330HZ349HZ音符低#FA低SO低#SO低LA低#LA低SI简谱码FA#_LSO_LSO#_LLA_LLA#_LSI_L频率370HZ393HZ415HZ440HZ466HZ494HZ音符中DO中#DO中RE中#RE中MI中EA简谱码DODO#RERE#MIFA频率523HZ554HZ587HZ622HZ659HZ698HZ音符中#FA中SO中#SO中LA中#LA中SI简谱码FA#SOSO#LALA#SI频率740HZ785HZ831HZ880HZ932HZ988HZ音符高DO高#DO高RE高#RE高MI高EA简谱码DO_HDO#_HRE_HRE#_HMI_HFA_H频率1047HZ1109HZ1174HZ1245HZ1318HZ1397HZ音符高#FA高SO高#SO高LA高#LA高SI简谱码FA#_HSO_HSO#_HLA_HLA#_HSI_H频率1480HZ1568HZ1661HZ1760HZ1865HZ1976HZ 每个音符分为简谱码和节拍码。简谱码为D0-L到SI-H。 在此设计程序中,包括了两个数据表,它们分别存放了已经计算好的、各种音符频率所对应的、半周期的定时时间初始值的高八位和低八位。有了这些数据,单片机就可以演奏从低音、中音、高音,三个八度的音符。在播放乐曲时,单片机根据音符的不同数值,从表中找到定时时间初始值,送入定时器即可控制音调。此外乐曲的数据也要写个数据表,在此设计程序中名为:code unsigned char Data_Sheet,表中每三个数字代表一个音符,它们分别为: 第一个数字是音符的数值1234567之一,代表Do、Re、Mi.; 第二个数字是012之一,代表低音、中音、高音; 第三个数字是时间长度,此实验程序以半拍为单位。 乐曲数据表的结尾处为三个0,在程序中作为结束标志。流程图为:闹钟主程序流程图中断1中断子程序流程图:2.3 LCD原理简述 1、SMG12864D3 液晶显示模块的接口信号说明: 编号 符号 引脚说明 编号 符号 引脚说明 1 CS2 片选IC2信号 11 DB2 Data I/O 2 CS1 片选IC1信号 12 DB3 Data I/O 3 VSS 电源地 13 DB4 Data I/O 4 VDD 电源正极(+5V) 14 DB5 Data I/O 5 V0 LCD偏压输入 15 DB6 Data I/O 6 RS 数据/命令选择端(H/L) 16 DB7 Data I/O 7 RW 读写控制信号(H/L) 17 /RESET 复位端 8 E 使能信号 18 VEE 负压输出 9 DB0 Data I/O 19 BLA 背光源正极 10 DB1 Data I/O 20 BLK 背光源负极 2、控制器接口说明(KS108B 及兼容芯片) 1) 基本操作时序: 1.1 读状态:输入:RS=L,R/W=H,CS1或CS2=H,E=H 输出:D0D7=状态字 1.2 写指令:输入:RS=L,R/W=L,D0D7=指令码,CS1或 CS2=H,E=高脉冲 输出:无 1.3 读数据:输入:RS=H,R/W=H,CS1或CS2=H,E=H 输出:D0D7=数据 1.4 写数据:输入:RS=H,R/W=L,D0D7=数据,CS1或 CS2=H,E=高脉冲 输出:无 2) 状态字说明 STA7 STA6 STA5 STA4 STA3 STA2 STA1 STA0 D7 D6 D5 D4 D3 D2 D1 D0 STA0-4 未用 STA5 液晶显示状态 1: 关闭 0: 显示 STA6 未用 STA7 读写操作使能 1: 禁止 0: 允许 注:对控制器每次进行读写操作之前,都必须进行读写检测,确保STA7为0。 3) RAM地址映射图 LCD 显示屏由两片控制器控制,每个内部带有8X64位(512 字节)的 RAM 缓冲区,对应关系如图所示: 4) 指令说明 4.1 初始化设置 4.1.1 显示开/关设置 指令码 功能 3EH 关显示 3FH 开显示 4.1.2 显示初始行设置 指令码 功能 0C0H 设置显示初始行 4.2 数据控制 控制器内部设有一个数据地址页指针和一个数据地址列指针,用户可通过它们来访问内部的全部512字节RAM。 4.2.1 数据指针设置 指令码 功能 0B8H+页码(07) 设置数据地址页指针 40H+列码(063) 设置数据地址列指针 5 初始化过程 写指令0C0H: 设置显示初始行。 写指令3FH:开显示。在编写软件代码之前必须要先掌握汉字取模的方法。有很多取模软件能将文字转成字模数据。取模常用的基本概念:1、横向取模和纵向取模与该单片机开发板配套的LCD12864D3内置KS0108B 接口型液晶显示控制器,它的每字节点阵排列方式是纵向排列的,用取模软件取模时采用纵向取模方式;还有的液晶每字节点阵排列方式是横向排列的,用取模软件取模时采用横向取模方式。不同液晶的取模方向可参考相应液晶的使用手册。本程序采用纵向取模。2、字节正序和字节倒序通常一个字节的数据按二进制排列的话都是最左边为高位A7,最右边为低位A0,这就是正序;若LCD的点阵与一个字节数据的排列顺序相反,左边最左边显示的是A0,右边显示A7,这就是倒序。竖向排列也一样,通常数据是上面为高位A7,下面为低位A0,是正序。如果LCD模块的点阵排列正好反了,就是竖向倒序。KS0108控制器的LCD竖向倒序排列图如下图所示。 程序流程图如图所示。 第三章 音乐播放器硬件电路的设计和调试3.1 复位与下载模块 由电容,电位器,按键组成复位电路部分,该电路接于单片机的RESET端可以通过按键达到手动复位的效果。复位时PSEN拉低进入下载或调试模式。 图 3.1 复位电路图 图 3.2 下载电路图 3.2 按键选择模块使用接线帽把J12的1,2端口连接,形成矩阵按键。图 3.3 按键电路图3.3 蜂鸣器发生模块本设计中采用无源电磁式蜂鸣器,蜂鸣器由PWM1(P2.6)控制。PWM1为片内PWM模块的输出。 图 3.4 音频发生与放大电路3.4 LCD显示模块关键网络名和引脚名解释: (1)DISCTRL04:显示控制信号。(2)D0D7、DB0DB7:数据总线。(3)E:LCD使能信号。(4)RS:数据、指令选择信号。(5)RW:读、写选择信号。其工作过程是通过芯片处理使用者通过按键发来的信息,显示歌曲名称,歌词随歌曲播放自动对应播放。 图 3.5LCD显示信号连接图3.5 IIC总线(RTC时钟)AduC848片内有I2C模块,并有独立的引脚SCLOCK和SDATA。板上的RTC时钟芯片DS1307和EEPROM芯片AT24C08均使用了I2C总线。板上设置了I2C接口,方便MCU与板外的I2C设备进行通信。对SCLOCK和SDATA设置了测试点。第4章 软件编程设计与综合测试4.1 程序流程图1. 中断0子程序流程图2. 主程序流程图4.2 程序清单4.2.1 12864子程序头文件/12864子程序头文件/头文件名:LCD12864.H#ifndef _LCD12864_H_#define _LCD12864_H_#define Display_Off 0x3e /显示关指令#define Display_On 0x3f /显示开指令#define Start_Line 0xc0 /初始行指令#define X_Page_Addr 0xb8 /定位到第0页指针指令#define Y_Col_Addr 0x40 /定位到第0列指针指令/屏幕选择#define LCD_sel_left CS1 = 1; CS2 = 0;#define LCD_sel_right CS1 = 0; CS2 = 1;#define LCD_sel_all CS1 = 1; CS2 = 1;#define LCD_sel_no CS1 = 0; CS2 = 0;/液晶开关#define LCD_show_on Write_cmd(Display_On);#define LCD_show_off Write_cmd(Display_Off);void LCD_init(); /液晶初始化void LCD_Write_Sentence(unsigned char Hang,unsigned char Lie,unsigned char *wordp); /向液晶写句子void LCD_write_shuzi(unsigned char Hang,unsigned char Lie,unsigned char p);void LCD_write_fuhao(unsigned char Hang,unsigned char Lie,unsigned char p);void Write_dat(unsigned char dat);#endif4.2.2 字模头文件/字模头文件/头文件名:BLESS.H#ifndef _BLESS_H_#define _BLESS_H_unsigned char code WordTable32=0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,/*年*/0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,/*月*/0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,/*日*/0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00,/*星*/0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00,/*期*/0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*一*/0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,/*二*/0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,/*三*/0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,/*四*/0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00,/*五*/0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00,/*六*/0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x00,0x40,0x42,0x44,0x58,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x50,0x48,0x46,0x40,0x00,/*显*/0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,0x20,0x10,0x08,0x06,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x02,0x04,0x08,0x30,0x00,/*示*/0x40,0x42,0xCC,0x00,0x00,0xFE,0x82,0x92,0x92,0xFE,0x92,0x92,0x82,0xFE,0x00,0x00,0x00,0x00,0x3F,0x10,0x88,0x7F,0x00,0x1E,0x12,0x12,0x12,0x5E,0x80,0x7F,0x00,0x00,/*调*/0x04,0x74,0xD4,0x54,0xFF,0x54,0xD4,0x74,0x14,0x08,0x77,0x84,0x44,0x3C,0x04,0x00,0x82,0x89,0x88,0xE8,0x8B,0x88,0x88,0xF9,0xA8,0xAA,0xA9,0xA8,0xA9,0x8A,0x82,0x00,/*整*/0x00,0x3E,0x22,0xE2,0x22,0x3E,0x10,0xEC,0x27,0x24,0x24,0xE4,0x04,0xFC,0x00,0x00,0x20,0x3F,0x20,0x1F,0x11,0x11,0x00,0x3F,0x42,0x42,0x4A,0x53,0x48,0x47,0x70,0x00,/*跑*/0x00,0x04,0x24,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x24,0x04,0x00,0x00,0x21,0x21,0x11,0x09,0xFD,0x83,0x41,0x23,0x05,0x09,0x11,0x29,0x25,0x41,0x41,0x00,/*表*/0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,0x10,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*功*/0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00,0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,/*能*/0x00,0xF8,0x01,0x22,0x20,0x22,0x2A,0xF2,0x22,0x22,0x22,0x22,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x1F,0x01,0x01,0x7F,0x09,0x11,0x0F,0x40,0x80,0x7F,0x00,0x00,/*闹*/0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xF0,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0x01,0x01,0x01,0x7F,0x21,0x11,0x00,0x07,0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00,/*钟*/0x40,0x40,0x42,0xCC,0x00,0x40,0xA0,0x9E,0x82,0x82,0x82,0x9E,0xA0,0x20,0x20,0x00,0x00,0x00,0x00,0x3F,0x90,0x88,0x40,0x43,0x2C,0x10,0x28,0x46,0x41,0x80,0x80,0x00,/*设*/0x00,0x17,0x15,0xD5,0x55,0x57,0x55,0x7D,0x55,0x57,0x55,0xD5,0x15,0x17,0x00,0x00,0x40,0x40,0x40,0x7F,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x7F,0x40,0x40,0x40,0x00,/*置*/0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*开*/0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00,/*关*/0x04,0x04,0x44,0xC4,0x4F,0x44,0x44,0xC4,0x24,0x24,0x2F,0xB4,0x24,0x04,0x04,0x00,0x40,0x44,0x24,0x24,0x15,0x0C,0x04,0xFE,0x04,0x0C,0x15,0x24,0x24,0x44,0x40,0x00,/*菜*/0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00,0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00,/*单*/0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00/*时*/;unsigned char code ShuTable16=0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*0*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*4*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*5*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*6*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*7*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*8*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,/*9*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00/*空白*/;unsigned char code FuhaoTable16=0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00, /*:*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00/*空白*/;#endif4.2.3 LCD12864主程序文件/LCD12864主程序文件#include #include #includesbit RS = P36;sbit RW = P35;sbit E = P33;sbit CS1 = P37;sbit CS2 = P24;void LCD_delay()unsigned char i;for(i = 0;i 50;i+);/*检测忙函数*/void Check_busy()P0 = 0xff; /P0口作为输入时应往相应引脚写1RS = 0; RW = 1;E = 1;LCD_delay();while(P0&0x80); /判断最高位是否为1,若为1则等待E = 0;RW = 0;P0 = 0x00;/*写指令函数*/void Write_cmd(unsigned char cmd)Check_busy();RS = 0;RW = 0;P0 = cmd;LCD_delay();E = 1;LCD_delay();E = 0;/*写数据函数*/void Write_dat(unsigned char dat)Check_busy();RS = 1;RW = 0;P0 = dat;LCD_delay();E = 1;LCD_delay();E = 0;/*液晶写数字*/*液晶初始化函数*/void LCD_init()unsigned char i,j;E = 0;RS = 0;RW = 0;LCD_sel_all /选择全屏Write_cmd(Start_Line); /设置显示初始行(0xc0)LCD_show_on /开显示 (0x3f)for(i=0;i8;i+)Write_cmd(X_Page_Addr + i); /第0页(0xb8)+iWrite_cmd(Y_Col_Addr); /第0列(0x40),写完一列后列指针自动加1for(j=0;j64;j+) Write_dat(0x00); /清第i页 LCD_sel_no /关全屏/*获取字的地址函数*/unsigned char GetWordAddress(unsigned int WordCode) switch(WordCode) case 0xc4ea:return /*年0*/0; case 0xd4c2:return /*月1*/1; case 0xc8d5:return /*日2*/2; case 0xd0c7:return /*星3*/3; case 0xc6da:return /*期4*/4; case 0xd2bb:return /*一5*/5; case 0xb6fe:return /*二6*/6; case 0xc8fd:return /*三7*/7; case 0xcbc4:return /*四8*/8; case 0xcee5:return /*五9*/9;case 0xc1f9:return /*六10*/10;case 0xcfd4:return /*显11*/11; case 0xcabe:return /*示12*/12; case 0xb5f7:return /*调13*/13; case 0xd5fb:return /*整14*/14; case 0xc5dc:return /*跑15*/15;case 0xb1ed:return /*表16*/16;case 0xb9a6:return /*功17*/17; case 0xc4dc:return /*能18*/18; case 0xc4d6:return /*闹19*/19; case 0xd6d3:return /*钟20*/20; case 0xc9e8:return /*设21*/21;case 0xd6c3:return /*置22*/22;case 0xbfaa:return /*开23*/23;case 0xb9d8:return /*关24*/24;case 0xb2cb:return /*菜25*/25;case 0xb5a5:return /*单26*/26;case 0xcab1:return /*时27*/27; default:break; /*向液晶写8*8阵列*/void LCD_write_byte(unsigned char Hang,unsigned char Lie,unsigned char Byte)unsigned char i;if(Lie 8) /左半屏LCD_sel_leftelseLCD_sel_rightLie = Lie - 8;Write_cmd(X_Page_Addr + Hang);Write_cmd(Y_Col_Addr + Lie*8);for(i = 0;i 8;i +)Write_dat(Bytei);LCD_sel_no/*向液晶写数字*/void LCD_write_shuzi(unsigned char Hang,unsigned char Lie,unsigned char p)unsigned char *Two_byte; if(p=0) Two_byte=ShuTable0;else if(p=1) Two_byte=ShuTable1;else if(p=2) Two_byte=ShuTable2;else if(p=3) Two_byte=ShuTable3;else if(p=4) Two_byte=ShuTable4;else if(p=5) Two_byte=ShuTable5;else if(p=6) Two_byte=ShuTable6;else if(p=7) Two_byte=ShuTable7;else if(p=8) Two_byte=ShuTable8;else if(p=9) Two_byte=ShuTable9;else if(p=10) Two_byte=ShuTable10;LCD_write_byte(Hang,Lie,Two_byte);LCD_write_byte(Hang + 1,Lie,Two_byte + 8);/*向液晶写符号*/void LCD_write_fuhao(unsigned char Hang,unsigned char Lie,unsigned char p)unsigned char *Two_byte; if(p=0) Two_byte=FuhaoTable0;else if(p=1) Two_byte=FuhaoTable1;LCD_write_byte(Hang,Lie,Two_byte);LCD_write_byte(Hang + 1,Lie,Two_byte + 8);/*向液晶写汉字*/void LCD_write_hanzi(unsigned char Hang,unsigned char Lie,unsigned char Four_byte)LCD_write_byte(Hang,Lie,Four_byte);LCD_write_byte(Hang,Lie + 1,Four_byte + 8);LCD_write_byte(Hang + 1,Lie,Four_byte + 16);LCD_write_byte(Hang + 1,Lie + 1,Four_byte + 24);/*向液晶写句子*/void LCD_Write_Sentence(unsigned char Hang,unsigned char Lie,unsigned char *wordp) unsigned int *word; word=(unsigned int *)wordp; while(*word)&0xff00)!=0x0000) LCD_write_hanzi(Hang,Lie,WordTableGetWordAddress(*word); word+;Lie+=2; 4.2.4 I2C操作程序/I2C操作SLADDWR EQU 0D0H /器件地址SLADDRD EQU 0D1HMDO EQU 0EFHMDE EQU 0EEHMCO EQU 0EDHMDI EQU 0ECH?PR?DELAY?TEST SEGMENT CODE PUBLIC DELAYRSEG ?PR?DELAY?TESTDELAY:/NOP/MOV R2,#30/DJNZ R2,$RET?PR?IICLK?TEST SEGMENT CODE/给I2C一个脉冲,结束时MCO为0 PUBLIC IICLKRSEG ?PR?IICLK?TESTIICLK:SETB MCOCALL DELAYCLR MCOCALL DELAYRET?PR?IICWRBYTE?TEST SEGMENT CODE/将A中数据写入I2C,包括ACK, PUBLIC IICWRBYTERSEG ?PR?IICWRBYTE?TESTIICWRBYTE:MOV R3,#08I2CWRBYTE_LP2:RLC AMOV MDO,CCALL DELAYCALL IICLKDJNZ R3,I2CWRBYTE_LP2CLR MDECALL IICLK /ACKSETB MDERET?PR?IICSTART?TEST SEGMENT CODE/i2cstart PUBLIC IICSTARTRSEG ?PR?IICSTART?TESTIICSTART:SETB MDESETB MDOCALL DELAYSETB MCO CALL DELAYCLR MDOCALL DELAYCLR MCO CALL DELAY/SRET?PR?IICSTOP?TEST SEGMENT CODE/I2Cstop PUBLIC IICSTOPRSEG ?PR?IICSTOP?TESTIICSTOP:CLR MDOCALL DELAYSETB MCOCALL DELAYSETB MDOCALL DELAYRET/*?PR?_I2CWR?TEST SEGMENT CODE /I2CWR(A,B)将数据A写入1307地址 B PUBLIC _I2CWR RSEG ?PR?_I2CWR?TEST_I2CWR:CALL IICSTARTMOV A,#SLADDWRCALL IICWRBYTEMOV A,R5 /REG ADDRESSCALL IICWRBYTEMOV A,R7 /DATACALL IICWRBYTECALL IICSTOPRETIICRDBYTE: /IIC读取1字节,结果在AMOV R3,#8IICRDBYTE_LP1:SETB MCOCALL DELAYMOV C,MDICLR MCOCALL DELAYRLC ADJNZ R3,IICRDBYTE_LP1CALL IICLK /ACKRET/*?PR?_I2CRD?TEST SEGMENT CODE /I2CRD(A)返回1307A地址内容 PUBLIC _I2CRD RSEG ?PR?_I2CRD?TEST_I2CRD:CALL IICSTARTMOV A,#SLADDWRCALL IICWRBYTEMOV A,R7 /REG ADDRESSCALL IICWRBYTECALL IICSTOP /写入REG地址CALL IICSTARTMOV A,#SLADDRDCALL IICWRBYTECLR MDECALL IICRDBYTECALL IICSTOPMOV R7,A /准备返回值RETEND4.2.5 主程序/主程序,timemain.c#include #include #include #include #define uint unsigned int#define uchar unsigned char#define ulong unsigned longvoid init(void);/初始化void I2CWR(uchar DATA,uchar ADDR);/写IICuchar I2CRD(uchar ADDR);/读IICuchar idata DPRAM13;/显示缓冲uchar idata TM7;/TM0-6存放秒分时日月年星期uchar FUNSEL=0;/功能选择 0:功能菜单 1:日期显示 2:日期调整 3:跑表功能 4:闹钟设置uchar keyscan();/按键扫描uchar keyNO=16;/按键返回值uchar keyNO1=16;uchar key1=0;void delayms(uint n);/1ms延时void DPTM(void);/将TM中数据转移到DPRAM中void TMDP(void);/将DPRAM中数据转移到TM中uchar sel=1;/选择调整时间位uchar sell=0; /选择调整闹钟位bit FLASH=0;void TFLASH(uchar FLASH, uchar p);void tiaoshi(uchar n,uchar m); /调时void tiaoxingqi();uchar keyfan();uchar CT1FLASH1=20;/显时计数 uchar CT1FLASH2=20;/调时计数uchar CT1FLASH3=20;/闹钟计数bit A_clock=0;/闹钟标志位 0:不响 1:响bit B_clock=0;/闹钟与时钟相等为1,不等为0bit C_clock=1;/从闹钟返回时钟位bit D_clock=0;ulong coclock=0;/闹钟计时uchar idata clk4;/存闹钟时分void tiaonaoz(uchar n,uchar m);uchar selln=1;/选择调整闹钟位uchar sellm=0;void xianshi0(void);/显示菜单void xianshi1(void);/显示时间void xianshi2(void);/显示调时void xianshi3(void);/显示跑表void xianshi4(void);/显示闹钟uchar PB8;/跑表数据bit PBSTOP=0;/1:跑 0:停bit PBZT=0;/1:把PB8放入显存 0:不放入sbit Buzzer=P26;unsigned char Timer0_High,Timer0_Low,timer;
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!