📄 main_lsd.c
字号:
{
if((c<<count)&0x80) SDA=1;
else SDA=0;
NOP();
SCL=1;
NOP();
NOP();
NOP();
NOP();
NOP();
SCL=0;
}
NOP();
NOP();
SDA=1; /*begin to check the ack signal*/
NOP();
NOP();
SCL=1;
NOP();
NOP();
NOP();
if(SDA==1) ACK=0;
else ACK=1;
SCL=0;
NOP();
NOP();
}
/*************************************************/
/**** receive byte from the i2c device *****/
uchar RdByte()
{
uchar c;
uchar count;
c=0;
SDA=1;
for(count=0;count<8;count++)
{
NOP();
SCL=0;
NOP();
NOP();
NOP();
NOP();
NOP();
SCL=1;
NOP();
NOP();
c=c<<1;
if(SDA==1) c=c+1;
SCL=0;
NOP();
NOP();
}
SCL=0;
NOP();
NOP();
return(c);
}
/*************************************************/
/***** write string to the i2c device *****/
bit WrStr(uchar WrAddr,uchar sub_addr,uchar Data )
{
Start_i2c();
WrByte(WrAddr);//write device address
if(ACK==0) return(0);//not ACKed
WrByte(sub_addr);//write regiset address
if(ACK==0) return(0);
WrByte(Data);//write data
if(ACK==0) return(0);
Stop_i2c();
return(1);
}
/*************************************************/
/**** read string from the i2c device *******/
uchar RdStr(uchar WrAddr,uchar sub_addr)
{
uchar Data;
Start_i2c();
WrByte(WrAddr);
if(ACK==0) return(0);
WrByte(sub_addr);
if(ACK==0) return(0);
Start_i2c();
WrByte(WrAddr+1);
if(ACK==0) return(0);
Data=RdByte();
/*flag ack signal*/
MACK(1);
Stop_i2c();
return(Data);
}
/****************************************************/
//** the end of the sub functions of I2c */
/****************************************************/
/********************************************************
The function about x5045
*********************************************************/
/***************** read data *****************/
uchar Read8()
{
bit bData;
uchar count;
uchar Data;
for(count=0;count<8;count++)
{
SCK=1;
SCK=0;
bData=SDO;
Data<<=1;
if(bData) Data+=1;
}
return Data;
}
/****************************************************/
/***************** write data *****************/
void Write8(uchar Data)
{
uchar count;
for(count=0;count<8;count++)
{
if((Data&0x80)==0)
{ SDI=0;}
else
{ SDI=1;}
SCK=0;
SCK=1;
Data<<=1;
}
}
/****************************************************/
/***************************************************/
uchar ReadSR()
{
uchar Data;
CS=0;
Write8(RDSR);
Data=Read8();
CS=1;
return Data;
}
/****************************************************/
/****************************************************/
void WriteSR(uchar Data)
{
CS=0;
Write8(WREN);
CS=1;
CS=0;
Write8(WRSR);
Write8(Data);
CS=1;
}
/****************************************************/
/****************************************************/
void WriteByte(uchar Data,uchar address)
{
while((ReadSR()&0x01)==1);
CS=0;
Write8(WREN);
CS=1;
CS=0;
Write8(WRITE0);
Write8(address);
Write8(Data);
SCK=0;
CS=1;
}
/****************************************************/
/****************************************************/
uchar ReadByte(uchar address)
{
uchar Data;
while((ReadSR()&0x01)==1);
CS=0;
Write8(READ0);
Write8(address);
Data=Read8();
CS=1;
return Data;
}
/******************** key *****************************/
/*********************************************************************************
The module of KeyboradScan()
**********************************************************************************/
uchar KeyboradScan( )
{
uchar i,scode;//scode为中间变量
com8155 = 0x02;
pb8155 = 0x00;
if( key_busy == 0 )
{
delay( 10 );//延时20ms消抖动
if ( key_busy == 0 )
{
scode=0xFE;//逐列扫描
for ( i=0;i<8;i++ )
{
pb8155=scode;
if(key_busy==0)
{
if ( IndexForCom8155 & 0x10 == 0 )
return ( i + 8 );
else
return ( i + 1 );
}
else
scode = ( scode <<1 ) | 0x01;//列扫描码左移
}
}
}
return ( 0 );
}
/*******************************************************/
/*******************************************************
the module of display the last off time /
*********************************************************/
void DisplayOffTime( )
{
uchar a,b;
LCOMM=0x3F;//turn on the left LCD
LCOMM=0xC0;//display the top of LCD
LCOMM=0x40;//
RCOMM=0x3F;//turn on the right LCD
RCOMM=0xC0;//display the top of LCD
RCOMM=0x40;//
//The follow program display the last off time
for ( a = 0; a < 4; a++ ) // clear the LCD screen
{
for ( b = 0; b < 4; b++ )
{
display( 0x09,16,(0xB8+2*a),(0x40+b*16),0 );
display( 0x09,16,(0xB8+2*a),(0x40+b*16),1 );
}
}
while(KeyboradScan()==0) //display the last off time
{
WriteSR(0x30);
year=ReadByte(0x00);
month=ReadByte(0x01);
day=ReadByte(0x02);
hour=ReadByte(0x03);
minute=ReadByte(0x04);
second=ReadByte(0x05);
date=ReadByte(0x06);
year1=(year>>4)&0x0f;
year0=year&0x0f;
month1=(month>>4)&0x01;
month0=month&0x0f;
day1=(day>>4)&0x03;
day0=day&0x0f;
hour1=(hour>>4)&0x03;
hour0=hour&0x0f;
minute1=(minute>>4)&0x07;
minute0=minute&0x0f;
second1=(second>>4)&0x07;
second0=second&0x0f;
date0=date&0x07;
display(year1,8,0xb8,0x40,0);
display(year0,8,0xb8,0x48,0);
display(0x07,16,0xb8,0x50,0); //年
display(month1,8,0xb8,0x60,0);
display(month0,8,0xb8,0x68,0);
display(0x08,16,0xb8,0x70,0); //月
display(day1,8,0xb8,0x40,1);
display(day0,8,0xb8,0x48,1);
display(0x00,16,0xb8,0x50,1); //日
display(0x09,16,0xb8,0x60,1);
display(date0,16,0xb8,0x70,1); //weekday
display(0x14,16,0xba,0x40,0); //关
display(0x15,16,0xba,0x50,0); //机
display(0x12,16,0xba,0x60,0); //时
display(0x13,16,0xba,0x70,0); //刻
display(hour1,8,0xba,0x40,1);
display(hour0,8,0xba,0x48,1);
display(0x10,8,0xba,0x50,1);
display(minute1,8,0xba,0x58,1);
display(minute0,8,0xba,0x60,1);
display(0x10,8,0xba,0x68,1);
display(second1,8,0xba,0x70,1);
display(second0,8,0xba,0x78,1);
}
return;
}
/*****************************************************************/
/*****************************************************************
The module of SettingHandonTime function
*****************************************************************/
void SettingHandonTime( )
{
uchar Key;
year3 = year1;//get time from off time
year2 = year0;
month3 = month1;
month2 = month0;
date3 = day1;
date2 = day0;
day3 = date0;
hour3 = hour1;
hour2 = hour0;
minute3 = minute1;
minute2 = minute0;
second3 = second1;
second2 = second0;
display( year3,8,0xB8,0x40,0 );
display( year2,8,0xB8,0x48,0 );
display( 0x07,16,0xB8,0x50,0 ); //年
display( month3,8,0xB8,0x60,0 );
display( month2,8,0xB8,0x68,0 );
display( 0x08,16,0xB8,0x70,0 ); //月
display( date3,8,0xB8,0x40,1 );
display( date2,8,0xB8,0x48,1 );
display( 0x00,16,0xB8,0x50,1 ); //日
display( 0x09,16,0xB8,0x60,1 );
display( day3,16,0xB8,0x70,1 ); //星期
display(0x29,16,0xba,0x40,0); //上
display(0x30,16,0xba,0x50,0); //传
display(0x09,16,0xba,0x70,0); //空格
display( hour3,8,0xBA,0x40,1 ); //hour
display( hour2,8,0xBA,0x48,1 );
display( 0x10,8,0xBA,0x50,1 ); // :
display( minute3,8,0xBA,0x58,1 ); //minute
display( minute2,8,0xBA,0x60,1 );
display( 0x10,8,0xBA,0x68,1 ); // :
display( second3,8,0xBA,0x70,1 ); //second
display( second2,8,0xBA,0x78,1 );
delay( 20 );
while ( 1 )
{
//set year
YEAR0:
display( 0x07,16,0xBA,0x60,0 ); //年
Key = KeyboradScan();
while ( ( Key ==0 ) | ( Key > 4 ) )
{
Key = KeyboradScan();
}
delay( 10 );
if ( Key ==1 ) //add
{
if ( year2 == 9 )
{
year2 = 0;
if ( year3 == 9 )
year3 = 0;
else
year3++;
}
else
year2++;
}
else if ( Key == 2) //subtract
{
if ( year2 == 0 )
{
if ( year3 == 0 )
{
year3 = 9;
year2 = 9;
}
else
{
year3--;
year2 = 9;
}
}
else
year2--;
}
display( year3,8,0xB8,0x40,0 );
display( year2,8,0xB8,0x48,0 );
year4 = ( year3 << 4 ) | year2; //pass new year
if ( Key == 4 )
break;
else if ( Key == 3 )
goto MONTH0;
goto YEAR0;
//set month
MONTH0:
display( 0x08,16,0xBA,0x60,0 ); //月
Key = KeyboradScan();
while ( ( Key ==0 ) | ( Key > 4 ) )
{
Key = KeyboradScan();
}
delay( 10 );
if ( Key == 1 ) // add
{
if ( month3 == 1 )
{
if ( month2 == 2 )
{
month3 = 0;
month2 = 1;
}
else
month2++;
}
else if ( month2 == 9 )
{
month3 = 1;
month2 = 0;
}
else
month2++;
}
else if ( Key == 2 ) //substract
{
if ( month3 == 0 )
{
if ( month2 == 1 )
{
month3 = 1;
month2 = 2;
}
else if ( month2 == 0 )
{
month3 = 1;
month2 = 2;
}
else
month2--;
}
else if ( month2 == 0 )
{
month3 = 0;
month2 = 9;
}
else
month2--;
}
display( month3,8,0xB8,0x60,0 );
display( month2,8,0xB8,0x68,0 );
month4 = ( month3 << 4 ) | month2; //pass new month
if ( Key == 4 )
break;
else if ( Key == 3 )
goto DATE0;
goto MONTH0;
//set date
DATE0:
display( 0x00,16,0xBA,0x60,0 ); //日
Key = KeyboradScan();
while ( ( Key ==0 ) | ( Key > 4 ) )
{
Key = KeyboradScan();
}
delay( 10 );
if ( Key == 1 ) // add
{
if ( date3 == 3 )
{
if ( date2 == 1 )
{
date3 = 0;
date2 = 1;
}
else
date2++;
}
else if ( date2 == 9 )
{
date2 = 0;
date3++;
}
else
date2++;
}
else if ( Key == 2 ) //substract
{
if ( date3 == 0 )
{
if ( date2 == 1 )
{
date3 = 3;
date2 = 1;
}
else if ( date2 == 0 )
{
date3 = 3;
date2 = 1;
}
else
date2--;
}
else if ( date2 == 0 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -