⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led.c

📁 Welding Robot controller C Embedded Program on micro-controller.
💻 C
字号:
/******************************************************************************
* welding mobile robot control programme
* led display processing module
* @author: thai nguyen nhut dien
* @date: may 2006
******************************************************************************/

#define Pin_E Pin_B3
#define Pin_D Pin_B2
#define Pin_C Pin_B1

void displayBCD(int bcd) {
  int i;
  for (i=0; i<4; i++) {
  output_high(Pin_C);                        // data send start
  output_bit(Pin_D, (bcd & 0x08) != 0);      // send data
  output_low(Pin_C);                         // data send end
  bcd = bcd << 1;                            // shift left one bit
  }
}

void display(int32 num) {
  int thousand, hundred, ten, unit;

  thousand  = num / 1000;
  hundred   = (num % 1000) / 100;
  ten       = (num % 100) /10;
  unit      = num % 10;

  // trim leading zero
  ten       = (thousand | hundred | ten) != 0 ? ten : 255;
  hundred   = (thousand | hundred) != 0 ? hundred : 255;
  thousand  = thousand != 0 ? thousand : 255;

  // enable leds
  output_low(Pin_E);

  displayBCD(0);
  displayBCD(thousand);
  displayBCD(hundred);
  displayBCD(ten);
  displayBCD(unit);

  // disable leds
  output_high(Pin_E);
}

void displayFloat(float fnum) {
  int32 num;
  int thousand, hundred, ten, unit;

  num = fnum * 10;

  thousand  = num / 1000;
  hundred   = (num % 1000) / 100;
  ten       = (num % 100) /10;
  unit      = num % 10;

  // trim leading zero
  ten       = (thousand | hundred | ten) != 0 ? ten : 255;
  hundred   = (thousand | hundred) != 0 ? hundred : 255;
  thousand  = thousand != 0 ? thousand : 255;

  // enable leds
  output_low(Pin_E);

  displayBCD(2);
  displayBCD(thousand);
  displayBCD(hundred);
  displayBCD(ten);
  displayBCD(unit);

  // disable leds
  output_high(Pin_E);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -