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。仿真截图浏览地址: