#include <reg52.h>
#include <stdlib.h>
#include <intrins.h>
#include <stdio.h>
#define TIMER0_COUNT 0xFE33
#define uchar unsigned char
#define uint unsigned int
unsigned char count_min_1=0;
unsigned char count_min_2=0;
unsigned char count_hour_1=0;
unsigned char count_hour_2=0;
uchar KEY,timer0_tick=0;
uint a;
/********************引脚定义********************/
sbit RS =P2^5; //数据指令
sbit RW =P2^6; //读写
sbit E =P2^7; //使能
sbit CS1 =P2^3; //左片选
sbit CS2 =P2^4; //中片选
sbit RST =P2^2; //右片选
sbit KEY_YES =P2^0; //YES
sbit KEY_NO =P2^1; //NO
sbit KEY_UP =P3^4; //UP
sbit KEY_DOWN =P3^5; //DOWN
unsigned char Page; //页 地址
unsigned char Col; //列 地址
unsigned char code BMP0[]; //启动界面
unsigned char code BMP1[]; //选择界面
unsigned char code BMP2[]; //帐户信息界面
unsigned char code BMP3[]; //公司联系方式
unsigned char code BMP4[]; //公司简介
unsigned char code BMP5[];
unsigned char code Cursor[]; //光标
unsigned char code number_0[];
unsigned char code number_1[];
unsigned char code number_2[];
unsigned char code number_3[];
unsigned char code number_4[];
unsigned char code number_5[];
unsigned char code number_6[];
unsigned char code number_7[];
unsigned char code number_8[];
unsigned char code number_9[];
unsigned char code Company_Profile[]; /*-- 文字: 公司简介 --*/
unsigned char code Information[]; /*-- 文字: 信息查询 --*/
unsigned char code parameters[]; /*-- 文字: 参数设置 --*/
unsigned char code Contact[]; /*-- 文字: 联系方式 --*/
unsigned char code Symbol[]; /*-- 文字: : --*/
unsigned char code DATE[];
unsigned char code TIME[];
void Delay(unsigned int MS);
void wtcom(void);
void time_display(void)
{
if(timer0_tick==60)
{
timer0_tick=0;
count_min_1+=1;
if(count_min_1==10)
{
count_min_1=0;
count_min_2+=1;
if(count_min_2==6)
{
count_min_2=0;
count_hour_1+=1;
if(count_hour_1==10)
{
count_hour_1=0;
count_hour_2+=1;
if(count_hour_2==2)count_hour_2=0;
}
}
}
}
}
/***************************************************
定时器服务程序
***************************************************/
static void timer0_isr(void) interrupt 1 using 0
{
TR0=0;
TL0=(TIMER0_COUNT&0x00FF);
TH0=(TIMER0_COUNT>>8);
TR0=1;
timer0_tick++;
}
/***************************************************
定时器初始化程序
***************************************************/
static void timer0_initialize(void)
{
EA=0;
timer0_tick=0;
TR0=0;
TMOD=0x01;
TL0=(TIMER0_COUNT&0x00FF);
TH0=(TIMER0_COUNT >> 8);
PT0=0;
ET0=1;
TR0=1;
EA=1;
}
/***************************/
/*检查Busy */
/***************************/
void BusyL(void)
{
CS1= 0;
CS2= 0;
wtcom();
}
void BusyM(void)
{
CS1= 0;
CS2= 1;
wtcom();
}
void BusyR(void)
{
CS1= 1;
CS2= 0;
wtcom();
}
void wtcom(void)
{
RS = 0; //指令
RW = 1;
P0 = 0xFF; //输出0xff以便读取正确
E = 1;
_nop_();
while(P0&0x80); //Status Read Bit7 = BUSY
E = 0;
_nop_();
}
/********************************************************/
/*根据设定的坐标数据,定位LCM上的下一个操作单元位置 */
/********************************************************/
void Locatexy(void)
{
unsigned char x,y;
switch (Col&0xc0) /* col.and.0xC0 */
{ /*条件分支执行 */
case 0: {BusyL();break;}/*左区 */
case 0x40: {BusyM();break;}/*中区 */
case 0x80: {BusyR();break;}/*右区 */
}
x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address 相当于x = (Col&0x3F)|0x40;*/
y = Page&0x07|0xB8; /* row.and.0x07.or.set Page */
wtcom(); /* waitting for enable */
RS = 0; //指令
RW = 0; //写
P0 = y; //设置页面地址
E = 1;
_nop_();
E = 0;
_nop_();
wtcom(); /* waitting for enable */
RS = 0;
RW = 0;
P0 = x; //设置列地址
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*写指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
BusyL();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandM( unsigned char CommandByte )
{
BusyM();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
void WriteCommandR( unsigned char CommandByte )
{
BusyR();
P0 = CommandByte;
RS = 0; //指令
RW = 0;
E = 1;
_nop_();
E = 0;
_nop_();
}
/***************************/
/*读数据 */
/***************************/
unsigned char ReadData( void )
{
unsigned char DataByte;
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
RS = 1; /*数据输出*/
RW = 1; /*读入 */
P0 = 0xFF; //输出0xff以便读取正确
E = 1; /*读入到LCM*/
_nop_();
DataByte = P0; /*数据读出到数据口P1 */
E = 0;
_nop_();
return DataByte;
}
/***************************/
/*写数据 */
/***************************/
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
RS = 1; /*数据输出*/
RW = 0; /*写输出 */
P0 = DataByte; /*数据输出到数据口 */
E = 1; /*写入到LCM*/
_nop_();
E = 0;
_nop_();
}
void LcmClear(unsigned char a,unsigned char b,unsigned char c,unsigned char d)
{
Page = 0;
Col = 0;
for(Page=a;Page<b;Page++)
for(Col=c;Col<d;Col++)
WriteData(0);
}
void LcmInit( void )
{
WriteCommandL(0x3f); //开显示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
WriteCommandL(0xc0); //设置起始地址=0
WriteCommandM(0xc0);
WriteCommandR(0xc0);
WriteCommandL(0x3f); //开显示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
LcmClear(0,8,0,192);
Col = 0;
Page= 0;
Locatexy();
}
void LcmPutDots( unsigned char a,unsigned char b,unsigned char c,unsigned char d,unsigned char DotByte )
{
Page = 0;
Col = 0;
for(Page=a;Page<b;Page++)
{
for(Col=c;Col<d;Col++)
{
WriteData( DotByte );
}
}
}
void LcmPutBMP(unsigned char a,unsigned char b,unsigned char c,unsigned char d,unsigned char *puts )
{
unsigned int X=0;
Page = 0;
Col = 0;
for(Page=a;Page<b;Page++)
{
for(Col=c;Col<d;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
/*void date(void)
{
LcmPutBMP(0,2,42,50,number_0); //0
LcmPutBMP(0,2,50,58,number_8); //8年
LcmPutBMP(0,2,62,70,number_0); //(0-1)月
LcmPutBMP(0,2,70,78,number_5); //(0-9)月
LcmPutBMP(0,2,82,90,number_2); //0-3日
LcmPutBMP(0,2,90,98,number_6); //0-9日
}*/
void Delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0)
{
usn = 2; //for 12M
while(usn!=0)
{
us=0xf6;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
void key_scan(void)
{
if(KEY_YES==0){Delay(100);if(KEY_YES==0){KEY=1;}}
if(KEY_UP==0){Delay(100);if(KEY_UP==0){KEY=2;a+=1;if(a==5)a=1;}}
if(KEY_DOWN==0){Delay(100);if(KEY_DOWN==0){KEY=3;a-=1;if(a==0)a=4;}}
if(KEY_NO==0){Delay(100);if(KEY_NO==0){KEY=4;}}
}
void main_menu(void)
{ KEY=0;
for(;;)
{
LcmPutBMP(0,2,2,34,DATE);
LcmPutBMP(0,2,34,42,Symbol);
LcmPutBMP(0,2,106,138,TIME);
LcmPutBMP(0,2,138,146,Symbol);
LcmPutBMP(2,4,2,66,Company_Profile);
LcmPutBMP(2,4,66,74,Symbol);
LcmPutBMP(2,4,100,164,Contact);
LcmPutBMP(2,4,164,172,Symbol);
LcmPutBMP(4,6,2,66,Information);
Lcm
评论0