//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,