📄 main.c
字号:
/**************************************************************************
* 文 件 名:main.c
* 功 能:万年历( 公历加农历),键盘输入,电子钢琴
* 作 者:张聪
**************************************************************************/
/****************************文件包含*************************************/
#include < at89x52.h >
#include < character.h >
#include < lcd.h >
#include < clock.h >
#include < sensor.h>
#include < calendar.h >
#include < key.h >
/*****************************预定义**************************************/
#define uchar unsigned char
#define uint unsigned int
unsigned char hi_note,low_note;
unsigned char STH0;
unsigned char STL0;
uchar ID=0;
unsigned char lastop;
unsigned long result=0;
unsigned long currentvalue=0,lastvalue=0;
/**********************************************************************
** 函数申明 **
**********************************************************************/
void display(int);
unsigned char key_scan(void);
unsigned char transition(unsigned char);
bit isdigit(unsigned char );
unsigned int process(unsigned char );
uchar input1();
/****************************************************************************
数组功能:计算器键盘定义
****************************************************************************/
unsigned char code keyvalue[]=
{
'7','8','9','/',
'4','5','6','*',
'1','2','3','-',
'o','0','=','+'
};
/****************************************************************************
数组功能:自定义歌曲
****************************************************************************/
code unsigned song[]={
0xfc,0xd1,0xc1,0xb1,0xc1, 0xd4,0xc1,0xd1,0xf1,0xc1,0xd6,0xc1,0xd1, 0xcc,0x01,0xc1,0xb1,0x91,0x81, 0x94,0x81,0x91,0xb1,0x81,0x98,
0x86,0x62,0x84,0xb2,0xc2, 0xd6,0xc1,0xd1,0xf6,0xd2, 0xc6,0xc2,0x01,0xc2,0xc2,0xb2,0x92,0xb8,0x41,0x51,0x61,0x51,0x61,0x81,0x41,0x51,
0x62,0xd4,0x01,0xd2,0x01,0xd8, 0xc2,0xc1,0xd1,0xd2,0xc2,0xb4,0x92,0x82, 0x66,0x52,0x42,0xb2,0xb2,0x92, 0x88,0x01,0x81,0x61,0x84,0x01,0x82,
0x92,0xb2,0xb2,0x92,0xb4,0xc1,0xb1,0x91,0x81, 0x62,0x82,0x82,0x81,0x91,0x84,0x42,0x52, 0x62,0x82,0x82,0xb2,0x92,0x82,0x62,0x52, 0x46,0xb2,0x92,0x82,0x61,0x51,0x42,
0x56,0x82,0x82,0x62,0x62,0x52, 0x42,0x42,0x52,0x62,0x86,0x01,0x82, 0x62,0x82,0x82,0xb2,0xb2,0xc2,0xc2,0xc2,0xc1,0xd1, 0xcf,
0xb6,0xc2,0xd4,0xc2,0xb2, 0x92,0xb2,0xb2,0x92,0x84,0x64,0x01, 0x66,0x82,0x81,0x91,0x82,0x61,0x51,0x42, 0x5c,0x62,0x82,
0x86,0x92,0x82,0x62,0x84, 0x92,0xb2,0xb2,0xc2,0xd8, 0xc6,0x01,0xc2,0xc2,0xc2,0xb2,0x91,0xb1, 0xbf,0x01, 0xbf,0x00};
code int note[]={
0x0000,0xFB03,0xFB8E,0xFC0B,0xFC43,0xFCAB,0xFD08,0xFD32,
0xFD81,0xFDC7,0xFE05,0xFE21,0xFE55,0xFE83,0xFE99,0xFEC0};
/****************************************************************************
数组功能:定义音节频率低音3到高音7
****************************************************************************/
unsigned int code tab[32]={64021,64103,64185,64260,64331,64400,64463,64524,
64580,64633,64684,64732,64777,64820,64860,64898,
64934,64968,64994,65030,65058,65085,65110,65134,
65157,65178,65198,65217,65235,65252,65268,65283};
code ksp[8]={0x8F,0x9F,0xAF,0xBF,0xCF,0xDF,0xEF,0xFF};
/****************************************************************************
数组功能:定义 按键按下时 P2口的数据
****************************************************************************/
code key_code1[32]={142,206,174,238,158,222,190,254,
141,205,173,237,157,221,189,253,
139,203,171,235,155,219,187,251,
135,199,167,231,151,215,183,247};
/****************************************************************************/
sbit in = P0 ^ 2 ;// 定义闹钟停止端口
sbit cut = P0 ^ 4;//功能切换端口
sbit bell = P0 ^ 5; //定义蜂鸣器端口
/*****************************************************************************
* 名称: timer1_isr(void) inturrupt 2
* 功能:
* 入口参数:
* 出口参数:
*****************************************************************************/
void calendar();
void singing();
static void timer1_isr(void) interrupt TF1_VECTOR using 2
{
TR1=0;
TL1=low_note;
TH1=hi_note;
TR1=1;
bell=~bell;
}
/*****************************************************************************
* 名称: timer1_initialize() inturrupt 0
* 功能:
* 入口参数:
* 出口参数:
*****************************************************************************/
static void timer1_initialize(void)
{
EA=0;
TR1=0;
TMOD = 0X10;
ET1=1;
EA=1;
}
/*****************************************************************************
* 名称: Timer0_Service() inturrupt 0
* 功能:
* 入口参数:
* 出口参数:
*****************************************************************************/
void t0(void) interrupt 1 using 0
{
TH0=STH0;
TL0=STL0;
bell=~bell;
}
/*****************************************************************************
* 名称: void switcch()
* 功能:功能选择键钮
* 入口参数:
* 出口参数:
/*****************************************************************************/
void switcch()
{ void calendar();
void input();
void piano();
void singsong();
void calculator();
switch(ID)
{ case 0:
{Lcd_Clear();
calendar();break;}
case 1:
{Lcd_Clear();
calculator();break;}
case 2:
{Lcd_Clear();
piano();break;}
case 3:
{Lcd_Clear();
input();break;}
case 4:
{Lcd_Clear();
singsong();break;}
}
}
/******************************************************************************
* 函数名称
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -