//===================================
//按鍵處理程序 按鍵為P6口
//===================================
void key_scan()
{
static uchar i;
//static uchar k;
uchar Mkey=P6;
if(BGset《2)
{
if((Mkey&0xFF)!= 0xFF) //有鍵按下先開啟背光
{
delayms(200);
if((Mkey&0xFF)!= 0xFF)
{
BGset++;
if(BGset》1)
{
BGset = 2;
}
}
}
}
if(BGset ==2 )
{
if(?。∕key&0x08)) //ESC按下嗎? P63
{
delayms(200); //消抖
if(?。∕key&0x08)) //再判斷
{
BGset =2; //開背光
//if(k《1) {Page = 0;} //頁面0:顯示版本信息狀態(tài)
//k++;
//if(k》1) {k =0;Page = 1; } //再按后退出
Page = 1;
set = 0;
}
}
if(!(Mkey&0x10)) //DATA按下嗎? P64
{
delayms(200); //消抖
if(?。∕key&0x10)) //再判斷
{
BGset =2; //開背光
//if(k《1) {Page = 0;} //頁面0:顯示版本信息狀態(tài)
//k++;
//if(k》1) {k =0;Page = 1; } //再按后退出
Page = 0;
set = 0;
}
}
if(!set)
{
if(?。∕key&0x80)) //---》按下嗎?下翻
{
delayms(200);
if(?。∕key&0x80))
{
if(Page !=0)
{
Page++;
BGset =2;
if(Page》7) //如果超過7界面回到1畫面
{
Page = 1;
}
}
}
}
if(?。∕key&0x20)) //《---按下嗎?上翻
{
delayms(200);
if(!(Mkey&0x20))
{
if(Page !=0)
{
Page--;
BGset =2;
if(Page《1) //小于1畫面后不顯示0畫面,顯示7畫面
{
Page = 7;
}
}
}
}
}
//************************************************
//設(shè)置參數(shù)
//************************************************
if(Page ==0)
{
if(?。∕key&0x02)) //SET按下嗎?設(shè)定SET在0畫面設(shè)置參數(shù)
{
delayms(200);
if(?。∕key&0x02))
{
BGset =2;
set = 1; //如果按下SET鍵表示開始設(shè)置時(shí)間,置設(shè)置標(biāo)志位;
}
}
if(set == 1)
{
if(!(Mkey&0x20)) //《- 按下嗎?左移《- 在0畫面修改參數(shù)
{
delayms(200);
if(?。∕key&0x20))
{
BGset =2;
direction1++;
if(direction1 》 14)
{
direction1 = 1; //本界面14個(gè)數(shù)字要修改
}
}
}
if(?。∕key&0x80)) //-》按下嗎?右移-》只在0畫面修改時(shí)間
{
delayms(200);
if(?。∕key&0x80))
{
BGset =2;
direction1--;
if(direction1 《 1)
{
direction1 = 14;
}
}
}
switch(direction1)
{
case 1: //第一位修改
{
//number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
number_disp (0x8f,1,TAB[SZH3],TAB[SZL3]);
number_disp (0x8e,1,TAB[SZH4],TAB[SZL4]);
number_disp (0x9f,1,TAB[SZH5],TAB[SZL5]);
number_disp (0x9e,1,TAB[SZH6],TAB[SZL6]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(?。∕key&0x01))
{
BGset =2;
SZL0++;
if(SZL0》9) //設(shè)置,不超過9
{
SZL0 = 0;
}
}
}
/*if(!(Mkey&0x10)) //-按下嗎?
{
delayms(200);
if(?。∕key&0x10))
{
BGset =2;
if(SZL0《=0) //小于1畫面后不顯示0畫面
{
SZL0 = 9;
}
SZL0--;
}
}*/
if(Tset 《 2)
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]);
}
if(Tset》2)
{
number_disp (0x97,1,TAB[SZH0],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 2://第二位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(?。∕key&0x01))
{
BGset =2;
SZH0++;
if(SZH0》9) //設(shè)置,不超過9
{
SZH0 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]);
}
if(Tset》2)
{
number_disp (0x97,1,0x20,TAB[SZL0]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 3://第三位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
if(?。∕key&0x01)) //+按下嗎?
{
delayms(200);
if(?。∕key&0x01))
{
BGset =2;
SZL1++;
if(SZL1》9) //設(shè)置,不超過9
{
SZL1 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
}
if(Tset》2)
{
number_disp (0x96,1,TAB[SZH1],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 4://第4位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(!(Mkey&0x01)) //+按下嗎?
{
delayms(200);
if(?。∕key&0x01))
{
BGset =2;
SZH1++;
if(SZH1》9) //設(shè)置,不超過9
{
SZH1 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
}
if(Tset》2)
{
number_disp (0x96,1,0x20,TAB[SZL1]); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 5://第5位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(?。∕key&0x01)) //+按下嗎?
{
delayms(200);
if(!(Mkey&0x01))
{
BGset =2;
SZL2++;
if(SZL2》9) //設(shè)置,不超過9
{
SZL2 = 0;
}
}
}
if(Tset 《 2)
{
number_disp (0x95,1,TAB[SZH2],TAB[SZL2]);
}
if(Tset》2)
{
number_disp (0x95,1,TAB[SZH2],0x20); //定時(shí)送滅狀態(tài),實(shí)現(xiàn)閃爍
}
}break;
case 6://第6位修改
{
number_disp (0x97,1,TAB[SZH0],TAB[SZL0]); //把前面的顯示了
number_disp (0x96,1,TAB[SZH1],TAB[SZL1]);
if(?。∕key&0x01)) //+按下嗎?
{
delayms(200);
if(?。∕key&0x01))
{
BGset =2;
SZH2++;
if(SZH2》9) //設(shè)置,不超過9
{
SZH2 = 0;
}
}
}
評論