?? text1
字號(hào):
/********************************************
內(nèi)部函數(shù).輸入數(shù)據(jù)
出口:B
********************************************/
void InI2C_Read()
{
unsigned char i=8;
do{
I2C_SCK=1;
ACC=B;
ACC+=ACC;
ACC0=I2C_SDA;
B=ACC;
I2C_SCK=0;
In1uSDelay();
}while(--i);
}
/********************************************
輸出數(shù)據(jù)->pcf8563
********************************************/
void I2C_WriteData(unsigned char mLocation,unsigned char mData)
{
InI2C_Start();
B=0xa2;
InI2C_Write(); /*寫命令*/
InI2C_ReadACK();
B=mLocation;
InI2C_Write(); /*寫地址*/
InI2C_ReadACK();
B=mData;
InI2C_Write(); /*寫數(shù)據(jù)*/
InI2C_ReadACK();
InI2C_Stop();
}
/********************************************
輸入數(shù)據(jù)<-pcf8563
********************************************/
unsigned char I2C_ReadData(unsigned char mLocation)
{
InI2C_Start();
B=0xa2;
InI2C_Write(); /*寫命令,設(shè)置地址*/
InI2C_ReadACK();
B=mLocation;
InI2C_Write(); /*寫地址*/
InI2C_ReadACK();
InI2C_Start();
B=0xa3;
InI2C_Write(); /*讀命令*/
_nop_();
_nop_();
InI2C_ReadACK();
_nop_();
_nop_();
InI2C_Read();
InI2C_WriteACK();
InI2C_Stop();
return(B);
}
/********************************************
天以后是取8563天以后的數(shù)據(jù)
********************************************/
void P8563_ReadDay()
{
g8563_Store[DAY]=I2C_ReadData(5)&0x3f;
g8563_Store[MONTH]=I2C_ReadData(7)&0x1f;
g8563_Store[YEAR]=I2C_ReadData(8);
}
/********************************************
內(nèi)部函數(shù),讀入時(shí)間到內(nèi)部緩沖區(qū)
********************************************/
void InP8563_Read()
{
g8563_Store[SECOND]=I2C_ReadData(2)&0x7f;
g8563_Store[MINUTE]=I2C_ReadData(3)&0x7f;
g8563_Store[HOUR]=I2C_ReadData(4)&0x3f;
P8563_ReadDay();
}
/********************************************
讀入時(shí)間到內(nèi)部緩沖區(qū)
********************************************/
void P8563_ReadTime()
{
InP8563_Read();
if(g8563_Store[0]==0){
InP8563_Read(); /*如果為秒=0,為防止時(shí)間變化,再讀一次*/
}
}
/********************************************
寫時(shí)間修改值
********************************************/
void P8563_WriteTime()
{
unsigned char i;
for(i=0;i<4;i++){
I2C_WriteData(i+2,g8563_Store[i]/*g8563_Store[i]*/);
}
for(i=4;i<6;i++){
I2C_WriteData(i+3,g8563_Store[i]/*g8563_Store[i]*/);
}
}
/********************************************
P8563的初始化,將CLOOUT設(shè)置為1HZ,檢查是否第一次啟動(dòng),是則初始化時(shí)間
********************************************/
void P8563_Init()
{
//unsigned char i;
I2C_WriteData(0xd,0x83);
// if((I2C_ReadData(0xc)&g8563_Store[3])!=0x5)
{
// for(i=0;i<6;i++)g8563_Store[i]=g8563_Store[i]; /*初始化*/
P8563_WriteTime();
I2C_WriteData(0xc,0x5);
}
}
void modifytime()
{
if(numd==0){if(tempd==0xff)numd++;}
else {g8563_Store[numd-1]=tempd;/*如果接收緩存不空,寫入緩存*/
numd++;
if(numd==7){numd=0;shizhong=1;}/*緩存字節(jié)=7*/
}
}
void F29040reset()
{XBYTE[0000]=flashreset;/*塊的任意地址寫入0XF0都會(huì)初始化塊*/
}
void selectpage() /*給出一個(gè)地址,自動(dòng)送出頁(yè)面地址,且返回頁(yè)內(nèi)偏移地址*/
{
lowaddress=(unsigned int)(address&0xFFFF);
page=(unsigned char)(address/0XFFFF);
switch(page)
{/*********選擇第一塊29F040即512B**/
case 0x0: CS512B;A18=0;A17=0;A16=0;
case 0x1: CS512B;A18=0;A17=0;A16=1;
case 0x2: CS512B;A18=0;A17=1;A16=0;
case 0x3: CS512B;A18=0;A17=1;A16=1;
case 0x4: CS512B;A18=1;A17=0;A16=0;
case 0x5: CS512B;A18=1;A17=0;A16=1;
case 0x6: CS512B;A18=1;A17=1;A16=0;
case 0x7: CS512B;A18=1;A17=1;A16=1;
/*********選擇第二塊29F040即512A**/
case 0x8: CS512A;A18=0;A17=0;A16=0;
case 0x9: CS512A;A18=0;A17=0;A16=1;
case 0xA: CS512A;A18=0;A17=1;A16=0;
case 0XB: CS512A;A18=0;A17=1;A16=1;
case 0XC: CS512A;A18=1;A17=0;A16=0;
case 0XD: CS512A;A18=1;A17=0;A16=1;
case 0XE: CS512A;A18=1;A17=1;A16=0;
case 0XF: CS512A;A18=1;A17=1;A16=1;
}
}
unsigned char F29040write(unsigned char byte)
{ unsigned char b1,b2;
unsigned char i=0;
selectpage();
XBYTE[flashaddress5555]=0xaa;
XBYTE[flashaddress2AAA]=0x55;
XBYTE[flashaddress5555]=0xa0;
XBYTE[lowaddress]=byte;
do{b1=XBYTE[lowaddress]; /*讀flash數(shù)據(jù)總線*/
b1&=0x80;
b2=byte & 0x80;
if(b1==b2) return(0); /*成功*/
b1=XBYTE[lowaddress];
b1&=0x80;
}while(b1==0); /*寫字節(jié)周期完成*/
b1=XBYTE[lowaddress]; /*讀flash數(shù)據(jù)總線*/
b1&=0x80;
b2=byte&0x80;
if(b1==b2) return(0); /*成功 */
else return(1); /*失敗*/
}
unsigned char F29040read() /*向flash讀一個(gè)字節(jié),寫入之前請(qǐng)調(diào)用F29040_reset*/
{
unsigned char ret;
F29040reset();
selectpage();
ret=XBYTE[lowaddress];
return(ret);
}//END
void dispclk()
{unsigned char i;
P8563_ReadTime();
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*年*/
tolcd[1]=22;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[5]>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*年*/
tolcd[1]=23;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[5]&0XF)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*/*/
tolcd[1]=24;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=0X0D;//g8563_Store[3];
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*月*/
tolcd[1]=25;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[4]>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*月*/
tolcd[1]=26;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[4]&0XF)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*/*/
tolcd[1]=27;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=0X0D;//g8563_Store[3];
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*日*/
tolcd[1]=28;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[3]>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*日*/
tolcd[1]=29;//20;
tolcd[2]=14;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[3]&0XF)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*時(shí)*/
tolcd[1]=22;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[2]>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*時(shí)*/
tolcd[1]=23;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[2]&0XF)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*/*/
tolcd[1]=24;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=0X1A;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*分*/
tolcd[1]=25;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[1]>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd); tolcd[0]=0xFF; /*分*/
tolcd[1]=26;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(g8563_Store[1]&0X0F)+0X10;
txtolcd=1;
TI=1;
/////////////////////////////////////
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*/*/
tolcd[1]=27;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=0X1A;
txtolcd=1;
TI=1;
i=g8563_Store[0];
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*秒*/
tolcd[1]=28;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(i>>4)+0X10;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[0]=0xFF; /*秒*/
tolcd[1]=29;//20;
tolcd[2]=15;//112;
tolcd[3]=0xFF;
tolcd[4]=(i&0X0F)+0X10;
txtolcd=1;
TI=1;
}//end if(shizhong==0)
void bendichuli()
{ unsigned char i,j,chexing2;
unsigned int xdata t_x_fee;
while(!lcdok); lcdok=0;
while(txtolcd);//本
tolcd[1]=22;
tolcd[2]=90;
tolcd[3]=0XB1;
tolcd[4]=0xBE;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);//本
tolcd[1]=24;
tolcd[2]=90;
tolcd[3]=0XB5;
tolcd[4]=0xd8;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);//本
tolcd[1]=26;
tolcd[2]=90;
tolcd[3]=0XB4;
tolcd[4]=0xa6;
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);//本
tolcd[1]=28;
tolcd[2]=90;
tolcd[3]=0Xc0;
tolcd[4]=0xEd;
txtolcd=1;
TI=1;
/////////////////////////////////////////////////////////////////
keyfinish=0;feefinish==0;
while((cheshu<(cheing+4))&(feefinish==0))
{gunping();
if(keyfinish==0){key=0;/*feefinish=0;*/}//沒(méi)有按下車型而按下回車無(wú)效
else{ chexing=key;
while(!lcdok); lcdok=0;
while(txtolcd);
tolcd[1]=10;
tolcd[2]=112;
tolcd[3]=0XA3;
tolcd[4]=chexing+0xB0;
txtolcd=1;
TI=1;
switch(chexing)
{case 0: t_x_fee=0;break;
case 1: t_x_fee=10;break;
case 2: t_x_fee=15;break;
case 3: t_x_fee=20;break;
case 4: t_x_fee=30;break;
case 5: t_x_fee=40;break;
case 6: t_x_fee=55;break;
case 7: t_x_fee=65;break;
case 8: t_x_fee=100;break;
case 9: t_x_fee=100;break;
}
if(ch_x_l_m>100)beilv=3;
else {if(ch_x_l_m>50)beilv=1;
else if(ch_x_l_m>30)beilv=0.5;
}
t_x_fee=(t_x_fee*(1+beilv));
/****************************顯示費(fèi)額********************************/
while(!lcdok); lcdok=0;
while(txtolcd);/**/
tolcd[1]=10;
tolcd[2]=90;
tolcd[3]=0xA3;
tolcd[4]=(t_x_fee/100)+0XB0;
if(tolcd[4]==0xB0){tolcd[3]=0xA2;tolcd[4]=0XA2;}
txtolcd=1;
TI=1;
while(!lcdok); lcdok=0;
while(txtolcd);/**/
tolcd[1]=12;
tolcd[2]=90;
tolcd[3]=0xA3;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -