基于PSOC3的自动报时系统时钟.docx

上传人:b****7 文档编号:8979723 上传时间:2023-02-02 格式:DOCX 页数:45 大小:84.69KB
下载 相关 举报
基于PSOC3的自动报时系统时钟.docx_第1页
第1页 / 共45页
基于PSOC3的自动报时系统时钟.docx_第2页
第2页 / 共45页
基于PSOC3的自动报时系统时钟.docx_第3页
第3页 / 共45页
基于PSOC3的自动报时系统时钟.docx_第4页
第4页 / 共45页
基于PSOC3的自动报时系统时钟.docx_第5页
第5页 / 共45页
点击查看更多>>
下载资源
资源描述

基于PSOC3的自动报时系统时钟.docx

《基于PSOC3的自动报时系统时钟.docx》由会员分享,可在线阅读,更多相关《基于PSOC3的自动报时系统时钟.docx(45页珍藏版)》请在冰豆网上搜索。

基于PSOC3的自动报时系统时钟.docx

基于PSOC3的自动报时系统时钟

基于PSOC3的自动报时系统.

功能:

可以调时、计时。

显示日期,时间。

还具有闹钟功能。

整点报时

原理图如下:

引脚分配:

P2是LCD的接口。

Pin_3\Pin_4是两个按钮。

Pin_1是蜂鸣器。

Mian.c的程序如下:

#include

uint8StatusRegister;

uint8InterruptCnt;

uint8secl,sech,minl,minh,houl,houh,a_secl=9,a_sech=5,a_minl=9,a_minh=5,a_houl=3,a_houh;

uint16sec=50,min=59,hou=3,day=1,mon=1,yea=2013,a_sec=0,a_min=0,a_hou=0;

uint8my_mode=0;flag=0;

char*alarmclock_state="OFF";

uint8alarmclock_other_flag=0;

uint8alarmclock_flag1=0,alarmclock_flag2=0,alarmclock_flag3=0;

uint8blank_flag=0;

uint8test_flag=0;

uint8mode0_flag=0;

uint8baoshi_flag=0;

uint8baoshi_cishu=0;

uint8cnt=0;

uint8alarm_bee_flag=0;

CY_ISR(TT1)

{test_flag++;

my_mode=0;

if(alarm_bee_flag==1)

{Pin_1_Write(0);

alarm_bee_flag=0;}

alarmclock_flag2=0;

alarmclock_flag3=0;

alarmclock_state="OFF";

mode0_flag=0;

}

CY_ISR(MY_I)

{if((a_houh==(hou/10))&&(a_houl==(hou%10))&&(a_minh==(min/10))&&(a_minl==(min%10))&&(a_sech==(sec/10))&&(a_secl==(sec%10))&&(alarmclock_flag1==1))

{alarm_bee_flag=1;}

if(alarm_bee_flag==1)

{Pin_1_Write

(1);}

if(baoshi_flag==1)

{cnt++;

if(cnt<2)

{Pin_1_Write

(1);}

if(cnt>2)

{Pin_1_Write(0);}

if(cnt==4)

{cnt=0;

baoshi_cishu--;

if(baoshi_cishu==0)

{baoshi_flag=0;}}

}

else

{baoshi_flag=0;}

StatusRegister=Timer_1_ReadStatusRegister();

InterruptCnt++;

if(InterruptCnt==2)

{

InterruptCnt=0;

sec++;

if(sec==60)

{sec=0;

min++;

if(min==60)

{hou++;

min=0;

if(hou==24)

{{hou=0;

day++;

if(day==29)

{if(~((yea/4==0&&yea/100!

=0)||(yea/400==0))&&(mon==2))

{day=0;

mon++;}}

if(day==31)

{if(~((mon==1)||(mon==3)||(mon==5)||(mon==7)||(mon==8)||(mon==10)||(mon==12)))

{day=0;

mon++;}}

if(day==32)

{day=0;

mon++;

}

if(mon==13)

{yea++;}

}

}

}

}

if((min==0)&&(sec==0))

{baoshi_flag=1;

baoshi_cishu=hou;}

}

}

CY_ISR(B_b)

{if(my_mode==0)

{

mode0_flag++;

if(mode0_flag==15)

{mode0_flag=0;}

}

if(my_mode==1)

{if(alarmclock_flag3==0)

{

alarmclock_flag1++;

if(alarmclock_flag1==2)

{alarmclock_flag1=0;

}

if(alarmclock_flag1==1)

{alarmclock_flag2++;

if(alarmclock_flag2==2)

{alarmclock_flag2=0;}

}

}

else

{

switch(alarmclock_flag3)

{case1:

a_houh++;if(a_houh==3){a_houh=0;};break;

case2:

a_houl++;if(a_houl==10){a_houl=0;};break;

case3:

a_minh++;if(a_minh==6){a_minh=0;};break;

case4:

a_minl++;if(a_minl==10){a_minl=0;};break;

case5:

a_sech++;if(a_sech==6){a_sech=0;};break;

case6:

a_secl++;if(a_secl==10){a_secl=0;};break;

default:

break;

}}

}}

