📄 display.c
字号:
//-----------------
//change value that display in lcd
//-----------------
#include <string.h>
#include <ABSACC.H>
#include <stdio.h>
#include <INTRINS.h>
#include <stdlib.h>
#include <AT89X52.H>
#include "charger.h"
#include "lcdp.h"
//--------------------------------------------------------------------
//keyboard
static unsigned char idata pos=0,len=0;
static unsigned int idata pushlen=0,uplen=0;
unsigned int bdata tlong=0,t50ms=0;
static unsigned char bdata kstate=0,mstate=0;
sbit waitover=kstate^0;
sbit change=kstate^1;
sbit key=kstate^2;
sbit kflag=kstate^3;//key buffer enmpty while kflag=0
//menu
static unsigned char idata no;
sbit mfirst=mstate^0;
sbit madin=mstate^1;
sbit mhis=mstate^2;
sbit msel=mstate^3;//select date
sbit mset=mstate^4;
//
static unsigned char idata dstr[21];
static unsigned char idata str[10];
static void itoa(unsigned i,unsigned int ad);
static void keyrst(void);
//
//--------------------------------------
//change lcd display number
static void onchange(unsigned char *chs)
{
len=strlen(chs)-1;
//restet cursor in second line
if(kflag)
{
if(key)//over 2s islong push,0x39='9'
{
if(chs[pos]>0x39||chs[pos]<0x30)//long push at no number position
{
keyrst();
return;
}
change=!change;
if(change)WC_LCD(SCR_TTT);
else WC_LCD(SCR_TTF); //change cursor state
delay(1000);
}
else //short push
{
if(change)
{
if(chs[pos]<0x39)chs[pos]++;
else chs[pos]=0x30;//'0'
if(pos&1)
{
WD_LCD(chs[pos-1]);
WD_LCD(chs[pos]);
WC_LCD(SCR_ACL);
}//acc add 1 while write two time
else
{
WD_LCD(chs[pos]);
WD_LCD(chs[pos+1]);
WC_LCD(SCR_ACL);
}
}
else
if(pos<len)
{
if(pos&1)WC_LCD(SCR_ACR);
pos++;
WC_LCD(SCR_TTF);
}
else
{
pos=0;
WC_LCD(0x90);
}
}
kflag=0;
}
}
//
//----------------------------
//key state and buffer reset
static void keyrst(void)
{
EX1=1;
EX0=1;
ET0=0;
TR0=0;
kstate=0;
mstate=0;
pos=0;
no=0;
waitover=0;
WC_LCD(SCR_TFF);
WC_LCD(0x90);
clear();
}
/*
Using to read input key
Configure Timer 0
- Mode = 2
- Interrupt = ENABLED
- Clock Source = INTERNAL
- Enable Gating Control = DISABLED
*/
//-----------------------------------------
//int0,t0,int1,t1,ser;int0 to 12887,int1 to key
void keyint(void)interrupt IE1_VECTOR //start key operation
{
EX0=0;//close 12887 second interrupt
EX1=0;//close externd keyint
//init_timer0();//enable readkey
TMOD &= 0XF0;
TMOD |= 0X1; //mode 1 max is 65.536ms on 12M
TL0 = 0X58; //on 6M,100ms(3CB0);
TH0 = 0X9E; //on 6M,50ms(9E58);
ET0 = 1; //on 6M,50ms(D8F0);
TF0 = 0;
TR0 = 1;
//display a/d input
madin=1;
}
//---------------------------------------------
//timer0 interrupt,scan key input
void readkey(void) interrupt TF0_VECTOR
{
//Timer reload
TR0=0;
TL0 = 0X58; //on 6M,100ms(3CB0);
TH0 = 0X9E; //on 6M,50ms(9E58);
TR0=1;
//Timer counter
if(((t50ms++)%20)==0)tlong++;
if(!kflag)
{
if(P3_3)
{
uplen++;
if(pushlen>1)
{
key=0;
kflag=1;
uplen=0;
}
else if(uplen>400)
{
waitover=1;
}
pushlen=0;
}
else
{
pushlen++;
uplen=0;
if(pushlen>40)
{
key=1;
kflag=1;
pushlen=0;
}
}
}
}
//
//----------------------------------------------
#define xdcdy adinhz[8]
#define lllssj adinhz[9]
//-------------------------------------------------
//general after second interrupt
//display battery volatage and timer
static void firstscr(void)
{
// if(_testbit_(mfirst))
// {
itoa(0,adin[8]);
strcpy(dstr,xdcdy);
strcat(dstr,str);
text(0x80,dstr);
itoa(4,0);
text(0x90,dstr);
// }
}
//----------------------------------------------
//int0,12887 second interrupt,display date and time,
//display volatage of storage battery
void int0second(void) interrupt IE0_VECTOR
{
/*
str[0]=P128879;
str[1]=P128878;
str[2]=P128877;
str[3]=P128874;
str[4]=P128872;
str[5]=P128870;
str[6]=P128876;
str[0]=P12887c;
today.date[0]=str[0];
today.date[1]=str[1];
today.date[2]=str[2];
tlong++;
mfirst=1;
*/
}
//
//-----------------------------------------------------------
//change unsigned int to ascii,add unit,change to date format
static void itoa(unsigned data i,unsigned int data ad)
{
unsigned char data t;
unsigned char data k;
dstr[0]='\0';
if(i<4)
{//change int to string
t=ad%0xA;
ad /=0xA;
sprintf(str,"%u.%bu\0",ad,t);
if(i==3)
{
k=strlen(str);
if(k&1)
{
str[k++]=0x20;
str[k]='\0';
}
};
strcat(str,unit[i]);
}
else
{//change to timer format string
sprintf(dstr,"%b02u/%b02u/%b02u \0",str[0],str[1],str[2]);
if(i==4)
{
sprintf(&dstr[9],"%b02u:%b02u:%b02u\0",str[3],str[4],str[5]);
}
}
}
//
//--------------------------------------------------------------------
//menu control
// first, current, history, set
//--------------------------------------------------------------------
//
//
static link pdate=&today;
void displayadin(void) //current
{
if(madin)
if(kflag)
{
//--------------------------------------------------
clear();
if(key)//long push
{
if(no<8)//8 way a/d input
{//enable mset
mstate=0;
kstate=0;
mset=1;
no=0;
}
else msel=1;//enable msel
if(msel)
{
pdate=pdate->next;
mstate=0;
kstate=0;
mhis=1;
};
delay(2000);
}
else//short push
{
if(no<8)//8 way a/d input
{ //0 2 4 6
secondline:
itoa(uadin[no],adin[no]);
strcpy(dstr,adinhz[no]);
strcat(dstr,str);
if(no&1){text(0x90,dstr);no++;}
else {text(0x80,dstr);no++;goto secondline;}
}
else
{
no=0;
text(0x80,lllssj);
str[0]=pdate->date[0];
str[1]=pdate->date[1];
str[2]=pdate->date[2];
itoa(5,0);
text(0x90,dstr);
if(msel)
{
if(pdate->up)pdate=pdate->up;
else pdate=&today;
}
}
}
//--------------------------------------------------
kflag=0;
}
}
//
//-----------------------------------------------------
static void init_int(void) //init interrupt register
{
TCON=0;
IE=0xFF; //int1 and serial,int0 interrupt enable
EX0=0;
IP=0;
ET0=0;
ET1=0; //time1,0 disable
IT0=0;
IT1=0;
}
//
//---------------------------------
//fill interrupt entry
void time1_int(void)interrupt TF1_VECTOR
{
}
//
void serial_int(void)interrupt SIO_VECTOR
{
}
//
void ex2_int(void)interrupt EX2_VECTOR //TF2_VECTOR
{
}
//
//----------------
//main program
////--------------
static unsigned char month_is(unsigned char *s)
{
unsigned char data i;
code char *m[]={"Ja","Fe","Ma","Ap","Ma","Ju","Jn","Au","Se","Oc","No","De"};
for(i=0;;i++)if((m[i][0]==s[0])&&(m[i][1]==s[1]))return i+1;
}
static void now_is(unsigned char *s)
{
unsigned char st[3];
code unsigned char *t[]={__DATE__,__TIME__};
st[0]=0;
s[5]=month_is(t[0]);
st[2]='\0';
st[0]=t[0][4];
st[1]=t[0][5];
s[4]=atoi(st);
st[0]=t[0][9];
st[1]=t[0][10];
s[6]=atoi(st);
st[0]=t[1][0];
st[1]=t[1][1];
s[2]=atoi(st);
st[0]=t[1][3];
st[1]=t[1][4];
s[1]=atoi(st);
st[0]=t[1][6];
st[1]=t[1][7];
s[0]=atoi(st);
}
//-----------------------
//init today tmp_data
static void init_today(void)
{
unsigned char data i;
getadin();
for(i=0;i<9;i++)
{
today.work[2*i]=adin[i];
}
}
//---------------------
//hardware reset flag
static unsigned char data reset_id;
static void init(void)
{
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
P2_7=0;
delay(1000);
WC_LCD(SET8B);
WC_LCD(SCR_TFF);
//init_system_work_point();
//init_today();
now_is(str);
setup12887(str);
start12887();
reset_id=0xAA;
init_int();
}
//--------------
void main(void)
{
delay(1000);
if(reset_id!=0xAA)init();
while(1)
{
RESET_DOG;
if(waitover)keyrst();
//getadin();
//control();
//account();
//displayadin();
//save();
if(mstate==0)if(!P3_2)
{
read12887(str);
//today.date[0]=str[0];
//today.date[1]=str[1];
//today.date[2]=str[2];
firstscr();
tlong++;//account using it
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -