基于C8051F的AD UART0 KEY FLASH TIME3程序
//**********************************************
//按鍵處理程序
//**********************************************
void key_scan()
{
static uchar i,k;
uchar Mkey=P4;
if(BGset<2)
{
if((Mkey&0xFE)!= 0XFE) //有鍵按下先開啟背光
{
delayms(200);
if((Mkey&0xFE)!= 0XFE)
{
BGset++;
if(BGset>1)
{
BGset = 2;
}
}
}
}
if(BGset ==2 )
{
if(!(Mkey&0x80)) //SW1按下嗎?ALM
{
delayms(200); //消抖
if(!(Mkey&0x80)) //再判斷
{
BGset =2; //開背光
if(k<1) {Page = 0;} //頁面0:顯示故障狀態(tài)}
k++;
if(k>1) {k =0;Page = 1; } //再按后退出
set = 0;
}
}
if(!set)
{
if(!(Mkey&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(Mkey&0x40))
{
if(Page !=0)
{
Page++;
BGset =2;
if(Page>6) //如果超過5界面回到1畫面
{
Page = 1;
}
}
}
}
if(!(Mkey&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(Mkey&0x20))
{
if(Page !=0)
{
Page--;
BGset =2;
if(Page<1) //小于1畫面后不顯示0畫面,顯示6畫面
{
Page = 6;
}
}
}
}
}
if(Page ==6) //修改時間界面
{
if(!(Mkey&0x04)) //SW6按下嗎?設(shè)定SET只在6畫面設(shè)置時間
{
delayms(200);
if(!(Mkey&0x04))
{
BGset =2;
set = 1; //如果按下SET鍵表示開始設(shè)置時間,置設(shè)置標志位;
}
}
if(set)
{
if(!(Mkey&0x10)) //SW4按下嗎?左移<- 只在6畫面修改時間
{
delayms(200);
if(!(Mkey&0x10))
{
BGset =2;
direction--;
if(direction < 1)
{
direction = 6;
}
}
}
if(!(Mkey&0x08)) //SW5按下嗎?右移->只在6畫面修改時間
{
delayms(200);
if(!(Mkey&0x08))
{
BGset =2;
direction++;
if(direction > 6)
{
direction = 1;
}
}
}
switch(direction)
{
case 1:
{
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset =2;
keybuffer[0]++;
if(keybuffer[0]>99) //年設(shè)置,不超過100年
{
keybuffer[0] = 11;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset =2;
keybuffer[0]--;
if(keybuffer[0]<11) //小于1畫面后不顯示0畫面,顯示6畫面
{
keybuffer[0] = 11;
}
}
}
if(Tset < 4)
{
TH = keybuffer[0]/10;
TL = keybuffer[0]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (1,0,0x91,1,0x20,0x20);
}
}break;
case 2:
{
TH = keybuffer[0]/10;
TL = keybuffer[0]%10;
number_disp (1,0,0x91,1,TAB[TH],TAB[TL]);
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset =2;
keybuffer[1]++;
if(keybuffer[1]>12) //月設(shè)置,不超過12月
{
keybuffer[1] = 1;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset =2;
keybuffer[1]--;
if(keybuffer[1]<1) //小于1 顯示12月
{
keybuffer[1] = 12;
}
}
}
if(Tset < 4)
{
TH = keybuffer[1]/10;
TL = keybuffer[1]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (1,0,0x93,1,0x20,0x20);
}
}break;
case 3:
{
TH = keybuffer[1]/10;
TL = keybuffer[1]%10;
number_disp (1,0,0x93,1,TAB[TH],TAB[TL]);
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset =2;
keybuffer[2]++;
if(keybuffer[2]>31) //日設(shè)置,不超過31日
{
keybuffer[2] = 1;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset =2;
keybuffer[2]--;
if(keybuffer[2]<1) //小于1,顯示31日
{
keybuffer[2] = 31;
}
}
}
if(Tset<4)
{
TH = keybuffer[2]/10;
TL = keybuffer[2]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (1,0,0x95,1,0x20,0x20);
}
}break;
case 4:
{
TH = keybuffer[2]/10;
TL = keybuffer[2]%10;
number_disp (1,0,0x95,1,TAB[TH],TAB[TL]);
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset =2;
keybuffer[3]++;