×点阵数字钟及汉字显示_第1页
×点阵数字钟及汉字显示_第2页
×点阵数字钟及汉字显示_第3页
×点阵数字钟及汉字显示_第4页
×点阵数字钟及汉字显示_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

16×32点阵数字钟及汉字显示作者:HYPERLINK"http://.cn/user/HEY"HEY|扫瞄数(6070)|评论数(0)|2007-08-09一.电路原理框架设计制作作品:16×32点阵显示数字钟及汉字显示实现功能:点阵显示的实时时钟以及汉字等字符的左移显示有用特征:接受双电源供电,断电后时钟由电池供电还能连续运行,而且精确性较高实现原理:1.时钟显示是由DS1302精确的时钟芯片产生时钟信号并将其送至单片机,经过单片机处理后再输送到点阵显示模块。2。汉字显示并左移原理是先写入与本点阵驱动相应的代码进单片机,通过单片机掌握程序取表进行处理后送点阵模块显示电路主要模块及原理图:1。单片机最小系统及掌握按键电路2.DS1302与单片机接口电路DS1302除了系统上电时由系统供电外,如果主电源断电还有一电池给DS1302供电,防止断电后DS1302数据消灭.4.点阵行驱动模块电路行驱动接受74LS154(4—16线译码器)及PNP三极管,由于是16×32点阵显示功率较大故接受8550NP三极管。5.点阵列驱动电路列驱动接受74HC595移位寄存器将掌握位级连接入单片机,每个74HC595数据输入端单独接单片机。16×32点阵模块由8块小的8×8点阵模块通过级连而拼成,共16行,32列。二:主要元器件选择:单片机:AT89S51接受市场上比较常用的AT89S51三极管:点阵的行驱动电路用,这里接受PNP管,简略型号用8550点阵块:为了电路简洁,接受双色8×8点阵晶振:接受的是12MHZ的晶振电源部分:接受5V电压供电,接受的是L7805稳压芯片供电电阻:大部分是限流电阻,阻值为4.7K或10K,1K译码器:4-16线接受市场上较为常用的74LS154,用来作行驱动移位寄存器:接受74HC595移位寄存器作列驱动,驱动列端口支配及连接:P1.0-P1。2:DS1302与单片机接口P1。3-P1.4:K0,K1按键,用来调整时间,按下为0P0:P0口接点阵行驱动电路接译码器P2:P2口点阵列驱动电路接74HC595最后是做好之后的图附:点阵时间显示源程序//===================================================================================//ﻫ//*标题:16*32点阵数字钟显示程序

//*说明:时钟信号产生接受DS1302,列接受74HC595驱动(共4个),行驱动接受4-16线译码器74LS154ﻫ//*功能:通过动态扫描显示时钟,可显示时,分,秒,日期中的月和日ﻫ//*作者:HEYﻫ//*日期:2006—05-29ﻫ//*邮箱:billy3416@163.com

//*备注:此是我刚接触单片机时的一个小制作程序和电路设计上难免有不足之处请谅解ﻫ//===================================================================================//#include<reg51。h>ﻫ#include<stdlib。h>ﻫ#defineucharunsignedchar//===================================================================================//ﻫ//用到的引脚及端口定义

//===================================================================================//sbitSERIALIN_0=P2^0;//定义P2。0为列向第1个74HC595的DATA输入

sbitSERIALIN_1=P2^1;//定义P2。1为列向第2个74HC595的DATA输入ﻫsbitSERIALIN_2=P2^2;//定义P2.2为列向第2个74HC595的DATA输入

sbitSERIALIN_3=P2^3;//定义P2。3为列向第2个74HC595的DATA输入sbitCLOCK_DATA=P1^0;//定义P1.0为DS1302的DATA端口

sbitCLOCK_RST=P1^1;//定义P1。1为DS1302的复位输出端口ﻫsbitCLOCK_SCLK=P1^2;//定义P1。2为DS1302的时钟信号状态掌握sbitK0=P1^3;//K0为按键1,用来选择要调整时间的选项(时和分)ﻫsbitK1=P1^4;//K1为按键2,执行加1sbitCLOCK=P2^4;//74HC595的移位时钟掌握ﻫsbitLATCH=P2^5;//74HC595的锁存输出时钟掌握voidcontrol();//调整时间掌握函数ﻫvoidtime();ucharCLOCK_TIME[3]={0,0,0};//定义时钟时间数据存储区,分别为(时,分,秒)ﻫucharBUFFER[8]={0,0,0,0,0,0,0,0};//显示缓冲区ﻫucharYEAR[3]={0,0,0};//定义时钟年月日数据存储区ﻫuchartemp[4]={0,0,0,0};//定义74HC595的移位缓冲区ucharFLASH_STOP;//显示小时和分钟之间的两点掌握位ﻫucharsec_flash;//用单片机定时器模拟的一秒(用来掌握小时和分中之间的两点)

//===================================================================================//ﻫ//定义0—9的点阵显示代码段8*8

//===================================================================================//ucharcodebmp[10][8]={ﻫ{0xe3,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xe3},//0ﻫ{0xf7,0xc7,0xf7,0xf7,0xf7,0xf7,0xf7,0xc1},//1ﻫ{0xe3,0xdd,0xdd,0xfd,0xfb,0xf7,0xef,0xc1},//2

{0xe3,0xdd,0xfd,0xe3,0xfd,0xfd,0xdd,0xe3},//3ﻫ{0xfb,0xf3,0xeb,0xdb,0xdb,0xc1,0xfb,0xf1},//4ﻫ{0xc1,0xdf,0xdf,0xc3,0xfd,0xfd,0xdd,0xe3},//5

{0xe3,0xdd,0xdf,0xc3,0xdd,0xdd,0xdd,0xe3},//6ﻫ{0xc1,0xdd,0xfd,0xfb,0xf7,0xf7,0xf7,0xf7},//7ﻫ{0xe3,0xdd,0xdd,0xe3,0xdd,0xdd,0xdd,0xe3},//8ﻫ{0xe3,0xdd,0xdd,0xdd,0xe1,0xfd,0xdd,0xe3},//9ﻫ};//===================================================================================//ﻫ//定义0-9的点阵显示代码段8*8与上面不同的是多了小时和分钟之间的两点ﻫ//===================================================================================//ucharcodebmp_1[10][8]={ﻫ{0xe3,0xdd,0x5d,0xdd,0xdd,0x5d,0xdd,0xe3},//:0

{0xf7,0xc7,0x77,0xf7,0xf7,0x77,0xf7,0xc1},//:1ﻫ{0xe3,0xdd,0x5d,0xfd,0xfb,0x77,0xef,0xc1},//:2ﻫ{0xe3,0xdd,0x7d,0xe3,0xfd,0x7d,0xdd,0xe3},//:3ﻫ{0xfb,0xf3,0x6b,0xdb,0xdb,0x41,0xfb,0xf1},//:4

{0xc1,0xdf,0x5f,0xc3,0xfd,0x7d,0xdd,0xe3},//:4

{0xe3,0xdd,0x5f,0xc3,0xdd,0x5d,0xdd,0xe3},//:5

{0xc1,0xdd,0x7d,0xfb,0xf7,0x77,0xf7,0xf7},//:6ﻫ{0xe3,0xdd,0x5d,0xe3,0xdd,0x5d,0xdd,0xe3},//:7ﻫ{0xe3,0xdd,0x5d,0xdd,0xe1,0x7d,0xdd,0xe3},//:8ﻫ};//===================================================================================//ﻫ//定义0—9的点阵显示代码段数码似的字模8*8显示数据前有一横杠将月和日格开

//===================================================================================//ucharcodebmp_2[10][8]={

{0xff,0xff,0xf8,0xfa,0x8a,0xfa,0xf8,0xff},//-0ﻫ{0xff,0xff,0xfe,0xfe,0x8e,0xfe,0xfe,0xff},//-1ﻫ{0xff,0xff,0xf8,0xfe,0x88,0xfb,0xf8,0xff},//-2ﻫ{0xff,0xff,0xf8,0xfe,0x88,0xfe,0xf8,0xff},//-3ﻫ{0xff,0xff,0xfa,0xfa,0x88,0xfe,0xfe,0xff},//-4

{0xff,0xff,0xf8,0xfb,0x88,0xfe,0xf8,0xff},//-5ﻫ{0xff,0xff,0xf8,0xfb,0x88,0xfa,0xf8,0xff},//-6ﻫ{0xff,0xff,0xf8,0xfe,0x8e,0xfe,0xfe,0xff},//-7ﻫ{0xff,0xff,0xf8,0xfa,0x88,0xfa,0xf8,0xff},//-8ﻫ{0xff,0xff,0xf8,0xfa,0x88,0xfe,0xf8,0xff},//-9ﻫ};//===================================================================================//

