基于51单片机的1302时钟芯片C程序Word下载.docx

上传人:b****3 文档编号:16574025 上传时间:2022-11-24 格式:DOCX 页数:60 大小:27.25KB
下载 相关 举报
基于51单片机的1302时钟芯片C程序Word下载.docx_第1页
第1页 / 共60页
基于51单片机的1302时钟芯片C程序Word下载.docx_第2页
第2页 / 共60页
基于51单片机的1302时钟芯片C程序Word下载.docx_第3页
第3页 / 共60页
基于51单片机的1302时钟芯片C程序Word下载.docx_第4页
第4页 / 共60页
基于51单片机的1302时钟芯片C程序Word下载.docx_第5页
第5页 / 共60页
点击查看更多>>
下载资源
资源描述

基于51单片机的1302时钟芯片C程序Word下载.docx

《基于51单片机的1302时钟芯片C程序Word下载.docx》由会员分享,可在线阅读,更多相关《基于51单片机的1302时钟芯片C程序Word下载.docx(60页珍藏版)》请在冰豆网上搜索。

基于51单片机的1302时钟芯片C程序Word下载.docx

voidRTInputByte(uchar);

//输入1Byte*/

ucharRTOutputByte(void);

//输出1Byte*/

voidW1302(uchar,uchar);

//向DS1302写入一个字节

ucharR1302(uchar);

//从DS1302读出一个字节

voidSet1302(uchar*);

//设置时间

voidKeySound();

//按键音

voidClockSound();

//闹铃蜂鸣声

/**************温度函数声明************/

voiddisplay_tem();

uintread_tmp();

voidtmpchange();

voidtmpwrite(uchardat);

uchartmpread_byte();

bittmpread_bit();

voiddsreset();

voiddelay2(uintz);

//voidtime_LCM(uchar);

voidkeyscan();

ucharid,msec,model,LedTime,flag,d,num1,num2,num3,c1,c2,c3,flag1;

bita,b;

ucharinittime[7]={0x00,0x00,0x12,0x20,0x07,0x02,0x10};

//初始化后设置为:

2010年7月20日星期212点0分0秒

voidOut_LCM(void);

//显示屏幕

voidmodel0(void);

//显示输出

voidmodel1(void);

voidmodel2(void);

voidmodel3(void);

voidmodel4(void);

voidmodel5(void);

voidmodel6(void);

voidmode1();

voidmode2();

voidmode3();

voidmode4();

voidmode5();

voidmode6();

voidmode7();

voidmode8();

voidid_case1_key();

//项目调整

voidModset();

//模式键处理

voidWriteDataLCM(ucharWDLCM);

voidWriteCommandLCM(ucharWCLCM,BuysC);

ucharReadStatusLCM(void);

voidLCMInit(void);

voidOutputInformation(ucharX,ucharY,ucharDData);

voidDisplayListChar(ucharX,ucharY,ucharcode*DData);

voidDelay5Ms(void);

voidDelay400Ms(void);

voidsystemsetup(void);

//进入系统设置

ucharcodesystemp[]={"

System.setup"

};

//字符串输出(系统设定)

ucharcodeTIMER[]={"

Time"

//字符串输出(时间)

ucharcodeTIMER1[]={"

T"

ucharcodeDATE[]={"

Date"

//字符串输出(日期)

ucharcodeDATE1[]={"

D"

ucharcodealarmclock[]={"

Clock"

//字符串输出(闹铃)

ucharcodelamp[]={"

Lamp"

//字符串输出(背光灯)

ucharcodereset[]={"

Reset"

//字符串输出(时间归零)

ucharcodeexit[]={"

Exit"

//字符串输出(退出)

ucharcodeset[]={"

Set"

//字符串输出(设置)

ucharcodesec[]={"

sec"

//字符串输出(秒)

ucharcodeClockSet[]={"

ClockSet"

//字符串输出(闹铃设置)

ucharcodeClockOn[]={"

ON"

//字符串输出(ON)

ucharcodeClockOff[]={"

OFF"

//字符串输出(OFF)

ucharcodetake[]={"

TakingTimeToSet"

ucharcodeshi1[]={"

06:

30"

ucharcodeshi2[]={"

07:

ucharcodeshi3[]={"

11:

ucharcodeshi4[]={"

12:

ucharcodeshi5[]={"

18:

ucharcodeshi6[]={"

19:

ucharcodeshi7[]={"

00:

ucharcodeshi8[]={"

03:

voidtimesetup(void);

//时间设置

voiddatesetup(void);

//日期设置

voidalarmclockset(void);

//闹铃设置

voidlampsetup(void);

//背光灯设置

voidtimereset(void);

//时间清零

/*******************************************************************/

voiddelay1(intms)

{

unsignedchary;

while(ms--)

{

for(y=0;

y<

250;

y++)

_nop_();

}

}

voidmain(void)

{

Speaker=1;

//关闭蜂鸣器

LED=0;

//打开LED,低电平有效,外接9012驱动

Delay400Ms();

//启动等待,等LCM讲入工作状态

LCMInit();

//LCM初始化

TMOD=0x01;

//16位定时

TH0=0x3c;

//50ms

TL0=0xb0;

EA=1;

TR0=1;

ET0=1;

flag=1;

flag1=1;

while

(1)

{

keyscan();

if(TimerDown==0)//左移键按下后把背光灯打开

{Delay5Ms();

if(TimerDown==0)

{KeySound();

//蜂鸣声

LED=0;

//打开背光灯

LedTime=R1302(0xc1)/16*10+R1302(0xc1)%16;

}//取出背光灯时间并转换为十进制数

if(TimerUp==0)//左移键按下后把背光灯打开

if(TimerUp==0)

b=1;

//模式键是否动作标志。

为1时不动作,为0时动作。

Modset();

//调用模式键处理程序判断按键是否按下。

if(b==0)

KeySound();

//打开背光灯

systemsetup();

//进入系统设置模式

//取出背光灯时间并转换为十进制数

if((LED==0)&

&

LedTime==0)//延时间是否到

LED=1;

//关闭背光灯

if(R1302(0xc3)==1)//闹铃是否打开,0xc3为读闹铃寄存器地址。

if((R1302(0x85)==R1302(0xc5))&

(R1302(0x83)==R1302(0xc7))&

(flag1))//判断闹铃时间是否到,

{

ClockSound();

//发出闹铃蜂鸣声,无按键动作蜂鸣一分钟。

LED=0;

if((TimerDown==0)||(TimerUp==0))

{

flag1=0;

}

}

if(R1302(0x83)!

=R1302(0xc7))

flag1=1;

}

model0();

//输出显示屏幕

}

voidKeySound()//按键音

Speaker=0;

//开蜂鸣声

Delay5Ms();

//关蜂鸣声

voidClockSound()//闹铃蜂鸣声

if(a==0)

//关蜂鸣声

voidModset()//模式键处理

{if(system==0)

if(system==0)

{while(system==0);

a=0;

msec=0;

b=0;

//a、msec为闪烁标志,按键有动作时清零,不闪烁。

}//b为模式键确认动作。

其它程判断b是否为零时来确定模式键是否动作。

voidsystemsetup(void)//系统设置

model=1;

while(model!

=0)

Out_LCM();

if(TimerUp==0)//设置项目左移

{a=0;

KeySound();

//蜂鸣声

if(model--==1)//6种系统设置项目

model=6;

}

while(TimerUp==0);

if(TimerDown==0)//设置项目右移

if(TimerDown==0)

if(model++==6)

model=1;

while(TimerDown==0);

switch(model)//进入进个项目设置

{

case1:

timesetup();

break;

case2:

datesetup();

break;

case3:

alarmclockset();

//闹铃设置

case4:

lampsetup();

//背光灯设置

case5:

timereset();

case6:

model=0;

//退出系统设置

}

voidtimesetup()//时间调整

id=6;

while(model==1)//model为1时进入时间调整

if(id++==9)//6..9为时分秒调。

.

id_case1_key();

//调用按键处理

//显示输出

voiddatesetup()//对日期进行调整

id=1;

while(model==2)//model为2时进入日期调整

{b=1;

//模式键是否动作

if(id++==5)//1..5为年月日星期exit

//日期调整

voidalarmclockset(void)//闹铃调整

{id=12;

while(model==3)//进入闹铃设置

//模式键是否动作

if(b==0)

if(R1302(0xc3)%16==0)

{id=0;

model++;

}//0xc2为闹铃开关寄存器。

当为关时按下模式键时将退出闹铃设置,当开时进入闹铃时间设置

elseif(id++==15)//12..15为闹铃开关和时间设置exit

id=12;

//调整

}

voidlampsetup(void)//背光灯时间设置

{id=10;

//背光灯存储空间DS1302(0xc0)

while(model==4)//model为3时进入背光灯调整

if(id++==11)//10为背光灯exit

id=10;

//显示输出

voidtimereset()//时间清零

Set1302(inittime);

//清时间

W1302(0x90,0xa6);

//打开充电二级管一个二级管串联一个2K电阻

model++;

//对相应的项目进行加、减调整。

voidid_case1_key()//按键处理

if(TimerUp==0)//增加

if((id==9)||(id==5)||(id==11)||(id==15))//当ID为9、5时按下加、减键将退出调整

{model++;

//退出时间、日期设置

id=0;

else

Set(id,1);

if(TimerDown==0)//减少

else

Set(id,0);

//调用DS1302写入函数

voidtimer_1(void)interrupt1//中断入口,闪烁

//50ms定时

if(msec++==10)//500ms

msec=0;

a=~a;

//闪烁标志反转

if(a==0)//1秒后背光时间减一秒。

LedTime--;

//根据选择调整相应项目并写入DS1302

voidSet(ucharsel,ucharsel_1)

ucharaddress,item;

ucharmax,min;

if(sel==1){address=0x8c;

max=99;

min=0;

}//年

if(sel==2){address=0x88;

max=12;

min=1;

}//月

if(sel==3){address=0x86;

max=31;

}//日

if(sel==4){address=0x8a;

max=7;

min=1;

}//星期

if(sel==6){address=0x84;

max=23;

}//小时

if(sel==7){address=0x82;

max=59;

}//分钟

if(sel==8){address=0x80;

}//秒

if(sel==10){address=0xc0;

}//背光时间,最长1分钟

if(sel==12){address=0xc2;

max=1;

}//闹铃开关寄存器

if(sel==13){address=0xc4;

}//闹铃时寄存器

if(sel==14){address=0xc6;

}//闹铃分寄存器

item=R1302(address+1)/16*10+R1302(address+1)%16;

if(sel_1==0)item++;

elseitem--;

if(item>

max)item=min;

if(item<

min)item=max;

W1302(0x8e,0x00);

//允许写操作

W1302(address,item/10*16+item%10);

//写入DS1302//转成BCD码

W1302(0x8e,0x80);

//写保护,禁止写操作

//屏幕显示

voidOut_LCM(void)

{switch(model)

case0:

case1:

model1();

case2:

model2();

//在不同的条件下显示不同的字符

case3:

model3();

case4:

model4();

model5();

case6:

model6();

/***********************model为零时第一行显示时间,不为零时显示systemsetup******/

voidmodel0()

{

//DisplayListChar(0,0,TIMER);

//显示固定字符串(Time)

OutputInformation(9,0,0x20);

//不显示

OutputInformation(12,1,0x20);

//OutputInformation(15,1,0x20);

OutputInformation(4,1,0x2f);

//显示固定字符"

/"

OutputInformation(7,1,0x2f);

OutputInformation(10,1,0x2f);

//DisplayListChar(0,1,DATE);

//显示固定字符串Date(日期)

display_tem();

if(a==1)//冒号闪烁

{OutputInformation(3,0,0x3a);

OutputInformation(6,0,0x3a);

{OutputInformation(3,0,0x20);

OutputInformation(6,0,0x20);

/*******************model为零时第二行显示日期,不为零显示设置项目*******/

OutputInformation(0,1,'

2'

);

//显示年

Out

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 调查报告

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1