国产肉体XXXX裸体137大胆,国产成人久久精品流白浆,国产乱子伦视频在线观看,无码中文字幕免费一区二区三区 国产成人手机在线-午夜国产精品无套-swag国产精品-国产毛片久久国产

新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 4×4矩陣鍵盤(pán)數(shù)碼管顯示按鍵值程序

4×4矩陣鍵盤(pán)數(shù)碼管顯示按鍵值程序

作者: 時(shí)間:2016-07-22 來(lái)源:網(wǎng)絡(luò) 收藏

  4×4顯示按鍵值程序

本文引用地址:http://m.ptau.cn/article/201607/294422.htm

  //電路說(shuō)明如下。

  //單片機(jī):使用51系列兼容的即可;

  //4×4:接在P1口;

  //兩位數(shù)碼顯示器: P0口輸出七段碼,P2口輸出位選碼。

  //==============================================================

  //C語(yǔ)言程序如下。

  /*************************************************************

  * 文件名: KEY_LED.c

  * 功能 : 對(duì)4×4進(jìn)行輸出,在后兩位顯示按鍵值。

  **************************************************************/

  #include

  #include

  #define uint unsigned int

  #define uchar unsigned char

  //uchar code table[10] = {0x03, 0x9f, 0x25, 0x0d, 0x99, 0x49, 0x41, 0x1f, 0x01, 0x09};

  uchar code table[10] = {0xC0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};

  /**************************************************************

  * 名稱(chēng) : Delay_1ms()

  * 功能 : 延時(shí)子程序,延時(shí)時(shí)間為 1ms * x

  * 輸入 : x (延時(shí)一毫秒的個(gè)數(shù))

  * 輸出 : 無(wú)

  ***************************************************************/

  void Delay_1ms(uint x)

  {

  uint i;

  uchar j;

  for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);

  }

  /**************************************************************

  * 名稱(chēng): Keyscan()

  * 功能: P1外接4×4按鍵, 按照掃描法讀出鍵值

  * 輸出: 按鍵值0~15/如無(wú)鍵按下, 返回16

  ***************************************************************/

  uchar Keyscan(void)

  {

  uchar i, j, temp, Buffer[4] = {0xef, 0xdf, 0xbf, 0x7f};

  for(j = 0; j < 4; j++) { //循環(huán)四次

  P1 = Buffer[j]; //在P1高四位分別輸出一個(gè)低電平

  temp = 0x01; //計(jì)劃先判斷P1.0位

  for(i = 0; i < 4; i++) { //循環(huán)四次

  if(!(P1 & temp)) //從P1低四位,截取1位

  return (i + j * 4); //返回取得的按鍵值

  temp <<= 1; //判斷的位,左移一位

  } }

  return 16; //判斷結(jié)束,沒(méi)有鍵按下,返回16

  } //呵呵,實(shí)質(zhì)性的語(yǔ)句不過(guò)8行,就是這么簡(jiǎn)練!

  /**************************************************************

  * 名稱(chēng): Display(uchar k)

  * 功能: 將參數(shù)分成十位、個(gè)位分別顯示

  * 輸入: k (鍵盤(pán)數(shù)值)

  * 輸出: P0口輸出七段碼,P2口輸出位選碼

  ***************************************************************/

  void Display(uchar k)

  {

  P2 = 0; //消隱

  P0 = table[k / 10];

  P2 = 0x02; Delay_1ms(5); //顯示5ms十位

  P2 = 0; //消隱

  P0 = table[k % 10];

  P2 = 0x01; Delay_1ms(5); //顯示5ms個(gè)位

  }

  /**************************************************************

  * 名稱(chēng) : Main()

  * 功能 : 主函數(shù)

  ***************************************************************/

  void Main(void)

  {

  uchar Key_Value = 16, Key_Temp1, Key_Temp2; //兩次讀出的鍵值

  while(1) {

  //---------以下讀入按鍵、消抖、等待按鍵釋放

  P1 = 0xff;

  Key_Temp1 = Keyscan(); //先讀入按鍵

  if(Key_Temp1 != 16) { //如果有鍵按下

  //Delay_1ms(10); //延時(shí)一下

  Display(Key_Value); //可用顯示代替延時(shí)

  Key_Temp2 = Keyscan(); //再讀一次按鍵

  if (Key_Temp1 == Key_Temp2) {//必須是兩次相等

  Key_Value = Key_Temp1; //才保存下來(lái),這就是消除抖動(dòng)

  while(Keyscan() < 16) //等待按鍵釋放

  Display(Key_Value); //等待期間顯示鍵值

  //---------以下是對(duì)按鍵的處理

  Display(Key_Value); //顯示鍵值

  } }

  Display(Key_Value); //沒(méi)有按鍵按下,也顯示鍵值

  }

  }

  //用PROTEUS仿真運(yùn)行時(shí)的屏幕截圖如下:



關(guān)鍵詞: 數(shù)碼管 矩陣鍵盤(pán)

評(píng)論


相關(guān)推薦

技術(shù)專(zhuān)區(qū)

關(guān)閉