//定义0-9的点阵显示代码段模拟数码似的字模8*8ﻫ//===================================================================================//ucharcodebmp_3[10][8]={ﻫ{0xff,0xff,0x8f,0xaf,0xaf,0xaf,0x8f,0xff},//0ﻫ{0xff,0xff,0xef,0xef,0xef,0xef,0xef,0xff},//1ﻫ{0xff,0xff,0x8f,0xef,0x8f,0xbf,0x8f,0xff},//2

{0xff,0xff,0x8f,0xef,0x8f,0xef,0x8f,0xff},//3ﻫ{0xff,0xff,0xaf,0xaf,0x8f,0xef,0xef,0xff},//4ﻫ{0xff,0xff,0x8f,0xbf,0x8f,0xef,0x8f,0xff},//5

{0xff,0xff,0x8f,0xbf,0x8f,0xaf,0x8f,0xff},//6

{0xff,0xff,0x8f,0xef,0xef,0xef,0xef,0xff},//7ﻫ{0xff,0xff,0x8f,0xaf,0x8f,0xaf,0x8f,0xff},//8ﻫ{0xff,0xff,0x8f,0xaf,0x8f,0xef,0x8f,0xff},//9ﻫ};//===================================================================================//

//定义0-59模拟七段数码管显示8*8ﻫ//===================================================================================//ucharcodebmp_4[60][8]={ﻫ{0xff,0xff,0x88,0xaa,0xaa,0xaa,0x88,0xff},//00ﻫ{0xff,0xff,0x8e,0xae,0xae,0xae,0x8e,0xff},//01ﻫ{0xff,0xff,0x88,0xae,0xa8,0xab,0x88,0xff},//02

{0xff,0xff,0x88,0xae,0xa8,0xae,0x88,0xff},//03ﻫ{0xff,0xff,0x8a,0xaa,0xa8,0xae,0x8e,0xff},//04ﻫ{0xff,0xff,0x88,0xab,0xa8,0xae,0x88,0xff},//05ﻫ{0xff,0xff,0x88,0xab,0xa8,0xaa,0x88,0xff},//06

{0xff,0xff,0x88,0xae,0xae,0xae,0x8e,0xff},//07ﻫ{0xff,0xff,0x88,0xaa,0xa8,0xaa,0x88,0xff},//08

{0xff,0xff,0x88,0xaa,0xa8,0xae,0x88,0xff},//09ﻫ{0xff,0xff,0xe8,0xea,0xea,0xea,0xe8,0xff},//10ﻫ{0xff,0xff,0xee,0xee,0xee,0xee,0xee,0xff},//11ﻫ{0xff,0xff,0xe8,0xee,0xe8,0xeb,0xe8,0xff},//12ﻫ{0xff,0xff,0xe8,0xee,0xe8,0xee,0xe8,0xff},//13ﻫ{0xff,0xff,0xea,0xea,0xe8,0xee,0xee,0xff},//14

{0xff,0xff,0xe8,0xeb,0xe8,0xee,0xe8,0xff},//15ﻫ{0xff,0xff,0xe8,0xeb,0xe8,0xea,0xe8,0xff},//16ﻫ{0xff,0xff,0xe8,0xee,0xee,0xee,0xee,0xff},//17ﻫ{0xff,0xff,0xe8,0xea,0xe8,0xea,0xe8,0xff},//18

{0xff,0xff,0xe8,0xea,0xe8,0xee,0xe8,0xff},//19ﻫ{0xff,0xff,0x88,0xea,0x8a,0xba,0x88,0xff},//20

{0xff,0xff,0x8e,0xee,0x8e,0xbe,0x8e,0xff},//21ﻫ{0xff,0xff,0x88,0xee,0x88,0xbb,0x88,0xff},//22ﻫ{0xff,0xff,0x88,0xee,0x88,0xbe,0x88,0xff},//23ﻫ{0xff,0xff,0x8a,0xea,0x88,0xbe,0x8e,0xff},//24

{0xff,0xff,0x88,0xeb,0x88,0xbe,0x88,0xff},//25ﻫ{0xff,0xff,0x88,0xeb,0x88,0xba,0x88,0xff},//26

