⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于SPCE061A单片机的语音电子时钟,液晶显示,语音控制,汉语报时(课程设计题目)
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "SPCE061A.H"
#include "SPLC501User.h"				//包含SPLC501液晶模组驱动程序的用户接口API函数声明的头文件
#include "zf.h"                         //字符库
#include "consist.h"
#include "a2000.h"


#define P_Watchdog_Clear		(volatile unsigned int *)0x7012

unsigned int aa[100][3]={
    	                 {"00"},{"01"},{"02"},{"03"},{"04"},{"05"},{"06"},{"07"},{"08"},{"09"},
                         {"10"},{"11"},{"12"},{"13"},{"14"},{"15"},{"16"},{"17"},{"18"},{"19"}, 
                         {"20"},{"21"},{"22"},{"23"},{"24"},{"25"},{"26"},{"27"},{"28"},{"29"},
                         {"30"},{"31"},{"32"},{"33"},{"34"},{"35"},{"36"},{"37"},{"38"},{"39"},
                         {"40"},{"41"},{"42"},{"43"},{"44"},{"45"},{"46"},{"47"},{"48"},{"49"},
                         {"50"},{"51"},{"52"},{"53"},{"54"},{"55"},{"56"},{"57"},{"58"},{"59"},
                         {"60"},{"61"},{"62"},{"63"},{"64"},{"65"},{"66"},{"67"},{"68"},{"69"},
                         {"70"},{"71"},{"72"},{"73"},{"74"},{"75"},{"76"},{"77"},{"78"},{"79"}, 
                         {"80"},{"81"},{"82"},{"83"},{"84"},{"85"},{"86"},{"87"},{"88"},{"89"},
                         {"80"},{"81"},{"82"},{"83"},{"84"},{"85"},{"86"},{"87"},{"88"},{"89"},
                         {"90"},{"91"},{"92"},{"93"},{"94"},{"95"},{"96"},{"97"},{"98"},{"99"} 
                       };

struct time
{
	unsigned int year;
  	unsigned int month;
	unsigned int day;
	unsigned int hour;
	unsigned int minute;
	unsigned int second;
	unsigned int hsecond;
	unsigned int msecond;
} timeb,times,timen1,timen2,timen3,timen4;
struct brow
{
	unsigned int top;//上
	unsigned int bottom;//下
	unsigned int left;//左
	unsigned int right;//右
} browl,brow2,brow3,brow4,brow5,brow6;

unsigned char menu_flag;//主菜单标志
unsigned char adjust_flag;//调整标志
unsigned char second_flag;//秒表标志
unsigned char second_flag1;
unsigned char alarm_flag;//闹钟标志
unsigned char alarm_flag1;
unsigned char alarm_flag11;
unsigned char alarm_flag2;
unsigned char alarm_flag21;
unsigned char alarm_flag3;
unsigned char alarm_flag31;
unsigned char alarm_flag4;
unsigned char alarm_flag41;
unsigned char clock_flag111;


 main(void)//主程序
{
	init();//初始化
	
	while(1)
	{
		
		scan_key1();//键盘程序/接IOA低八位
		display1();//显示
	}
	
}

void init(void)//初始化
{
   	*P_IOA_Dir = 0xff00;
  	*P_IOA_Attrib = 0xff00;
   	*P_IOA_Data = 0x0000;
   
   	*P_IOB_Dir=0xffff;
   	*P_IOB_Attrib=0xffff;
   	*P_IOB_Data=0x0000;
   	
   	timeb.year = 06;
   	timeb.month =2;
   	timeb.day = 28;
   	timeb.hour = 23;
   	timeb.minute = 59;
   	timeb.second = 59;
   	
   	LCD501_Init(0x00);	              //初始化LCD端口以及LCD初始化所需要的设置,在SPLC501User.c中定义
	LCD501_FontSet(1);						//设置大号的ASCII码字体
   	
	asm("int off");	     //关中断			
	*P_INT_Ctrl=0x0010;	//1kHZ定时中断
	asm("int irq,fiq");    //开中断
}