CY_ISR(B_a)

{if((my_mode==0)&&(mode0_flag!

=0))

{

switch(mode0_flag)

{

case14:

hou=hou+10;if(hou>24){hou=0;};break;

case13:

hou++;if(hou>24){hou=0;};break;

case12:

min=min+10;if(min>=60){min=0;};break;

case11:

min++;if(min>=60){min=0;};break;

case10:

sec=sec+10;if(sec>=60){sec=0;};break;

case9:

sec++;if(sec>=60){sec=0;};break;

case8:

yea=yea+1000;if(yea>=10000){yea=0;};break;

case7:

yea=yea+100;break;

case6:

yea=yea+10;break;

case5:

yea=yea++;break;

case4:

mon=mon+10;break;

case3:

mon++;break;

case2:

day=day+10;break;

case1:

day++;break;

default:

break;

}

}

if((alarmclock_flag2==0)&&(mode0_flag==0))

{

my_mode=my_mode+1;

if(my_mode==2)

{my_mode=0;}

}

if(alarmclock_flag2==1)

{alarmclock_flag3++;

if(alarmclock_flag3==7)

{alarmclock_flag3=0;}

}

}

voidmain()

{

CyGlobalIntEnable;

ButtonISR_Start();

ButtonISR_Disable();

ButtonISR1_Start();

ButtonISR1_Disable();

TimerISR_Start();

TimerISR_Disable();

TimerISR_1_Start();

TimerISR_1_Disable();

ButtonISR_SetVector(B_a);

ButtonISR_Enable();

ButtonISR1_SetVector(B_b);

ButtonISR1_Enable();

TimerISR_SetVector(MY_I);

TimerISR_Enable();

TimerISR_1_SetVector(TT1);

TimerISR_1_Enable();

clock_1_Enable();

clock_2_Enable();

Timer_1_Start();

Timer_2_Start();

LCD_Start();

Pin_1_Write(0);

for(;;)

{LCD_Position(0,15);

LCD_PrintNumber(cnt);

switch(my_mode)

{case0:

if(mode0_flag==0)

{

LCD_Position(0,0);

LCD_PrintString("Time:

");

LCD_Position(0,5);

LCD_PrintString("");

LCD_Position(0,6);

LCD_PrintNumber(hou/10);

LCD_Position(0,7);

LCD_PrintNumber(hou%10);

LCD_Position(0,8);

LCD_PrintString("-");

LCD_Position(0,9);

LCD_PrintNumber(min/10);

LCD_Position(0,10);

LCD_PrintNumber(min%10);

LCD_Position(0,11);

LCD_PrintString("-");

LCD_Position(0,12);

LCD_PrintNumber(sec/10);

LCD_Position(0,13);

LCD_PrintNumber(sec%10);

LCD_Position(0,14);

LCD_PrintString("");

LCD_Position(1,0);

LCD_PrintString("Date:

");

LCD_Position(1,5);

LCD_PrintString("");

LCD_Position(1,6);

LCD_PrintNumber(yea/1000);

LCD_Position(1,7);

LCD_PrintNumber((yea%1000)/100);

LCD_Position(1,8);

LCD_PrintNumber(((yea%1000)%100)/10);

LCD_Position(1,9);

LCD_PrintNumber(((yea%1000)%100)%10);

LCD_PrintString("-");

LCD_Position(1,11);

LCD_PrintNumber(mon/10);

LCD_Position(1,12);

LCD_PrintNumber(mon%10);

LCD_Position(1,13);

LCD_PrintString("-");

LCD_Position(1,15);

LCD_PrintString("");

LCD_Position(1,14);

LCD_PrintNumber(day/10);

LCD_Position(1,15);

LCD_PrintNumber(day%10);

}

if(mode0_flag==14)

{

LCD_Position(0,0);

LCD_PrintString("Time:

");

LCD_Position(0,5);

LCD_PrintString("");

LCD_Position(0,6);

if(InterruptCnt==0)

{LCD_PrintString("");}

else

{LCD_PrintNumber(hou/10);}

LCD_Position(0,7);

LCD_PrintNumber(hou%10);

LCD_Position(0,8);

LCD_PrintString("-");

LCD_Position(0,9);

LCD_PrintNumber(min/10);

LCD_Position(0,10);

LCD_PrintNumber(min%10);

LCD_Position(0,11);

LCD_PrintString("-");

LCD_Position(0,12);

LCD_PrintNumber(sec/10);

LCD_Position(0,13);

LCD_PrintNumber(sec%10);

LCD_Position(0,14);

LCD_PrintString("");

LCD_Position(1,0);

LCD_PrintString("Date:

");

LCD_Position(1,5);

LCD_PrintString("");

LCD_Position(1,6);

LCD_PrintNumber(yea/1000);

LCD_Position(1,7);

LCD_PrintNumber((yea%1000)/100);

LCD_Position(1,8);

LCD_PrintNumber(((yea%1000)%100)/10);

LCD_Position(1,9);

LCD_PrintNumber(((yea%1000)%100)%10);

LCD_PrintString("-");

LCD_Position(1,11);

LCD_PrintNumber(mon/10);

LCD_Position(1,12);

LCD_PrintNumber(mon%10);

LCD_Position(1,13);

LCD_PrintString("-");

LCD_Position(1,15);

LCD_PrintString("");

LCD_Position(1,14);

LCD_PrintNumber(day/10);

LCD_Position(1,15);

LCD_PrintNumber(day%10);

}

if(mode0_flag==13)

{

LCD_Position(0,0);

LCD_PrintString("Time:

");

LCD_Position(0,5);

LCD_PrintString("");

LCD_PrintString("");

LCD_Position(0,6);

LCD_PrintNumber(hou/10);

LCD_Position(0,7);

if(InterruptCnt==0)

{LCD_PrintString("");}

else

{LCD_PrintNumber(hou%10);}

LCD_Position(0,8);

LCD_PrintString("-");

LCD_Position(0,9);

LCD_PrintNumber(min/10);

LCD_Position(0,10);

LCD_PrintNumber(min%10);

LCD_Position(0,11);

LCD_PrintString("-");

LCD_Position(0,12);

LCD_PrintNumber(sec/10);

LCD_Position(0,13);

LCD_PrintNumber(sec%10);

LCD_Position(0,14);

LCD_PrintString("");

LCD_Position(1,0);

LCD_PrintString("Date:

");

LCD_Position(1,5);

LCD_PrintString("");

LCD_Position(1,6);

LCD_PrintNumber(yea/1000);

LCD_Position(1,7);

LCD_PrintNumber((yea%1000)/100);

LCD_Position(1,8);

LCD_PrintNumber(((yea%1000)%100)/10);

LCD_Position(1,9);

LCD_PrintNumber(((yea%1000)%100)%10);

LCD_PrintString("-");

LCD_Position(1,11);

LCD_PrintNumber(mon/10);

LCD_Position(1,12);

LCD_PrintNumber(mon%10);

LCD_Position(1,13);

LCD_PrintString("-");

LCD_Position(1,15);

LCD_PrintString("");

LCD_Position(1,14);

LCD_PrintNumber(day/10);

LCD_Position(1,15);

LCD_PrintNumber(day%10);

}

if(mode0_flag==12)

{

LCD_Position(0,0);

LCD_PrintString("Time:

");

LCD_Position(0,5);

LCD_PrintString("");

LCD_PrintString("");

LCD_Position(0,6);

LCD_PrintNumber(hou/10);

LCD_Position(0,7);

LCD_PrintNumber(hou%10);

LCD_Position(0,8);

LCD_PrintString("-");

LCD_Position(0,9);

if(InterruptCnt==0)

{LCD_PrintString("");}

else

{LCD_PrintNumber(min/10);}

LCD_Position(0,10);

LCD_PrintNumber(min%10);

LCD_Position(0,11);

LCD_PrintString("-");

LCD_Position(0,12);

LCD_PrintNumber(sec/10);

LCD_Position(0,13);

LCD_PrintNumber(sec%10);

LCD_Position(0,14);

LCD_PrintString("");

LCD_Position(1,0);

LCD_PrintString("Date:

");

LCD_Position(1,5);

LCD_PrintString("");

LCD_Position(1,6);

LCD_PrintNumber(yea/1000);

LCD_Position(1,7);

LCD_PrintNumber((yea%1000)/100);

LCD_Position(1,8);

LCD_PrintNumber(((yea%1000)%100)/10);

LCD_Position(1,9);

LCD_PrintNumber(((yea%1000)%100)%10);

LCD_PrintString("-");

LCD_Position(1,11);

LCD_PrintNumber(mon/10);

LCD_Position(1,12);

LCD_PrintNumber(mon%10);

LCD_Position(1,13);

LCD_PrintString("-");

LCD_Position(1,15);

LCD_PrintString("");

LCD_Position(1,14);

LCD_PrintNumber(day/10);

LCD_Position(1,15);

LCD_PrintNumber(day%10);

}

if(mode0_flag==11)

{

LCD_Position(0,0);

LCD_PrintString("Time:

");

LCD_Position(0,5);

LCD_PrintString("");

LCD_PrintString("");

LCD_Position(0,6);

LCD_PrintNumber(hou/10);

LCD_Position(0,7);

LCD_PrintNumber(hou%10);

LCD_Position(0,8);

LCD_PrintString("-");

LCD_Position(0,9);

LCD_PrintNumber(min/10);

LCD_Position(0,10);

if(InterruptCnt==0)

{LCD_PrintString("");}

else

{LCD_PrintNumber(min%10);}

LCD_Position(0,11);

LCD_PrintString("-");

LCD_Position(0,12);

LCD_PrintNumber(sec/10);

LCD_

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

当前位置:首页 > 法律文书 > 判决书

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

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