{0xff,0xff,0x88,0xee,0x8e,0xbe,0x8e,0xff},//27

{0xff,0xff,0x88,0xea,0x88,0xba,0x88,0xff},//28ﻫ{0xff,0xff,0x88,0xea,0x88,0xbe,0x88,0xff},//29ﻫ{0xff,0xff,0x88,0xea,0x8a,0xea,0x88,0xff},//30ﻫ{0xff,0xff,0x8e,0xee,0x8e,0xee,0x8e,0xff},//31

{0xff,0xff,0x88,0xee,0x88,0xeb,0x88,0xff},//32ﻫ{0xff,0xff,0x88,0xee,0x88,0xee,0x88,0xff},//33ﻫ{0xff,0xff,0x8a,0xea,0x88,0xee,0x8e,0xff},//34ﻫ{0xff,0xff,0x88,0xeb,0x88,0xee,0x88,0xff},//35ﻫ{0xff,0xff,0x88,0xeb,0x88,0xea,0x88,0xff},//36ﻫ{0xff,0xff,0x88,0xee,0x8e,0xee,0x8e,0xff},//37ﻫ{0xff,0xff,0x88,0xea,0x88,0xea,0x88,0xff},//38ﻫ{0xff,0xff,0x88,0xea,0x88,0xee,0x88,0xff},//39ﻫ{0xff,0xff,0xa8,0xaa,0x8a,0xea,0xe8,0xff},//40ﻫ{0xff,0xff,0xae,0xae,0x8e,0xee,0xee,0xff},//41ﻫ{0xff,0xff,0xa8,0xae,0x88,0xeb,0xe8,0xff},//42

{0xff,0xff,0xa8,0xae,0x88,0xee,0xe8,0xff},//43

{0xff,0xff,0xaa,0xaa,0x88,0xee,0xee,0xff},//44

{0xff,0xff,0xa8,0xab,0x88,0xee,0xe8,0xff},//45ﻫ{0xff,0xff,0xa8,0xab,0x88,0xea,0xe8,0xff},//46ﻫ{0xff,0xff,0xa8,0xae,0x8e,0xee,0xee,0xff},//47ﻫ{0xff,0xff,0xa8,0xaa,0x88,0xea,0xe8,0xff},//48

{0xff,0xff,0xa8,0xaa,0x88,0xee,0xe8,0xff},//49ﻫ{0xff,0xff,0x88,0xba,0x8a,0xea,0x88,0xff},//50ﻫ{0xff,0xff,0x8e,0xbe,0x8e,0xee,0x8e,0xff},//51ﻫ{0xff,0xff,0x88,0xbe,0x88,0xeb,0x88,0xff},//52ﻫ{0xff,0xff,0x88,0xbe,0x88,0xee,0x88,0xff},//53ﻫ{0xff,0xff,0x8a,0xba,0x88,0xee,0x8e,0xff},//54ﻫ{0xff,0xff,0x88,0xbb,0x88,0xee,0x88,0xff},//55

{0xff,0xff,0x88,0xbb,0x88,0xea,0x88,0xff},//56

{0xff,0xff,0x88,0xbe,0x8e,0xee,0x8e,0xff},//57ﻫ{0xff,0xff,0x88,0xba,0x88,0xea,0x88,0xff},//58ﻫ{0xff,0xff,0x88,0xba,0x88,0xee,0x88,0xff},//59ﻫ};//===================================================================================//

//名称:delayﻫ//说明:延时函数ﻫ//功能:依据需要取不同的值,实现不同的延时效果ﻫ//===================================================================================//voiddelay()ﻫ{ﻫucharn;ﻫfor(n=0;n<=125;n++);ﻫ}voiddelay2(ucharm)ﻫ{ﻫucharn;

while(m-—)ﻫ{ﻫfor(n=0;n〈=200;n++);ﻫ}}//===================================================================================//ﻫ//名称:shiftﻫ//说明:74HC595左移程序ﻫ//功能:实现74HC595的移位输入ﻫ//===================================================================================//voidshift()ﻫ{ﻫucharj;ﻫfor(j=0;j〈8;j++)ﻫ{ﻫtemp[0]=temp[0]<<1;//将temp[0]左移1位ﻫSERIALIN_0=CY;//进位输出到移位寄存器ﻫtemp[1]=temp[1]<<1;//将temp[1]左移1位后ﻫSERIALIN_1=CY;//进位输出到移位寄存器

