VPM buttton 按鈕代碼 實例 系列之四

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截圖地址:

https://p-blog.csdn.net/images/p_blog_csdn_net/duojinian/EntryImages/20091012/button_Driver.jpg

發佈了48 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章