void IRQ4(void)__attribute__((ISR));//中断服务程序
void IRQ4(void)
{
   if (*P_INT_Ctrl == 0x0010)
  {  	   
      *P_INT_Clear=0x0010;
       
       timeb.msecond++;
       if(timeb.msecond == 10)
       {
       		time_change();
       		time_mchange();
       }
  }
}
void time_change(void)//时间改变程序
{
	timeb.msecond = 0;
	timeb.hsecond++;
	{
		if(timeb.hsecond ==100)
		{
			timeb.hsecond = 0;
		 	timeb.second++;
		 	
			if(timeb.second == 60)
			{
				timeb.second = 0;
				timeb.minute++;
				if(alarm_flag1 == 1) clock1();
				if(alarm_flag2 == 1) clock2();
				if(alarm_flag3 == 1) clock3();
				if(alarm_flag4 == 1) clock4();
				if(timeb.minute == 60)
				{
					timeb.minute = 0;
					timeb.hour++;
					if(timeb.hour == 24)
					{
						timeb.hour = 0;
			    		timeb.day++;
						day_change();//日期改变程序
					}
				}
			}
		}
	}
}

void clock1(void)
{
	if((timeb.minute == timen1.minute) &&(timeb.hour == timen1.hour))
	clock_flag111 = 1;
	else clock_flag111 = 0;
	dell();
}
void clock2(void)
{
	if((timeb.minute == timen2.minute) &&(timeb.hour == timen2.hour))
	clock_flag111 = 1;
	else clock_flag111 = 0;	
    dell();
}
void clock3(void)
{
	if((timeb.minute == timen3.minute) &&(timeb.hour == timen3.hour))
	clock_flag111 = 1;
	else clock_flag111 = 0;	
	dell();
}
void clock4(void)
{
	if((timeb.minute == timen4.minute) &&(timeb.hour == timen4.hour))
	clock_flag111 = 1;
	else clock_flag111 = 0;	
    dell();

}

void dell(void)
{
	while(clock_flag111 == 1)
	{
		unsigned int key;
    	PlayRespond(0);   //报时声
    	display1();
 	 	key = key_code();//取得键值
 	 	if(key == 0x0040)    
 	 	{
 	 		clock_flag111 = 0;
 	 		timeb.minute++;
 	 	}	 	
	}
}	


void day_change(void)//日期改变程序
{	
	if(timeb.month == 1 || timeb.month == 3 || timeb.month == 5 || timeb.month == 7 || 
	   timeb.month == 8|| timeb.month == 10 || timeb.month == 12)
	{
		if(timeb.day == 32)
		{
			timeb.day = 1;
			timeb.month++;
		}
	}
	else if(timeb.month == 4 || timeb.month == 6 || timeb.month == 9 || timeb.month == 11)
	{
		if(timeb.day == 31)
		{
			timeb.day = 1;
			timeb.month++;
		}
	}	
	else if(timeb.month == 2)
	{
		unsigned char leap;
		if((timeb.year%4 == 0&&timeb.year%100 !=0)  || (timeb.year%400 == 0)) leap = 1;
		else    leap = 0;
		if(leap ==1)
		{
			if(timeb.day == 30)
			{
				timeb.day = 1;
				timeb.month++;
			}
		}
		else
		{
			if(timeb.day == 29)
			{
				timeb.day = 1;
				timeb.month++;
			}
		}
	}
	if(timeb.month == 13)
	{
			timeb.day = 1;
			timeb.month = 1;
			timeb.year++;
	}
}

void time_mchange(void)//秒表时间改变
{
	if(second_flag)
	{
		times.hsecond++;
		if(times.hsecond == 100)
		{
			times.hsecond = 0;
			times.second++;	
			if(times.second ==60)
			{
				times.second = 0;
				times.minute++;
				{
					if(times.minute == 100)
					{
						second_flag == 0;
					}
				}
			}
		}
	}
}

							
void scan_key1(void)//键盘程序
{
	unsigned int key;
	key = key_code();//取得键值
	
	switch(key)
	{
		case 0x0001:menu();break;//菜单
//		case 0x0080:SpeakTime();break;//报时
		default:break;
	}
}
unsigned int key_code(void)//取得键值
{
	unsigned int key;
	if(judge_key())          //判键
	{
		*P_IOA_Data=*P_IOA_Data&0xff00;
		key = *P_IOA_Data&0x00ff;
		while(judge_key());
		return key;
	}
}
				 	
unsigned char judge_key(void)  //判键
{
	if((*P_IOA_Data&0x00ff)!=0x0000)
	{
		delay10ms();
		if((*P_IOA_Data&0x00ff)!=0x0000)
		     return(1);
		else return(0);
	}
}

void delay10ms(void)
{
	unsigned int i;
	for(i=0;i<1000;i++)
	{
		*P_Watchdog_Clear = 0x0001;
	}
}
		
void menu(void)//菜单
{
	LCD501_Init(0x00);
	LCD501_ClrScreen(0);
	menu_flag = 1;
     browl.right = 8;	
	while(menu_flag)
	{
		display2();
		scan_key2();		
	}
}
void scan_key2(void)
{
	unsigned int key;
	key = key_code();//取得键值
	
	switch(key)
	{
		case 0x0002:top1();break;//向上
		case 0x0004:bottom1();break;//向下
		case 0x0020:sure1();break;//确定
		case 0x0040:return1();break;//返回
		default:break;
	}
}
void top1(void)
{
	LCD501_Bitmap(12,browl.right,(unsigned int *)encoding_1f);//
	if( browl.right == 8) 
	browl.right = 40;
	else 
	browl.right -= 16;
}
void bottom1(void)
{
    LCD501_Bitmap(12,browl.right,(unsigned int *)encoding_1f);//
	if( browl.right == 40)
		browl.right = 8;
	else
	    browl.right += 16;
}
void return1(void)
{
	menu_flag = 0;
	LCD501_ClrScreen(0);
}
void sure1(void)
{
	if(browl.right == 8)
		time_adjust();//调整时间
	else if(browl.right == 24)
		second_clock();//秒表
	else if(browl.right == 40)
		alarm_clock();//闹钟
}
void time_adjust(void)
{
	asm("int off");	
	LCD501_ClrScreen(0);
	adjust_flag = 1;
	brow2.bottom = 16;
	brow2.top = 16;
	while(adjust_flag)
	{
		display3();
		scan_key3();
	}
}

void scan_key3(void)
{
	unsigned int key;
	key = key_code();//取得键值
	
	switch(key)
	{
		case 0x0002:add();break;//加一
		case 0x0004:sub();break;//减一
		case 0x0008:left1();break;//左移
    case 0x0010:right1();break;//右移
		case 0x0040:return2();break;//返回
		default:break;
	}
}
void add(void)
{
	if(brow2.top == 16 && brow2.bottom == 16)
	{
		timeb.year++;
		if(timeb.year == 60) timeb.year = 0;
	}
	else if(brow2.top == 48 && brow2.bottom == 16)
	{
		timeb.month++;
		if(timeb.month ==13)  timeb.month = 0;
	}
	else if(brow2.top == 80 && brow2.bottom == 16)
	{	
		timeb.day++;
		day_change1();
	}
	else if(brow2.top == 16 && brow2.bottom == 48)
	{
		timeb.hour++;
		if(timeb.hour == 24)  timeb.hour = 0;
	}
	else if(brow2.top == 48 && brow2.bottom == 48)
	{
		timeb.minute++;
		if(timeb.minute == 60)  timeb.minute = 0;
	}
	else if(brow2.top == 80 && brow2.bottom == 48)
	{
		timeb.second++;
		if(timeb.second == 60)  timeb.second = 0;
	}
	display3();
}


void day_change1(void)
{
	if(timeb.month == 1 || timeb.month == 3 || timeb.month == 5 || timeb.month == 7 || 
	   timeb.month == 8|| timeb.month == 10 || timeb.month == 12)
	{
		if(timeb.day == 32)
		{
			timeb.day = 1;
		}
	}
	else if(timeb.month == 4 || timeb.month == 6 || timeb.month == 9 || timeb.month == 11)
	{
		if(timeb.day == 31)
		{
			timeb.day = 1;
		}
	}	
	else if(timeb.month == 2)
	{
		unsigned char leap;
		if((timeb.year%4 == 0&&timeb.year%100 !=0)  || (timeb.year%400 == 0)) leap = 1;
		else    leap = 0;
		if(leap ==1)
		{
			if(timeb.day == 30)
			{
				timeb.day = 1;
			}
		}
		else
		{
			if(timeb.day == 29)
			{
				timeb.day = 1;
			}
		}
	}
}
void sub(void)
{
	if(brow2.top == 16 && brow2.bottom == 16)
	{
		if(timeb.year == 0) timeb.year = 59;
		else  timeb.year--;
	}
	else if(brow2.top == 48 && brow2.bottom == 16)
	{
		timeb.month--;
		if(timeb.month ==0)  timeb.month = 12;
	}
	else if(brow2.top == 80 && brow2.bottom == 16)
	{	
		timeb.day--;
		day_change2();
	}
	else if(brow2.top == 16 && brow2.bottom == 48)
	{
		if(timeb.hour == 0)  timeb.hour = 23;
		else  timeb.hour--;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -