| 搞了个IAR环境体验下C++上来就踩坑啊, 类的成员函数内位移操作不能用成员变量
 
  , 用函数变量操作位移却是好的,
 但是用成员变量赋值给函数变量就不行了。
 还是先用C折腾吧~
 
 
 复制代码#include "AI8051U.h"
typedef         unsigned char        u8;
typedef         unsigned int        u16;
typedef         unsigned long        u32;
#define MAIN_Fosc        24000000UL
#define LED_PORT P0
class LED {
public:
    int  _pinNum;
    // 构造函数,关联PIN脚
    LED( int pinNum) {
      //_pinNum = pinNum;
      _pinNum = 1;
    }
    // 点亮LED
    void on() {
      int tempPin = _pinNum;
      //LED_PORT &= ~(1 << _pinNum);
      LED_PORT &= ~(1 << tempPin);
    }
    // 熄灭LED
    void off() {
      int tempPin = _pinNum;
      //LED_PORT |= (1 << _pinNum);
      LED_PORT |= (1 << tempPin);
    }
};
void  delay_ms(u16 ms)
{
     u16 i;
     do{
          i = MAIN_Fosc / 10000;
          while(--i);
     }while(--ms);
}
int main( void )
{
    int  _pinNum = 2;
    P_SW2 |= 0x80; //扩展寄存器(XFR)访问使能
    P0M1 = 0x00;   P0M0 = 0xff;   //设置为推挽输出
    P4M1 = 0x00;   P4M0 = 0x00;   //设置为准双向口
    P4_bit.P40 = 0;                //LED Power On
    P0 = 0xFF;
    LED led(1);
    while(1)
    {
        led.on();
      //LED_PORT &= ~(1 << _pinNum);
        //P0_bit.P00 = 0;                //LED On
        delay_ms(500);
        led.off();
        //LED_PORT |= (1 << _pinNum);
        //P0_bit.P00 = 1;                //LED Off
        delay_ms(500);
        //_pinNum++;
    }
}
 
 
 |