您的位置:首页 > 产品设计 > 产品经理

VPM buttton 按钮代码 实例 系列之四

2009-10-12 15:13 288 查看
1。本实例实用按钮,Button控制LED亮灭。

2。Button自带延迟时间选项,可以填入数值,单位ms。不过注意:输入的是十六进制,再次打开可以看到自动转化为十进制。

3。实例代码如下: 编译环境HT IDE 3000 V7.0

/*
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"

#define ledPort _pa //led driving ports
#define ledPortCtrl _pac //led controling
#define swPort _pc0 //switch port
#define swPortCtrl _pcc0 //switch controlling

int iCntButton;
//function
int getSwitchStatus(void);

void main(void)
{
int i;
int swStatus;

ledPortCtrl = 0x00; //output
ledPort = 0xff; //turn off leds
swPortCtrl = 0xff;

//_delay(10000);
swStatus = 1;
while(1)
{
_delay(1000);

swStatus = getSwitchStatus();

if(1 == (swStatus%2))
{
ledPort = ~ledPort; //change led's status
}
}
}
//function
int getSwitchStatus()
{
_pcc = 0xff;

if(0 == _pc0)
{
iCntButton++;
while(0 == swPort)
{
_delay(1000);
}
return 0xff;
}

return 0x00;
}

4。自定义头文件代码如下:

// self-HT48R50A-1.H
// This file contains the definition of registers for
// Holtek HT48R50A-1 microcontroller.
// Generated by Cfg2IncH V1.2.
// [Version] 6.2, 4

// Do not modify manually.

#ifndef _HOLTEK_H_
#define _HOLTEK_H_

void CLEARMEMORYHT48R50A_1();
#define ClearMemory CLEARMEMORYHT48R50A_1

unsigned char _iar0 @0x00;
unsigned char _mp0 @0x01;
unsigned char _iar1 @0x02;
unsigned char _mp1 @0x03;
unsigned char _acc @0x05;
unsigned char _pcl @0x06;
unsigned char _tblp @0x07;
unsigned char _tblh @0x08;
unsigned char _wdts @0x09;
unsigned char _status @0x0a;
unsigned char _intc @0x0b;
unsigned char _tmr0 @0x0d;
unsigned char _tmr0c @0x0e;
unsigned char _tmr1h @0x0f;
unsigned char _tmr1l @0x10;
unsigned char _tmr1c @0x11;
//;;
unsigned char _pa @0x12;
unsigned char _pac @0x13;
unsigned char _pb @0x14;
unsigned char _pbc @0x15;
unsigned char _pc @0x16;
unsigned char _pcc @0x17;
unsigned char _pd @0x18;
unsigned char _pdc @0x19;
unsigned char _pg @0x1e;
unsigned char _pgc @0x1f;
//;;
#define _c _0a_0
#define _ac _0a_1
#define _z _0a_2
#define _ov _0a_3
#define _pdf _0a_4
#define _to _0a_5
#define _emi _0b_0
#define _eei _0b_1
#define _et0i _0b_2
#define _et1i _0b_3
#define _eif _0b_4
#define _t0f _0b_5
#define _t1f _0b_6
#define _t0psc0 _0e_0
#define _t0psc1 _0e_1
#define _t0psc2 _0e_2
#define _t0e _0e_3
#define _t0on _0e_4
#define _t0m0 _0e_6
#define _t0m1 _0e_7
#define _t1e _11_3
#define _t1on _11_4
#define _t1m0 _11_6
#define _t1m1 _11_7
//;;
#define _pa0 _12_0
#define _pa1 _12_1
#define _pa2 _12_2
#define _pa3 _12_3
#define _pa4 _12_4
#define _pa5 _12_5
#define _pa6 _12_6
#define _pa7 _12_7
//;;self add
#define _pac0 _13_0
#define _pac1 _13_1
#define _pac2 _13_2
#define _pac3 _13_3
#define _pac4 _13_4
#define _pac5 _13_5
#define _pac6 _13_6
#define _pac7 _13_7
//;;
#define _pb0 _14_0
#define _pb1 _14_1
#define _pb2 _14_2
#define _pb3 _14_3
#define _pb4 _14_4
#define _pb5 _14_5
#define _pb6 _14_6
#define _pb7 _14_7
//;;self add
#define _pbc0 _15_0
#define _pbc1 _15_1
#define _pbc2 _15_2
#define _pbc3 _15_3
#define _pbc4 _15_4
#define _pbc5 _15_5
#define _pbc6 _15_6
#define _pbc7 _15_7
//;;
#define _pc0 _16_0
#define _pc1 _16_1
#define _pc2 _16_2
#define _pc3 _16_3
#define _pc4 _16_4
#define _pc5 _16_5
#define _pc6 _16_6
#define _pc7 _16_7
//;;self add
#define _pcc0 _17_0
#define _pcc1 _17_1
#define _pcc2 _17_2
#define _pcc3 _17_3
#define _pcc4 _17_4
#define _pcc5 _17_5
#define _pcc6 _17_6
#define _pcc7 _17_7
//;;
#define _pd0 _18_0
#define _pd1 _18_1
#define _pd2 _18_2
#define _pd3 _18_3
#define _pd4 _18_4
#define _pd5 _18_5
#define _pd6 _18_6
#define _pd7 _18_7
//;;self add
#define _pdc0 _19_0
#define _pdc1 _19_1
#define _pdc2 _19_2
#define _pdc3 _19_3
#define _pdc4 _19_4
#define _pdc5 _19_5
#define _pdc6 _19_6
#define _pdc7 _19_7
//;;
#define _pg0 _1e_0
#define _pg1 _1e_1
#define _pg2 _1e_2
//;;self add
#define _pgc0 _1f_0
#define _pgc1 _1f_1
#define _pgc2 _1f_2

#endif

5。软件仿真使用VPM截图地址:

http://p.blog.csdn.net/images/p_blog_csdn_net/duojinian/EntryImages/20091012/button_Driver.jpg
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: