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

📄 liquid.c

📁 使用的是8951单片机实现万年历的程序,并且有液晶显示..还有proteus文件可以直接仿真 ...请求加分,原创.
💻 C
📖 第 1 页 / 共 2 页
字号:
//OCM12864参考程序
#include <reg52.h>
#define uint       unsigned int
#define uchar      unsigned char
#define disp_off   0x3e
#define disp_on    0x3f
#define disp_x     0xb8
#define disp_z     0xc0
#define disp_y     0x40
#define comm       0
#define dat        1
#define data_ora   P2       //MCU P1<------> LCM

sbit di =P3^7;  //Data or Instrument Select,H:写数据,L:写指令
sbit rw =P3^6;  //Write or Read,H:read,L:write
sbit e  =P3^5;  //读写使能
sbit cs1=P3^4;  //cs1=H,选择左半屏
sbit cs2=P3^3;  //cs2=H,选择右半屏
sbit rst=P3^2;  //Lcm reset,低有效
sbit bf =P2^7;
sbit res=P2^4;
////////////**自定义的全局变量***/////////////

char function=0;/////功能键的作用是判别当前在什么状态下
////*******/////
/*
function 功能说明
0 正常状态
1 调整时间的年
2 调整时间的月
3 调整时间的日
4 调整时间的时
5 调整时间的分
6 调整时间的秒
7 调整闹钟的能否使用
8 调整闹钟的时
9 调整闹钟的分
10 调整星期的值
*/
////******/////

int year_counter=2007;////年的计数
char month_counter=12;//////取值为1到12
char day_counter=10;/////取值为1到30,
char hour_counter=12;/////计时当前的小时,取值为0到23
char minute_counter=9;////计时分钟,取值为0到59
char second_counter=56;/////计时秒,取值为0到59
char week_counter=0;//////计数星期,取值为0到6,共七个值,0表示星期1,6表示星期日
char ring_enable=1;//////闹钟的标记位,标记闹钟是否允许,0是禁止,1是开放
char ring_hour=12;
char ring_min=10;
char time_reach=0;////标记有没有达到闹钟所标记的定时时间,达到则此位被置1
uchar counter=0;////计数范围为0到200,200*5ms=1s
//uchar tmp_second;/////在显示功能键到了哪一个的函数中,用于闪烁显示
uchar enable_add=1;//////允许日的计数,由于日要考虑到大月,小月,闰年的情况,比较复杂,用以此位标记正常的情况,

uchar enable_sub=1;///////允许日的减数,标记减的正常进行

sbit fun_key=P1^2;
sbit add_key=P1^1;
sbit sub_key=P1^0;/////定义三个开关 

////**初始化函数,使用定时器0来产生精确的50ms的信号,本次用的晶振为12MHZ**////////////
uchar code time_up[]=
{
///////***             定 ****////////
0x00, 0x10, 0x0c, 0xa4, 0x24, 0x24, 0x25, 0xe6, 0x24, 0x24, 0x24, 0x24, 0x14, 0x0c, 0x04, 0x00, 
0x40, 0x20, 0x18, 0x07, 0x08, 0x10, 0x20, 0x7f, 0x42, 0x42, 0x42, 0x42, 0x40, 0x40, 0x00, 0x00, 

/////******             时****//////
0x00, 0xfc, 0x44, 0x44, 0x44, 0xfc, 0x10, 0x90, 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x00, 
0x00, 0x07, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00, 0x03, 0x40, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00,

////****               到***////
0x00, 0x22, 0x72, 0x2a, 0x26, 0xe2, 0x2a, 0x72, 0x22, 0x00, 0xf8, 0x00, 0x00, 0xff, 0x00, 0x00, 
0x00, 0x42, 0xc2, 0x42, 0x22, 0x3f, 0x22, 0x12, 0x12, 0x00, 0x0f, 0x40, 0x80, 0x7f, 0x00, 0x00, 
};


uchar code week1[]=
{
////**    一    **///////
0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc0, 0x80, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

uchar code week2[]=
{
////**    二    **///////
0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00, 0x00, 0x00, 
0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x18, 0x10, 0x00, 

};
uchar code week3[]=
{
////**    三    **///////
0x00, 0x04, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x04, 0x00, 0x00, 
0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 

};
uchar code week4[]=
{
////**    四    **///////
0x00, 0xfe, 0x02, 0x02, 0x02, 0xfe, 0x02, 0x02, 0xfe, 0x02, 0x02, 0x02, 0x02, 0xfe, 0x00, 0x00, 
0x00, 0x7f, 0x28, 0x24, 0x23, 0x20, 0x20, 0x20, 0x21, 0x22, 0x22, 0x22, 0x22, 0x7f, 0x00, 0x00, 

};
uchar code week5[]=
{
////**    五    **///////
0x00, 0x02, 0x82, 0x82, 0x82, 0x82, 0xfe, 0x82, 0x82, 0x82, 0xc2, 0x82, 0x02, 0x00, 0x00, 0x00, 
0x20, 0x20, 0x20, 0x20, 0x20, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x3f, 0x20, 0x20, 0x30, 0x20, 0x00, 

};
uchar code week6[]=
{
////**    六    **///////
0x10, 0x10, 0x10, 0x10, 0x10, 0x91, 0x12, 0x1e, 0x94, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 
0x00, 0x40, 0x20, 0x10, 0x0c, 0x03, 0x01, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x78, 0x30, 0x00, 0x00, 

};
uchar code week7[]=
{
////**    日   **///////
0x00, 0x00, 0x00, 0xfe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xfe, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x3f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x00,
};
uchar code num0[]=
{
//////***    0      ****///////
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,

};

uchar code num1[]=
{
//////***    1      ****///////
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

};
uchar code num2[]=
{
//////***    2      ****///////
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,

};
uchar code num3[]=
{
//////***    3     ****///////
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,

};
uchar code num4[]=
{
//////***    4      ****///////
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,

};
uchar code num5[]=
{
//////***    5      ****///////
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,

};
uchar code num6[]=
{
//////***    6      ****///////
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,

};
uchar code num7[]=
{
//////***    7      ****///////
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,

};
uchar code num8[]=
{
//////***    8     ****///////
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,

};
uchar code num9[]=
{
//////***    9      ****///////
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,

};
uchar code naozhong[]=
{
/////****   闹   ***////////
0x00, 0x00, 0xf9, 0x12, 0x90, 0x92, 0x96, 0xfa, 0x92, 0x92, 0x92, 0x12, 0x02, 0xfe, 0x00, 0x00, 
0x00, 0x00, 0xff, 0x00, 0x1f, 0x00, 0x00, 0x7f, 0x00, 0x08, 0x1f, 0x40, 0x80, 0x7f, 0x00, 0x00, 

////***    钟       **///
0x40, 0x30, 0x2c, 0xeb, 0x28, 0x28, 0x00, 0xf8, 0x08, 0x08, 0xff, 0x08, 0x08, 0xf8, 0x00, 0x00, 
0x01, 0x01, 0x01, 0xff, 0x41, 0x21, 0x00, 0x01, 0x01, 0x01, 0xff, 0x01, 0x01, 0x01, 0x00, 0x00, 

};
uchar code open[]=
{
///*****    开    ***///
0x40, 0x42, 0x42, 0x42, 0x42, 0xfe, 0x42, 0x42, 0x42, 0x42, 0xfe, 0x42, 0x42, 0x42, 0x42, 0x00, 
0x00, 0x40, 0x20, 0x10, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 

};
uchar code close[]=
{
///******   关     ***/////
0x00, 0x10, 0x10, 0x10, 0x11, 0x1e, 0x14, 0xf0, 0x10, 0x18, 0x17, 0x12, 0x18, 0x10, 0x00, 0x00, 
0x01, 0x81, 0x41, 0x21, 0x11, 0x09, 0x05, 0x03, 0x05, 0x09, 0x31, 0x61, 0xc1, 0x41, 0x01, 0x00, 

};

uchar code year[]=
{
/////****   年   ****/////
0x40, 0x20, 0x10, 0x0c, 0xe3, 0x22, 0x22, 0x22, 0xfe, 0x22, 0x22, 0x22, 0x22, 0x02, 0x00, 0x00, 
0x04, 0x04, 0x04, 0x04, 0x07, 0x04, 0x04, 0x04, 0xff, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 

};
uchar code month[]=
{
/////****   月   ****/////
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x11, 0x11, 0x11, 0x11, 0x11, 0xff, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x40, 0x20, 0x10, 0x0c, 0x03, 0x01, 0x01, 0x01, 0x21, 0x41, 0x3f, 0x00, 0x00, 0x00, 0x00, 
};

uchar code day[]=
{
/////****   日   ****/////
0x00, 0x00, 0x00, 0xfe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xfe, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x3f, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x00, 
};

uchar code hour[]=
{
/////****   时   ****/////
0x00, 0xfc, 0x44, 0x44, 0x44, 0xfc, 0x10, 0x90, 0x10, 0x10, 0x10, 0xff, 0x10, 0x10, 0x10, 0x00, 
0x00, 0x07, 0x04, 0x04, 0x04, 0x07, 0x00, 0x00, 0x03, 0x40, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00,
};

uchar code miniute[]=
{
/////****   分   ****/////
0x80, 0x40, 0x20, 0x98, 0x87, 0x82, 0x80, 0x80, 0x83, 0x84, 0x98, 0x30, 0x60, 0xc0, 0x40, 0x00, 
0x00, 0x80, 0x40, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x20, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 

};

uchar code second[]=
{
/////****   秒   ****/////
0x12, 0x12, 0xd2, 0xfe, 0x91, 0x11, 0xc0, 0x38, 0x10, 0x00, 0xff, 0x00, 0x08, 0x10, 0x60, 0x00, 
0x04, 0x03, 0x00, 0xff, 0x00, 0x83, 0x80, 0x40, 0x40, 0x20, 0x23, 0x10, 0x08, 0x04, 0x03, 0x00,
};
uchar code week[]=
{
/////****   星   ****/////
0x00, 0x00, 0x00, 0xbe, 0x2a, 0x2a, 0x2a, 0xea, 0x2a, 0x2a, 0x2a, 0x2a, 0x3e, 0x00, 0x00, 0x00, 
0x00, 0x48, 0x46, 0x41, 0x49, 0x49, 0x49, 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x41, 0x40, 0x00,

/////****   期   ****/////
0x00, 0x04, 0xff, 0x54, 0x54, 0x54, 0xff, 0x04, 0x00, 0xfe, 0x22, 0x22, 0x22, 0xfe, 0x00, 0x00, 
0x42, 0x22, 0x1b, 0x02, 0x02, 0x0a, 0x33, 0x62, 0x18, 0x07, 0x02, 0x22, 0x42, 0x3f, 0x00, 0x00, 

};
uchar code clear[]=
{
/////////**   为了刷屏的需要   **//////////
0x00, 0x00, 0x00,0x00, 0x00, 0x00,0x00, 0x00, 0x00,0x00, 0x00, 0x00,0x00, 0x00, 0x00,0x00, 0x00, 

};


/////////***   数字钟计时方面的函数   ***////////
void initial_timer(void)
{
TMOD=0x01;/////定时器工作在方式1,16位计数的状态下
TL0=-5000%256;
TH0=-5000/256;
ET0=1;/////定时器0中断打开
EA=1;/////全局中断打开
TR0=1;/////启动定时器
}
//////****初始化函数结束***//////////
///**延时函数*////
void delay(unsigned char i)
{
	while(--i);
		
}
//精确延时,,,,(i-1)*2+5微秒

///////***中断处理函数,定时器0中断为1号中断**///////
void timer(void) interrupt 1 using 1
{
TL0=-5000%256;
TH0=-5000/256;////定时器再次载入初值
counter++;
}



////***以下为读开关的程序**/////
//////设置为读到秒的开关返回1;读到分的开关返回为2;读到时的开关返回3;否则返回0
//////开关的设置为在开关按下为低电平,返回值为开关的编号


int read_key(void)
{
P1=0xff;
////**判断秒位的进位键有没有被按下**//////
if(sub_key==0)
{
delay(10);/////延时一段时间再采样,防止噪声
if(sub_key==0)
{
while(sub_key==0);/////确保一次按键无论多长时间只能加1秒
return(1);
}
}
////**判断分位的进位键有没有被按下**//////
if(add_key==0)
{
delay(10);/////延时一段时间再采样,防止噪声
if(add_key==0)
{
while(add_key==0);
return(2);
}
}
////**判断小时的进位键有没有被按下**//////
if(fun_key==0)
{
delay(10);/////延时一段时间再采样,防止噪声
if(fun_key==0)
{
while(fun_key==0);
return(3);
}
}
return(0);


}
/////////***   下面的函数的作用是根据数字返回对应液晶字符数组的指针 (0到9)    ***////////////
char*conv_point(char numx)
{
switch(numx)
{
case 0:
return(num0);
case 1:
return(num1);
case 2:
return(num2);
case 3:
return(num3);
case 4:
return(num4);
case 5:
return(num5);
case 6:
return(num6);
case 7:
return(num7);
case 8:
return(num8);
case 9:
return(num9);
}
}
/////////******                   下面函数的作用是返回星期对应的字符数组指针                          *******//////////
char *week_point(char week_num)
{
switch(week_num)
{
case 0:
return(week1);
case 1:
return(week2);
case 2:
return(week3);
case 3:
return(week4);
case 4:
return(week5);
case 5:
return(week6);
case 6:
return(week7);
}


}


////**开关的的处理函数*****/////
void key_process(int key)
{
switch(key)
{
case 1:    /////读到的开关键是减
switch(function)
{
case 1:////调整年的值
year_counter--;
break;
case 2:////调整月的值
if(month_counter==1)
month_counter=12;
else
month_counter--;

break;

case 3://///调整日期

if(month_counter==1&&day_counter==1)/////一月
{
enable_sub=0;
day_counter=31;
}
if(year_counter%4==0)//////闰年
{
if(month_counter==2&&day_counter==1)/////二月
{
enable_sub=0;
day_counter=28;
}
}
else
{
if(month_counter==2&&day_counter==1)
{
enable_sub=0;
day_counter=29;
}
}

if(month_counter==3&&day_counter==1)/////三月
{
enable_sub=0;
day_counter=31;
}
if(month_counter==4&&day_counter==1)/////四月
{
enable_sub=0;
day_counter=30;
}
if(month_counter==5&&day_counter==1)/////五月
{
enable_sub=0;
day_counter=31;
}
if(month_counter==6&&day_counter==1)/////六月
{
enable_sub=0;
day_counter=30;
}
if(month_counter==7&&day_counter==1)/////七月
{
enable_sub=0;
day_counter=31;
}
if(month_counter==8&&day_counter==1)/////八月
{
enable_sub=0;
day_counter=31;
}
if(month_counter==9&&day_counter==1)/////九月
{
enable_sub=0;
day_counter=30;
}
if(month_counter==10&&day_counter==1)/////十月
{
enable_sub=0;
day_counter=31;
}
if(month_counter==11&&day_counter==1)/////十一月
{
enable_sub=0;
day_counter=30;
}
if(month_counter==12&&day_counter==1)/////十二月
{
enable_sub=0;
day_counter=31;
}

if(enable_sub==1)
day_counter--;


break;

case 4://///调整时的值
if(hour_counter==0)
hour_counter=23;
else
hour_counter--;
break;

case 5://///调整分的值
if(minute_counter==0)
minute_counter=59;
else
minute_counter--;
break;

case 6:////调整秒的值
if(second_counter==0)
second_counter=59;
else
second_counter--;
break;

case 7:////调整闹钟的使能值
if(ring_enable==1)
ring_enable=0;
else
ring_enable=1;
break;

case 8:///调整闹钟的时
if(ring_hour==0)
ring_hour=23;
else
ring_hour--;
break;

case 9://///调整闹钟的分
if(ring_min==0)
ring_min=59;
else
ring_min--;
break;

case 10:
if(week_counter==0)
week_counter=7;
else
week_counter--;
break;
}

break;

case 2:    /////读到的开关键是加
switch(function)
{
case 1:
year_counter++;////调整年的值

break;
case 2:////调整月的值
if(month_counter==12)
month_counter=1;
else
month_counter++;
break;
case 3:///调整日的值

/*
if(day_counter==30)
day_counter=1;
else
day_counter++;
*/

if(month_counter==1&&day_counter==31)/////一月
{
enable_add=0;
day_counter=1;
}
if(year_counter%4==0)//////闰年
{
if(month_counter==2&&day_counter==28)/////二月

⌨️ 快捷键说明

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