(十)msp430:7段显示器与MSP-EXP430G2 TI Launchpad连接

释放双眼,带上耳机,听听看~!

介绍

(十)msp430:7段显示器与MSP-EXP430G2 TI Launchpad连接

7段显示

7段显示器由8个LED段组成。它们用于显示数字(0-9)和某些字母(如c,A,H,P等)。

  • 这些LED段中的7个呈线形,而1个段是圆形的。
  • 8个元件中的每一个都有一个与之相关的引脚,可以驱动为高电平或低电平。
  • 要显示数字或字母,我们需要打开显示屏的特定LED段。

 

搭建图

7段显示器与MSP-EXP430G2 TI启动板连接

(十)msp430:7段显示器与MSP-EXP430G2 TI Launchpad连接

7段显示器与MSP-EXP430G2 TI启动板连接

 

这里,7段显示器由MSP-EXP430G2 TI Launchpad直接驱动。需要在显示器和MSP-EXP430G2 TI Launchpad板之间连接电阻器。根据要显示的数字或字母,应用控制信号。

注意: 我们使用了共阳极显示器,因此公共引脚连接到5V。如果使用共阴极显示器,则公共引脚需要接地。

对于共阳极显示器,驱动引脚LOW以打开相应的LED段。

对于共阴极显示器,驱动引脚HIGH以打开相应的LED段。

 

使用SN7446AN驱动器与MSP-EXP430G2 TI Launchpad连接7段显示器

(十)msp430:7段显示器与MSP-EXP430G2 TI Launchpad连接

使用SN7446AN驱动器与MSP-EXP430G2 TI Launchpad连接7段显示器

这里,7段显示器由SN7446AN IC驱动。它是一个BCD到7段驱动器/解码器IC。这减少了驱动7段显示器所需的引脚数量。

 

注意: MSP-EXP430G2 TI Launchpad主板具有512字节的RAM,可轻松上传,尤其是在使用不同库时。有时您需要串行缓冲区足够大以包含所需的数据,并且您必须修改串行库的缓冲区大小。在做这些事情时,我们必须确保代码不会使用超过70%的RAM。这可能导致代码以不稳定的方式工作,有时运行良好并且在其他方​​面失败。 

有些时候RAM使用率可能会超过70%并且代码将完全正常工作,并且即使RAM使用率为65%,代码也无法工作。 

在这种情况下,可能需要对缓冲区大小和/或变量进行一些试验和错误。

​​​​​​​

用于控制7段显示的程序

int disp_pin[7];	/* array for a-g pins of 7-Segment display */

void define_segment_pins(int a, int b, int c, int d, int e, int f, int g)	/* Assigns 7-segment display pins to board */
{  
  disp_pin[0] = a;
  disp_pin[1] = b;
  disp_pin[2] = c;
  disp_pin[3] = d;
  disp_pin[4] = e;
  disp_pin[5] = f;
  disp_pin[6] = g;
}

void display_number(int num)	/* Function for displaying number (0-9) */
{switch(num)
  {case 0:
    digitalWrite(disp_pin[0], LOW);	/* Drive disp_pin[0] to LOW */
    digitalWrite(disp_pin[1], LOW);	/* Driving LOW turns on LED segment for common anode display */
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], HIGH); 
    break;
    case 1:
    digitalWrite(disp_pin[0], HIGH);	/* Drive disp_pin[7] to HIGH */
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);	/* Driving HIGH turns off LED segment for common anode display */
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], HIGH);
    break;
    case 2:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], HIGH);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 3:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 4:
    digitalWrite(disp_pin[0], HIGH);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 5:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], HIGH);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 6:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], HIGH);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 7:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], HIGH);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], HIGH);
    break;
    case 8:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    case 9:
    digitalWrite(disp_pin[0], LOW);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], HIGH);
    digitalWrite(disp_pin[5], LOW);
    digitalWrite(disp_pin[6], LOW);
    break;
    default:
    digitalWrite(disp_pin[0], HIGH);
    digitalWrite(disp_pin[1], LOW);
    digitalWrite(disp_pin[2], LOW);
    digitalWrite(disp_pin[3], LOW);
    digitalWrite(disp_pin[4], LOW);
    digitalWrite(disp_pin[5], HIGH);
    digitalWrite(disp_pin[6], LOW);
    break;
  }
}

void setup() {
  pinMode(7, OUTPUT);	
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  define_segment_pins(13,12,11,10,9,8,7);	/* a-g segment pins to TI Launchpad */
}

void loop() {
  int i;
  for(i = 9; i>=0; i--)
  {
    display_number(i);
    delay(1000);
  }for(i = 0; i<=9; i++)
  {
    display_number(i);
    delay(1000);
  }
}

 

 

使用SN7446AN解码器/驱动器控制7段显示的程序

int bcd_pins[4];	/* array for A-D pins of driver IC */

void bcd_control_pins(int a, int b, int c, int d)	/* Assigns A-D pins of deiver IC to TI Launchpad */
{  
  bcd_pins[0] = a;	
  bcd_pins[1] = b;
  bcd_pins[2] = c;
  bcd_pins[3] = d;
}

void display_number(int num)	/* Function for displaying number (0-9) */
{switch(num)
  {case 0:
    digitalWrite(bcd_pins[0], LOW);	/* Drive bcd_pin[0] to LOW */
    digitalWrite(bcd_pins[1], LOW);	/* Driving LOW turns on LED segment for common anode display */
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);	
    break;
    case 1:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 2:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 3:
    digitalWrite(bcd_pins[0], HIGH);	/* Drive bcd_pin[3] to HIGH */
    digitalWrite(bcd_pins[1], HIGH);	/* Driving HIGH turns on LED segment for common anode display */
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 4:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 5:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 6:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 7:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], HIGH);
    digitalWrite(bcd_pins[2], HIGH);
    digitalWrite(bcd_pins[3], LOW);
    break;
    case 8:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], HIGH);
    break;
    case 9:
    digitalWrite(bcd_pins[0], HIGH);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], HIGH);
    break;
    default:
    digitalWrite(bcd_pins[0], LOW);
    digitalWrite(bcd_pins[1], LOW);
    digitalWrite(bcd_pins[2], LOW);
    digitalWrite(bcd_pins[3], LOW);
    break; 
  }
}

void setup() {
  pinMode(11, OUTPUT);		
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  bcd_control_pins(14,13,12,11);	/* A-D of driver IC to TI Launchpad */
}

void loop() {
  int i;
  for(i = 9; i>=0; i--)
  {
    display_number(i);
    delay(1000);
  }for(i = 0; i<=9; i++)
  {
    display_number(i);
    delay(1000);
  }
}

程序下载

给TA打赏
共{{data.count}}人
人已打赏
msp430/Arduino-进阶

(九)msp430进阶:HC-05蓝牙模块与MSP-EXP430G2 TI Launchpad连接

2019-6-13 23:51:46

msp430/Arduino-进阶

(十一)msp430进阶:遥感模块与MSP-EXP430G2 TI Launchpad连接

2019-6-14 19:49:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
'); })();