无法在mikroc的7段显示中显示从0到9的数字

时间:2015-03-24 10:11:25

标签: microcontroller mikroc

我对MIKROC的微控制器编程非常陌生。我试图在带有mikroc的7段显示中显示从0到9的数字。我使用了无限循环。在while循环中我使用了函数" delay_ms(500)"与其他代码。但是,不是显示从0到9的数字,而是显示前几个数字,如0,1,2。

我的代码在

下面
void main()
{

 trisb=0;
 portb=0;

 while(1){
 delay_ms(500);
  portb=0x3F;
  delay_ms(500);

  portb= 0x06;
  delay_ms(500);
  portb= 0x5B;
  delay_ms(500);
  portb=0x4F;
  delay_ms(500);
  portb=0x66;
  delay_ms(500);
  portb=0x6D;
  delay_ms(500);
  portb=0x7D;
  delay_ms(500);
  portb=0x07;
  delay_ms(500);
  portb=0x7F;
  delay_ms(500);
  portb=0x6F;
  delay_ms(500);



 }
}

我的电路图

enter image description here

1 个答案:

答案 0 :(得分:0)

首先, 如果这是一个标准的7段显示器,它基本上只是一堆带有共阴极共阳极的LED。 因此,您需要保护μChip免受“短路”,因为LED将完全打开,或者从引脚(共阴极)吸取最大功率,或者强制芯片吸收最大功率(共阳极)。

您的电路图没有显示使用的是哪个,所以我在这里是通用的。

因此,在LCD引脚(不是普通引脚,其他引脚)上串联一个电阻。对于5伏特,根据所需的光强度,通常需要300到1K欧姆!

下一步

与LCD的通信有关,lcd可以设置为:“abcdefg”或“gfedcba”

bit# name description
MSb "A" is the top LED bar
2.b "B" is the right most upper LED bar
3.b "C" is the right most lower LED bar
4.b "D" is the the bottom LED bar
5.b "E" is the left most lower LED bar
6.b "F" is the left most upper LED bar
7.b "G" is the center LED bar
8.b "D.P" is the dot .. also indicating down.. (or decimal point)

对于共阴极(共阳极的反位模式)的含义:

Digit   gfedcba abcdefg a   b   c   d   e   f   g
0       0×3F    0×7E    on  on  on  on  on  on  off
1       0×06    0×30    off on  on  off off off off
2       0×5B    0×6D    on  on  off on  on  off on
3       0×4F    0×79    on  on  on  on  off off on
4       0×66    0×33    off on  on  off off on  on
5       0×6D    0×5B    on  off on  on  off on  on
6       0×7D    0×5F    on  off on  on  on  on  on
7       0×07    0×70    on  on  on  off off on  off
8       0×7F    0×7F    on  on  on  on  on  on  on
9       0×6F    0×7B    on  on  on  on  off on  on

所以我想(根据你的十六进制值)你必须有一个类型“gfedcba” 如您所见,您的代码符合表格。当且仅当公共端接地时。

(在此处阅读更多内容:http://www.electronicsblog.org/seven-segment-display-everything-you-need-to-know-about/

<强>代码 如果您能够显示数字0,1和2,我仍然看不到您的代码有问题。因为这表明所有LED已经至少点亮一次,并且您的PIC应该正确配置。

我最好的猜测是,这实际上是一个电气问题。 PIC应该使用此代码,以半秒的间隔显示数字0 - 9,除非它在达到一定数量后重置。这可能是一个不好的焊接,或者更常见的是不稳定的直流电源问题。

要抑制电源上的小尖峰,请尝试在电源上并联一些电容。为了测试,你可以尝试:100nF和1000μF。 不要担心它不会做任何事情......除了吸收高频噪声..这是一个低通滤波器的特殊情况..