標(biāo)題: 兩個(gè)獨(dú)立按鍵單片機(jī)程序 控制靜態(tài)數(shù)碼管數(shù)字增加或減少 [打印本頁(yè)]

作者: kscheang    時(shí)間: 2021-1-14 01:21
標(biāo)題: 兩個(gè)獨(dú)立按鍵單片機(jī)程序 控制靜態(tài)數(shù)碼管數(shù)字增加或減少
//靜態(tài)數(shù)碼管, 按下K1增加到F, 按下K2減少到0


#include "reg52.h"                        
typedef unsigned int u16;         
typedef unsigned char u8;
sbit K1=P1^0;
sbit K2=P1^2;
unsigned int i=0;
signed int j=0;
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                     0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(u16 i)
{
while(i--);        
}
void keypush1()
{
if (K1==0)
{
  delay(1000);
  if (K1==0)
  {
   j++;
  }
while(!K1);
}
}
void keypush2()
{
if (K2==0)
{
  delay(1000);
  if (K2==0)
  {
   j--;
  }
while(!K2);
}
}
void DigDisplay()
{
    P0=~smgduan[j];
}
void main()
{        
while(1)
    {        
  keypush1();
  if (j>15)
  {
   j=15;
  }         
  keypush2();
  if (j<0)
  {
   j=0;
  }         
     DigDisplay();
}               
}





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1