temp[2]=temp[2]<<1;//将temp[2]左移1位后ﻫSERIALIN_2=CY;//进位输出到移位寄存器ﻫtemp[3]=temp[3]<<1;//将temp[0]左移1位后的进位输出到移位寄存器ﻫSERIALIN_3=CY;//进位输出到移位寄存器ﻫCLOCK=1;//移位时钟掌握移位ﻫCLOCK=0;ﻫ}ﻫ}//===================================================================================//ﻫ//名称:displayﻫ//说明:显示函数ﻫ//功能:将要显示的数据通过74HC595和74LS154用LED点阵显示出来ﻫ//实现方法:该16X32点阵为8块小点阵,显示时将上下分开,上面显示时间。下面显示日期和秒ﻫ//===================================================================================//voiddisplay(void)

{ﻫuchari,sec;

sec=CLOCK_TIME[0];ﻫBUFFER[0]=CLOCK_TIME[1]%10;//显示时钟分钟个位

BUFFER[1]=CLOCK_TIME[1]/10;//显示时钟分钟十位ﻫBUFFER[2]=CLOCK_TIME[2]%10;//显示时钟小时个位ﻫBUFFER[3]=CLOCK_TIME[2]/10;//显示时钟小时十位ﻫBUFFER[4]=YEAR[1];//显示月,从00—12

BUFFER[5]=YEAR[2]/10;//显示日十位ﻫBUFFER[6]=YEAR[2]%10;//显示日个位

BUFFER[7]=CLOCK_TIME[0];//显示秒从00-59for(i=0;i〈16;i++)//逐行扫描ﻫ{

if(i<8)//上面的8行显示时间ﻫ{ﻫtemp[0]=bmp[BUFFER[3]][i];//取表显示时钟十位ﻫtemp[1]=bmp[BUFFER[2]][i];//取表显示时钟个位ﻫif(FLASH_STOP==0)//小时和分钟之间的两点闪标志位ﻫ{

temp[2]=bmp_1[BUFFER[1]][i];//标志位为0时,两点亮ﻫ}ﻫelseﻫ{ﻫtemp[2]=bmp[BUFFER[1]][i];//相反不亮

}

ﻫtemp[3]=bmp[BUFFER[0]][i];//取表显示分钟个位

}ﻫelseﻫ{

temp[0]=bmp_4[BUFFER[4]][i-8];//通过取表显示月ﻫtemp[1]=bmp_2[BUFFER[5]][i—8];//通过取表显示日ﻫtemp[2]=bmp_3[BUFFER[6]][i—8];ﻫtemp[3]=bmp_4[BUFFER[7]][i-8];//通过取表显示秒ﻫ}ﻫshift();//调用移位函数处理ﻫﻫLATCH=0;LATCH=1;//输出ﻫP0=i;//逐行显示,扫描ﻫdelay();//延时ﻫP0=0xff;//显示完一行清显示ﻫ}ﻫ}//===================================================================================//ﻫ//单字节写子程序RC0(SCLK),RC1(I/O),RC2(RST)ﻫ//名称:inputdataﻫ//说明:先写地址,后写数据ﻫ//功能:往DS1302写入时钟数据ﻫ//===================================================================================//ﻫvoidinputdata(unsignedchartmaddr,unsignedchartmdata)

{ﻫucharloop;

CLOCK_DATA=0;//设置为输出;ﻫCLOCK_RST=0;ﻫCLOCK_SCLK=0;ﻫCLOCK_RST=1;ﻫfor(loop=0;loop<8;loop++)//送地址ﻫ{ﻫtmaddr=tmaddr>〉1;//右移一位

CLOCK_DATA=CY;//输出移位标志位ﻫCLOCK_SCLK=1;

CLOCK_SCLK=0;ﻫ}

for(loop=0;loop〈8;loop++)//送数据

tmdata=tmdata>>1;//右移一位ﻫCLOCK_DATA=CY;//输出移位标志ﻫCLOCK_SCLK=1;ﻫCLOCK_SCLK=0;

}ﻫCLOCK_SCLK=1;ﻫCLOCK_RST=0;ﻫCLOCK_DATA=1;//设置为输出;

}

//===================================================================================//ﻫ//单字节读子程序RC0(SCLK),RC1(I/O),RC2(RST)ﻫ//名称:outputdataﻫ//说明:读数据ﻫ//功能:从DS1302读取1Byte数据

//===================================================================================//ﻫunsignedcharoutputdata(unsignedchartmaddr)ﻫ{ﻫucharloop;ﻫuchartmdata=0;ﻫinputdata(0x8F,0x00);

CLOCK_DATA=0;//设置为输ﻫCLOCK_RST=0;

CLOCK_SCLK=0;

CLOCK_RST=1;ﻫfor(loop=8;loop>0;loop——)//送地址ﻫ{ﻫtmaddr=tmaddr>>1;

CLOCK_DATA=CY;ﻫCLOCK_SCLK=1;ﻫCLOCK_SCLK=0;ﻫ}ﻫCLOCK_DATA=1;//设置为输入;ﻫCLOCK_DATA=1;ﻫCLOCK_SCLK=1;ﻫCLOCK_SCLK=0;

for(loop=8;loop〉0;loop—-)//读数据ﻫ{ﻫtmdata=tmdata>〉1;

if(CLOCK_DATA==1)

tmdata=tmdata|0x80;ﻫCLOCK_SCLK=1;ﻫCLOCK_SCLK=0;ﻫ}ﻫtmdata=tmdata〈<1;//由于在开头读是已经是其次个时钟下降延所以要进行左移处理ﻫif(CY==1)ﻫtmdata=tmdata|0x01;ﻫCLOCK_SCLK=1;ﻫCLOCK_RST=0;ﻫreturn(tmdata);ﻫ}//===================================================================================//

//函数:调整时间子程序ﻫ//名称:controlﻫ//说明:调整时间掌握ﻫ//功能:通过两个按键调整时间,其中一个选择要调整的分钟或时钟,另一个加1功能

//===================================================================================//voidcontrol()ﻫ{ﻫucharmin16,hour16;ﻫinputdata(0x80,0x80);//时钟停止运行ﻫCLOCK_TIME[0]=0;//秒初始化位0ﻫFLASH_STOP=0;//时钟分钟之间两点状态位为0ﻫTR0=0;//开启T0定时器while(1)ﻫ{ﻫif(K1==0)//当K1按下时ﻫ{ﻫdelay2(50);//延时ﻫif(K1==0)//K1按下ﻫ{ﻫCLOCK_TIME[1]=CLOCK_TIME[1]+1;//分钟加1ﻫif(CLOCK_TIME[1]==60)//当分钟加到60时初始化为0ﻫCLOCK_TIME[1]=0;

}ﻫ}ﻫif(K0==0)//K0键再次按下,小时调整ﻫ{

delay2(100);ﻫif(K0==0)

while(1)ﻫ{ﻫif(K0==1)//K0键按下加1ﻫ{while(1)

{ﻫif(K1==0)ﻫ{ﻫdelay2(50);

if(K1==0)

{ﻫCLOCK_TIME[2]=CLOCK_TIME[2]+1;//小时加1

if(CLOCK_TIME[2]==24)//当变成24时初始化为0ﻫCLOCK_TIME[2]=0;ﻫ}ﻫﻫ}ﻫif(K0==0)//当K0再次按下时返回ﻫ{ﻫdelay2(100);ﻫif(K0==0)ﻫ{

while(1)ﻫ{ﻫif(K0==1)//按下的键弹起时ﻫ{

min16=CLOCK_TIME[1]/10*16+CLOCK_TIME[1]%10;//将所得的分钟数据转变成16进制数据ﻫhour16=CLOCK_TIME[2]/10*16+CLOCK_TIME[2]%10;//将所得的小时数据转变成16进制数据

inputdata(0x84,hour16);//将调整后的小时数据写入DS1302ﻫinputdata(0x82,min16);//将调整后的分钟数据写入DS1302ﻫ

inputdata(0x80,0x00);//启动时钟ﻫtime();//回到time函数ﻫ}

}ﻫ}ﻫ}ﻫdisplay();//显示函数ﻫ}ﻫﻫ}ﻫ}ﻫ}ﻫ}

display();//显示函数

}ﻫ}//===================================================================================//ﻫ//函数:T0中断服务子程序

//名称:time0

//说明:掌握时钟和分钟之间的两点显示

//功能:利用单片机内部定时器造成0.5秒时钟和分钟之间两点闪动ﻫ//===================================================================================//ﻫvoidtime0(void)interrupt1using1//T0中断函数ﻫ{

TH0=-10100/256;//填入计数器初值高位ﻫTL0=—10100%256;//填入计数器初值低位

sec_flash=sec_flash+1;ﻫif(sec_flash==50)//0。5S到ﻫ{ﻫFLASH_STOP=0;

}ﻫif(sec_flash==100)//1S到

{

FLASH_STOP=1;ﻫsec_flash=0;ﻫ}ﻫ}//===================================================================================//

//函数:时间掌握函数ﻫ//说明:统一时钟显示于调整ﻫ//功能:ﻫ//===================================================================================//ﻫvoidtime()ﻫ{

ucharsec,min,hour,year,month,day;ﻫFLASH_STOP=1;

EA=1;ET0=1;//开总中断源,开T0中断ﻫTMOD=0x61;//T1方式2计数,T0方式1计时

TH0=—10000/256;TL0=-10000%256;//初始化计数器初值ﻫET0=1,TR0=1;//开中断ﻫﻫinputdata(0x8E,0x00);//掌握命令,WP=0,写操作ﻫinputdata(0x90,0x06);while(1)ﻫ{ﻫK0=1;//K0=1ﻫif(K0==0)

{ﻫdelay2(100);//延时ﻫif(K0==0)//K0按下时ﻫ{

while(1)

{ﻫif(K0==1)

{ﻫcontrol();//进入调时子程序ﻫ}

}ﻫ}

}ﻫsec=outputdata(0x81);//读取秒ﻫmin=outputdata(0x83);//读取分ﻫhour=outputdata(0x85);//读取时ﻫyear=outputdata(0x8d);//读取年ﻫmonth=outputdata(0x89);//读取月

day=outputdata(0x87);//读取日

CLOCK_TIME[0]=sec/16*10+sec%16;//将读取到的16进制数转化为10进制ﻫCLOCK_TIME[1]=min/16*10+min%16;//将读取到的16进制数转化为10进制

CLOCK_TIME[2]=hour/16*10+hour%16;//将读取到的16进制数转化为10进制ﻫﻫYEAR[0]=year/16*10+year%16;//将读取到的16进制数转化为10进制

YEAR[1]=month/16*10+month%16;ﻫYEAR[2]=day/16*10+day%16;display();//调用显示子函数ﻫ}ﻫ}//===================================================================================//ﻫ//函数:主程序ﻫ//说明:ﻫ//功能:

//===================================================================================//ﻫvoidmain()ﻫ{ﻫtime();ﻫ}附:点阵汉字显示程序//===================================================================================//ﻫ//*标题:16*32点阵汉字显示程序

//*说明:接受89s51或52单片机,12M晶震,列接受74HC595驱动(共4个),行驱动接受4-16线译码器74LS154ﻫ//*功能:通过动态扫描显示汉字,并实现左移功能ﻫ//*作者:HEYﻫ//*日期:2006-06-01ﻫ//*邮箱:billy3416@163.comﻫ//*声明:以下源程序均通过keil调试与硬件实现均无问题

//===================================================================================//ﻫ#include<reg52.h〉

#include<stdlib.h>ﻫ#defineucharunsignedchar//===================================================================================//ﻫ//用到的引脚及端口定义及全局变量

//===================================================================================//ﻫsbitSERIALIN_0=P2^0;//定义P2.0为列向第1个74HC595的DATA输入

sbitSERIALIN_1=P2^1;//定义P2。1为列向第1个74HC595的DATA输入

sbitSERIALIN_2=P2^2;//定义P2.2为列向第1个74HC595的DATA输入ﻫsbitSERIALIN_3=P2^3;//定义P2。3为列向第1个74HC595的DATA输入sbitCLOCK=P2^4;//74HC595的移位时钟掌握ﻫsbitLATCH=P2^5;//74HC595的锁存输出时钟掌握uchartemp[4]={0,0,0,0};//用到的74HC595显示缓冲区变量ﻫuchardisp[4][16];//用到的显示缓冲区//===================================================================================//

//定义要显示的汉字代码段16*16,分别是左上—左下-右上-右下ﻫ//===================================================================================//ﻫucharcodeword[52][16]={ﻫ/*****点*****/

{0xfe,0xfe,0xfe,0xfe,0xfe,0xe0,0xef,0xef,0xef,0xe0,0xef,0xfe,0xd7,0xdb,0xbb,0xff},ﻫ{0xff,0xff,0x07,0xff,0xef,0x07,0xef,0xef,0xef,0x0f,0xef,0xef,0x77,0xbb,0xbb,0xff},/*****阵*****/

{0xff,0x07,0x77,0x68,0x5e,0x6e,0x75,0x70,0x77,0x57,0x68,0x7f,0x7f,0x7f,0x7f,0x7f},ﻫ{0x7f,0x7f,0x7f,0x03,0xff,0xbf,0xbf,0x03,0xbf,0xbf,0x01,0xbf,0xbf,0xbf,0xbf,0xbf},/*****显*****/ﻫ{0xff,0xe0,0xef,0xe0,0xef,0xe0,0xfb,0xfb,0xbb,0xdb,0xeb,0xeb,0xfb,0x00,0xff,0xff},ﻫ{0xff,0x0f,0xef,0x0f,0xef,0x0f,0xbf,0xbf,0xb7,0xb7,0xaf,0x9f,0xbf,0x01,0xff,0xff},/*****示*****/ﻫ{0xff,0xe0,0xff,0xff,0xff,0x80,0xfe,0xfe,0xee,0xee,0xde,0xbe,0x7e,0xfe,0xfa,0xfd},

{0xff,0x07,0xff,0xff,0xff,0x01,0xff,0xff,0xdf,0xef,0xf7,0xf3,0xfb,0xff,0xff,0xff},/*****由*****/ﻫ{0xfe,0xfe,0xfe,0xfe,0xc0,0xde,0xde,0xde,0xc0,0xde,0xde,0xde,0xde,0xc0,0xdf,0xff},

{0xff,0xff,0xff,0xff,0x07,0xf7,0xf7,0xf7,0x07,0xf7,0xf7,0xf7,0xf7,0x07,0xf7,0xff},/*****信*****/ﻫ{0xf7,0xf3,0xe7,0xe8,0xcf,0xcc,0xaf,0x6c,0xef,0xec,0xed,0xed,0xed,0xec,0xed,0xff},

{0x7f,0x9f,0xbf,0x01,0xff,0x07,0xff,0x07,0xff,0x07,0xf7,0xf7,0xf7,0x07,0xf7,0xff},/*****息*****/ﻫ{0xfe,0xfd,0xe0,0xef,0xe0,0xef,0xe0,0xef,0xe0,0xff,0xf6,0xd7,0xd7,0x97,0xf8,0xff},ﻫ{0xff,0xff,0x0f,0xef,0x0f,0xef,0x0f,0xef,0x0f,0xff,0xff,0x7b,0x6d,0xed,0x0f,0xff},/*****工*****/ﻫ{0xff,0xc0,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0x00,0xff,0xff},ﻫ{0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01,0xff,0xff},/*****程*****/

{0xf2,0x8e,0xee,0xee,0x02,0xee,0xcf,0xc4,0xab,0xaf,0x6c,0xef,0xef,0xef,0xe8,0xef},ﻫ{0x07,0xf7,0xf7,0xf7,0xf7,0x07,0xff,0x03,0xbf,0xbf,0x03,0xbf,0xbf,0xbf,0x01,0xff},/*****学*****/ﻫ{0xfe,0xef,0xf3,0xf7,0x80,0xbf,0x70,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0xfd,0xfe},ﻫ{0xf7,0x73,0x37,0x6f,0x01,0xfb,0x17,0xbf,0x7f,0x01,0x7f,0x7f,0x7f,0x7f,0x7f,0xff},/*****院*****/

{0xff,0x07,0x70,0x6b,0x5f,0x5c,0x6f,0x77,0x70,0x56,0x6e,0x7e,0x7d,0x7d,0x7b,0x77},

{0x7f,0xbf,0x01,0xfb,0xff,0x07,0xff,0xff,0x01,0xdf,0xdf,0xdf,0xdd,0xdd,0xdd,0xe1},ﻫ{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},ﻫ{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},ﻫ{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},ﻫ{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}};ﻫﻫ//===================================================================================//ﻫ//名称:delayﻫ//说明:延时函数ﻫ//功能:依据需要取不同的值,实现不同的延时效果

//===================================================================================//ﻫvoiddelay()ﻫ{ﻫuchari;ﻫfor(i=0;i〈=100;i++);ﻫ}

//==============================================================

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论