HT IDE 3000 VPM 軟件仿真 按鈕按下 數碼管顯示數字 電路搭建以及源代碼 VPM 應用 系列之五

1。功能說明:按下按鈕,數碼管從0計數,到9復位爲0,繼續顯示。

2。代碼如下:歡迎大家優化爲最佳代碼。

/*
 Date : 20091010
 For  : button drive led
 Tool : HT IDE 3000 V7.0
 MCU  : HT48R50A-1
 Fsys : 4MHz
 ASM/C: C
 VPM  : yes
*/
#include  "self-HT48R50A-1.h"

//for Segs-Com0
#define  SegsPort _pa
#define  SegsCtrl  _pac 
#define  PtrPort  _pb6
#define  PtrCtrl  _pbc6
#define  Com0Port _pb7
#define  Com0Ctrl _pbc7
//for Button
#define  swPort  _pc0 //switch port
#define  swCtrl  _pcc0 //switch controlling

//variable
int iCntButton;
//function
int getSwitchStatus(void);
void blinkSegs(int);
//the main function
void main(void)
{
 int i; 
 
 SegsPort = 0x00;   //turn off segs
 SegsCtrl = 0x00;   //output
 Com0Ctrl = 0;
 PtrCtrl = 0;
 Com0Port = 0;
 PtrPort = 0;
 swCtrl = 1;    //input
 iCntButton = 0; 

 while(1)
 {  
  _delay(10000);
   
  getSwitchStatus();
  
  blinkSegs(iCntButton);
 }
}
//function ==================================
int getSwitchStatus()
{
 
 swCtrl = 1;
 
 if(0 == swPort)
 { 
  iCntButton++;
  iCntButton = iCntButton % 10;
  while(0 == swPort)
  {
   _delay(1000);
  }
  return 0xff;
 }
 
 return 0x00;
}
//function -----------------------------------
void blinkSegs(int sum)
{
 char iBlink;
 char Segs[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
 iBlink = Segs[sum];
 
 SegsPort = iBlink;
}

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

3。仿真截圖瀏覽地址:

https://p-blog.csdn.net/images/p_blog_csdn_net/duojinian/EntryImages/20091013/Segs_Driver_20091013.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章