xtest08_1.c

来自「AT91sam7s 256 B/D example」· C语言 代码 · 共 60 行

C
60
字号
/* ========================================================================== */
/*		Xtest08_1.c : Key Input Count without Debouncing	      */
/* ========================================================================== */
/*			  Designed and programmed by Duck-Yong Yoon in 2007.  */

#include "AT91SAM7S256.h"
#include "lib_AT91SAM7S256.h"
#include "OK7S256ads.h"

void LCD_3d(unsigned int number)		/* display 3-digit decimal number */
{ unsigned int i, flag;

  flag = 0;
  i = number/100;				// 10^2
  if(i == 0) LCD_data(' ');
  else {     LCD_data(i + '0');
             flag = 1;
       }

  number = number % 100;			// 10^1
  i = number/10;
  if((i == 0) && (flag == 0))
             LCD_data(' ');
  else {     LCD_data(i + '0');
             flag = 1;
       }

  i = number % 10;				// 10^0
  LCD_data(i + '0');
}

int main(void)
{
  unsigned int key1=0, key2=0;

  MCU_initialize();				// initialize AT91SAM7S256 & kit
  Delay_ms(50);					// wait for system stabilization
  LCD_initialize();				// initialize text LCD

  LCD_string(0x80,"   KEY1 = 000   ");		// display title on text LCD
  LCD_string(0xC0,"   KEY2 = 000   ");
  Beep();

  while(1)
    { switch(Key_in())				// key input without debouncing
        { case 0x01 : key1++;			// if KEY1, display KEY1 count
                      if(key1 > 999) key1 = 0;
                      LCD_command(0x8A);
                      LCD_3d(key1);
                      break;
          case 0x02 : key2++;			// if KEY2, display KEY2 count
                      if(key2 > 999) key2 = 0;
                      LCD_command(0xCA);
                      LCD_3d(key2);
                      break;
          default :   break;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?