📄 main.c
字号:
if(LCD_StatusCheck(LCD_CC)==0)return(0);
for(i=0;i<240*8;i++)
{
dat = pgm_read_byte(p++);
if(LCD_AutoWriteData(dat)==0)
{
i = LCD_INIT();
return(0);
}
}
if(LCD_WriteCommand(LCD_AUT_OVR)==0)
{
i =LCD_INIT();
return(0);
}
return(-1);
}
char LCD_PutChar(unsigned char page,unsigned int position,const unsigned char *hz)
{
unsigned char i = 0,k = 0;
unsigned char dat = 0;
unsigned char x = 0,y = 0;
x = position % 256;
y = position / 256;
position = y * 240;
position += x;// * 2;
position += page * 0XF00;
for(k=0;k<16;k++)
{
position += 30;
x = position %256;
y = position / 256;
if(LCD_WriteData(x)==0)return(0);
if(LCD_WriteData(y)==0)return(0);
if(LCD_WriteCommand(LCD_ADD_POS)==0)return(0);
for(i=0;i<2;i++)
{
dat = pgm_read_byte(hz++);
if(LCD_WriteData(dat)==0)return(0);
if(LCD_WriteCommand(LCD_INC_WR)==0)return(0);
}
}
return(-1);
}
////////////////////////////////////////////////
///////////////////////////////////////////////
char LCD_PutEng(unsigned char page,unsigned int position,const unsigned char *eng)
{
unsigned char i = 0;
unsigned char dat = 0;
unsigned char x = 0,y = 0;
x = position % 256;
y = position / 256;
position = y * 240;
position += x;// * 2;
position += page * 0XF00;
for(i=0;i<16;i++)
{
position += 30;
x = position % 256;
y = position / 256;
if(LCD_WriteData(x)==0)return(0);
if(LCD_WriteData(y)==0)return(0);
if(LCD_WriteCommand(LCD_ADD_POS)==0)return(0);
dat = pgm_read_byte(eng++);
if(LCD_WriteData(dat)==0)return(0);
if(LCD_WriteCommand(LCD_INC_WR)==0)return(0);
}
return(-1);
}
char LCD_PutAnyThing(unsigned char page,unsigned int position,unsigned char dat)
{
position += page * 0XF00;
if(LCD_WriteData(position%256)==0)return(0);
if(LCD_WriteData(position/256)==0)return(0);
if(LCD_WriteCommand(LCD_ADD_POS)==0)return(0);
if(LCD_WriteData(dat)==0)return(0);
if(LCD_WriteCommand(LCD_NOC_WR)==0)return(0);
return(-1);
}
char LCD_Case(unsigned char page)
{
unsigned int i=0;
unsigned char x=0;
for(i=0;i<60;i++)
{
if(LCD_PutAnyThing(page,0x0000+i,0xff)==0)return(0);
}
for(i=3740;i<3840;i++)
{
if(LCD_PutAnyThing(page,0x0000+i,0xff)==0)return(0);
}
i = 30;
for(x=2;x<124;x++)
{
i += 30;
if(LCD_PutAnyThing(page,i,0xc0)==0)return(0);
if(LCD_PutAnyThing(page,i+29,0x03)==0)return(0);
}
return(-1);
}
void vLCD_Page_Change(unsigned char page)
{
unsigned int pos = 0;
unsigned null = 0;
pos = page*0xF00;
null = LCD_WriteData(pos%256);
null = LCD_WriteData(pos/256);
null = LCD_WriteCommand(LCD_GRH_STP);
CPage = page;
}
void LCD_page0(void)
{
char null = 0;
unsigned char i = 0;
unsigned char page = 0;
const unsigned char *p = name;
null = LCD_FILL(page,00);
for(i=2;i<28;i+=2)
{
null = LCD_PutChar(page,0x0200+i,p);
p += 32;
}
p = web;
for(i=4;i<26;i++)
{
null = LCD_PutEng(page,0x0600+i,p);
p += 16;
}
p = phone;
null = LCD_PutChar(page,0x0902,p);
p += 32;
null = LCD_PutChar(page,0x0904,p);
p = pnum;
for(i=6;i<28;i++)
{
null = LCD_PutEng(page,0x0900+i,p);
p += 16;
}
null = LCD_Case(page);
}
void LCD_page1(void)//显示背景
{
volatile unsigned char null = 0;
unsigned char page = 1;
const unsigned char *p = ctrl;
page = 1;
if(m_page==0)
{
null = LCD_FILL(page,0);
null = LCD_Case(page);
}
p = web;
null = LCD_PutEng(page,0x0105,p+4*16);//:
null = LCD_PutEng(page,0x0305,p+4*16);//:
null = LCD_PutEng(page,0x0505,p+4*16);//:
null = LCD_PutEng(page,0x0111,p+4*16);//:
null = LCD_PutEng(page,0x0311,p+4*16);//:
null = LCD_PutEng(page,0x0511,p+4*16);//:
null = LCD_PutEng(page,0x070a,p+4*16);//:
null = LCD_PutEng(page,0x090A,p+4*16);//:
null = LCD_PutEng(page,0x030b,p+22*16);//V
null = LCD_PutEng(page,0x050b,p+23*16);//A
null = LCD_PutEng(page,0x0516,p+23*16);//Ah-A
null = LCD_PutEng(page,0x0517,p+0*16);//Ah-h
p =english;
//null = LCD_PutEng(page,0x0b04,p+0*16);//F1_F
//null = LCD_PutEng(page,0x0b0f,p+0*16);//F2_F
p = nen;
// null = LCD_PutEng(page,0x0b05,p+1*16);//1
// null = LCD_PutEng(page,0x0b10,p+2*16);//2
p = ctrl;
null = LCD_PutChar(page,0x0101,p+6*32);//状
null = LCD_PutChar(page,0x0103,p+7*32);//态
null = LCD_PutChar(page,0x0301,p+18*32);//电
null = LCD_PutChar(page,0x0303,p+19*32);//压
null = LCD_PutChar(page,0x0501,p+20*32);//电
null = LCD_PutChar(page,0x0503,p+21*32);//流
null = LCD_PutChar(page,0x0701,p+49*32);//当
null = LCD_PutChar(page,0x0703,p+50*32);//前
null = LCD_PutChar(page,0x0705,p+51*32);//步
null = LCD_PutChar(page,0x070e,p+51*32);//步
null = LCD_PutChar(page,0x0901,p+52*32);//循
null = LCD_PutChar(page,0x0903,p+53*32);//环
null = LCD_PutChar(page,0x0905,p+54*32);//周
null = LCD_PutChar(page,0x0907,p+55*32);//期
null = LCD_PutChar(page,0x090E,p+54*32);//周
null = LCD_PutChar(page,0x010d,p+22*32);//温
null = LCD_PutChar(page,0x010f,p+23*32);//度
null = LCD_PutChar(page,0x030d,p+24*32);//时
null = LCD_PutChar(page,0x030f,p+25*32);//间
null = LCD_PutChar(page,0x050d,p+28*32);//容
null = LCD_PutChar(page,0x050f,p+29*32);//量
// null = LCD_PutChar(page,0x0b11,p+12*32);//启
// null = LCD_PutChar(page,0x0b13,p+13*32);//动
// null = LCD_PutChar(page,0x0b06,p+14*32);//设
// null = LCD_PutChar(page,0x0b08,p+15*32);//置
null = LCD_PutChar(page,0x0116,p+34*32);//℃
null = LCD_PutChar(page,0x0316,p+35*32);//分
if(dis_fige==1)
{
vWork();
}
else
{
vStop();
}
}
void LCD_page2(void)
{
volatile unsigned char null = 0;
unsigned char page = 2;
const unsigned char *p = ctrl;
page = 2;
if(m_page==0)
{
null = LCD_FILL(page,0);
null = LCD_Case(page);
}
p = web;
null = LCD_PutEng(page,0x0105,p+4*16);//:
null = LCD_PutEng(page,0x0309,p+4*16);//:
null = LCD_PutEng(page,0x0505,p+4*16);//:
null = LCD_PutEng(page,0x0511,p+4*16);//:
null = LCD_PutEng(page,0x0705,p+4*16);//:
null = LCD_PutEng(page,0x0711,p+4*16);//:
null = LCD_PutEng(page,0x0905,p+4*16);//:
null = LCD_PutEng(page,0x050b,p+22*16);//V
null = LCD_PutEng(page,0x070b,p+23*16);//A
null = LCD_PutEng(page,0x090b,p+23*16);//Ah-A
null = LCD_PutEng(page,0x090c,p+0*16);//Ah-h
null = LCD_PutEng(page,0x0519,p+23*16);//V
null = LCD_PutEng(page,0x0719,p+21*16);//:m
p = ctrl;
null = LCD_PutChar(page,0x0101,p+6*32);//状
null = LCD_PutChar(page,0x0103,p+7*32);//态
null = LCD_PutChar(page,0x0305,p+14*32);//设
null = LCD_PutChar(page,0x0307,p+15*32);//置
null = LCD_PutChar(page,0x0301,p+6*32);//状
null = LCD_PutChar(page,0x0303,p+7*32);//态
null = LCD_PutChar(page,0x030f,p+56*32);//第
null = LCD_PutChar(page,0x0313,p+51*32);//步
null = LCD_PutChar(page,0x0501,p+46*32);//恒
null = LCD_PutChar(page,0x0503,p+19*32);//压
null = LCD_PutChar(page,0x0701,p+46*32);//恒
null = LCD_PutChar(page,0x0703,p+21*32);//流
null = LCD_PutChar(page,0x050f,p+38*32);//涓
null = LCD_PutChar(page,0x0511,p+39*32);//流
null = LCD_PutChar(page,0x070f,p+24*32);//时
null = LCD_PutChar(page,0x0711,p+25*32);//间
null = LCD_PutChar(page,0x0901,p+28*32);//容
null = LCD_PutChar(page,0x0903,p+29*32);//量
null = LCD_PutChar(page,0x090f,p+52*32);//循
null = LCD_PutChar(page,0x0911,p+53*32);//环
null = LCD_PutChar(page,0x0913,p+60*32);//到
null = LCD_PutChar(page,0x0917,p+51*32);//步
null = LCD_PutChar(page,0x0d07,p+32*32);//确
null = LCD_PutChar(page,0x0d09,p+33*32);//认
null = LCD_PutChar(page,0x0d12,p+42*32);//退
null = LCD_PutChar(page,0x0d14,p+43*32);//出
null = LCD_PutChar(page,0x0b02,p+4*32);//←
null = LCD_PutChar(page,0x0b04,p+59*32);//上
null = LCD_PutChar(page,0x0b06,p+58*32);//一
null = LCD_PutChar(page,0x0b08,p+51*32);//步
null = LCD_PutChar(page,0x0b0f,p+5*32);// →
null = LCD_PutChar(page,0x0b11,p+57*32);//下
null = LCD_PutChar(page,0x0b13,p+58*32);//一
null = LCD_PutChar(page,0x0b15,p+51*32);//步
p =english;
null = LCD_PutEng(page,0x0d04,p+1*16);//F1_F
null = LCD_PutEng(page,0x0d05,p+4*16);//F1_F
null = LCD_PutEng(page,0x0d06,p+5*16);//F1_F
null = LCD_PutEng(page,0x0d0f,p+1*16);//F2_F
null = LCD_PutEng(page,0x0d10,p+2*16);//F2_F
null = LCD_PutEng(page,0x0d11,p+3*16);//F2_F
}
/*void LCD_page3(void)
{
volatile unsigned char null = 0;
unsigned char page = 3;
const unsigned char *p = ctrl;
page = 3;
null = LCD_FILL(page,0);
null = LCD_Case(page);
}*/
void DisNum(unsigned int nm,unsigned char tp)
{
unsigned int np = 0;
unsigned char page = 10;
const unsigned char *p = nen;
switch(tp)
{
case 0://实际电压
{
nm = Voltage;
page = 1;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0306,p+np*16);//Xx.xx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0307,p+np*16);//xX.xx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0308,p+np*16);//xx.Xx
LCD_PutEng(page,0x0309,p+10*16);//xx.xx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x030a,p+np*16);//xx.xX
}
case 1://实际电流
{
nm = Current;
page = 1;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0506,p+np*16);//Xxx.x
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0507,p+np*16);//xXx.x
LCD_PutEng(page,0x0508,p+10*16);//xxx.x
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0509,p+np*16);//xxX.x
np = nm/1;
np %= 10;
LCD_PutEng(page,0x050a,p+np*16);//xxx.X
} case 2://实际温度
{
nm = Temp;
page = 1;
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0112,p+np*16);//Xx.x
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0113,p+np*16);//xX.x
LCD_PutEng(page,0x0114,p+10*16);//xx.x
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0115,p+np*16);//xx.X
}
case 3://实际时间
{
nm = Time;
page = 1;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0312,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0313,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0314,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0315,p+np*16);//xxxX
}
case 4://实际容量
{
nm = Capacitor;
page = 1;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0512,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0513,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0514,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0515,p+np*16);//xxxX
}
case 13://当前步
{
nm = N_step;
page = 1;
np = nm/100;
np %= 10;
LCD_PutEng(page,0x070b,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x070c,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x070d,p+np*16);//xxxX
}
case 14://周期
{
nm = N_cycle;
page = 1;
np = nm/100;
np %= 10;
LCD_PutEng(page,0x090b,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x090c,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x090d,p+np*16);//xxxX
}break;
case 5://恒压
{
page = 2;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0506,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0507,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0508,p+np*16);//xxXx
LCD_PutEng(page,0x0509,p+10*16);//xxx.x
np = nm/1;
np %= 10;
LCD_PutEng(page,0x050a,p+np*16);//xxxX
}break;
case 6://恒流
{
page = 2;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0706,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0707,p+np*16);//xXxx
LCD_PutEng(page,0x0708,p+10*16);//xxx.x
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0709,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x070a,p+np*16);//xxxX
}break;
case 7://涓
{
page = 2;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0514,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0515,p+np*16);//xXxx
LCD_PutEng(page,0x0516,p+10*16);//xxx.x
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0517,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0518,p+np*16);//xxxX
}break;
case 8://时间
{
page = 2;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0714,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0715,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0716,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0717,p+np*16);//xxxX
}break;
case 9://容量
{
page = 2;
np = nm/1000;
np %= 10;
LCD_PutEng(page,0x0906,p+np*16);//Xxxx
np = nm/100;
np %= 10;
LCD_PutEng(page,0x0907,p+np*16);//xXxx
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0908,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0909,p+np*16);//xxxX
}break;
case 10://步
{
page = 2;
if(XS_state[number]==5)
{
np = nm/10;
np %= 10;
LCD_PutEng(page,0x0915,p+np*16);//xxXx
np = nm/1;
np %= 10;
LCD_PutEng(page,0x0916,p+np*16);//xxxX
}
else
{
p = zero;
LCD_PutChar(page,0x0915,p);
}
}break;
default:break;
}
}
unsigned char cKeyScan(void)
{
unsigned char k = 0x00;
PORTD = 0x30;
DDRD = 0x30;
PORTC = 0x0bc;
DDRC = 0x00;
DDRD = 0x3f;
vWait(10);
if(KEYPIN4 == 0){k = 0x40;KEYDIR4 = 1;}
if(KEYPIN5 == 0){k = 0x50;KEYDIR5 = 1;}
if(KEYPIN6 == 0){k = 0x60;KEYDIR6 = 1;}
if(KEYPIN7 == 0){k = 0x70;KEYDIR7 = 1;}
if(KEYPIN8 == 0){k = 0x80;KEYDIR8 = 1;}
DDRD &= 0xf0;
vWait(10);
k |= ((~PIND)&0x0f);
KEYDIR4 = 0;
KEYDIR5 = 0;
KEYDIR6 = 0;
KEYDIR7 = 0;
KEYDIR8 = 0;
return(k);
}
unsigned char cKey(unsigned char keyval)
{
switch(keyval)
{
case 0x41:return(5);
break;
case 0x42:return(2);
break;
case 0x44:return(8);
break;
case 0x48:return(0);
break;
case 0x51:return(6);
break;
case 0x52:return(3);
break;
case 0x54:return(9);
break;
case 0x58:return(13);
break;
case 0x61:return(4);
break;
case 0x62:return(1);
break;
case 0x64:return(7);
break;
case 0x68:return(10);
break;
case 0x71:return(11);
break;
case 0x72:return(12);
break;
case 0x74:return(14);
break;
case 0x78:return(15);
break;
case 0x81:return(16);
break;
case 0x82:return(17);
break;
case 0x84:return(18);
break;
case 0x88:return(19);
break;
default:return(0x0ff);
break;
}
}
/////////////////////////////////////////////////////////////////////////
//系统函数区/////////////////////////////////////////////////////////////
void vInit(void)
{
vPortInit();
vTimer0Init();
if(MCUCSR&(1<<WDRF));//wdt rest
if(MCUCSR&(1<<BORF));//brown out
if(MCUCSR&(1<<PORF));//power on
MCUCR = 0x00;
SREG |= 0x80;
vOCR1Init();
vSpiInit();
}
void vPortInit(void)
{
PORTA = 0x0ff;
DDRA = 0x00;
PORTB = 0x0ff;
DDRB = 0x4f;
PORTC = 0x0ff;
DDRC = 0x00;
PORTD = 0x0ff;
DDRD = 0x30;
}
void vTimer0Init(void)
{
OCR0 = 249;
TCCR0 = 0x0b;
}
void vOCR1Init(void)
{
OCR1A = 0x0000;
OCR1B = 0x0000;
TCCR1A = 0x0f2;
TCCR1B = 0x19;
ICR1 = 0x03e7;
}
void vSpiInit(void)
{
SPCR = 0xce;
SPSR = 0x00;
}
/////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -