新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 基于C8051F的AD UART0 KEY FLASH TIME3程序

基于C8051F的AD UART0 KEY FLASH TIME3程序

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
//**********************************************
//按鍵處理程序
//**********************************************
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]++;
if(keybuffer[3]>23) //時設(shè)置,不超過24
{
keybuffer[3] = 0;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset =2;
keybuffer[3]--;
if(keybuffer[3]<=0) //小于1,顯示23
{
keybuffer[3] = 23;
}
}
}
if(Tset < 4)
{
TH = keybuffer[3]/10;
TL = keybuffer[3]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (0,1,0x85,1,0x20,0x20);
}
}break;
case 5:
{
TH = keybuffer[3]/10;
TL = keybuffer[3]%10;
number_disp (0,1,0x85,1,TAB[TH],TAB[TL]);
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset =2;
keybuffer[4]++;
if(keybuffer[4]>59) //分設(shè)置,不超過59
{
keybuffer[4] = 0;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset =2;
keybuffer[4]--;
if(keybuffer[4]<=0) //小于1,顯示59
{
keybuffer[4] = 59;
}
}
}
if(Tset < 4)
{
TH = keybuffer[4]/10;
TL = keybuffer[4]%10;
number_disp (0,1,0x87,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (0,1,0x87,1,0x20,0x20);
}
}break;
case 6:
{
TH = keybuffer[4]/10;
TL = keybuffer[4]%10;
number_disp (0,1,0x87,1,TAB[TH],TAB[TL]);
if(!(P4&0x40)) //SW2按下嗎?下翻
{
delayms(200);
if(!(P4&0x40))
{
BGset = 2;
keybuffer[5]++;
if(keybuffer[5]>59) //時設(shè)置,不超過24
{
keybuffer[5] = 0;
}
}
}
if(!(P4&0x20)) //SW3按下嗎?上翻
{
delayms(200);
if(!(P4&0x20))
{
BGset = 2;
keybuffer[5]--;
if(keybuffer[5]<=0) //小于1,顯示23
{
keybuffer[5] = 59;
}
}
}
if(Tset < 4)
{
TH = keybuffer[5]/10;
TL = keybuffer[5]%10;
number_disp (0,1,0x89,1,TAB[TH],TAB[TL]);
}
if(Tset>4)
{
number_disp (0,1,0x89,1,0x20,0x20);
}
}break;
default:break;
}
if(!(Mkey&0x02)) //SW7按下嗎?確認ENT 只在6畫面設(shè)定時間
{
delayms(200);
if(!(Mkey&0x02))
{
BGset =2;
for(i=0;i<6;i++)
{
time_buf1[i+1] = keybuffer[i];
}
Ds1302_Write_Time(); //寫DS1302
set = 0;
Page = 1; //退出到1畫面
}
}

關(guān)鍵詞: C8051FADUART0TIME

評論


技術(shù)專區(qū)

關(guān)閉