0

我对使用 MIKROC 进行微控制器编程非常陌生。我正在尝试使用 mikroc 在 7 段显示器中显示从 0 到 9 的数字。我使用了无限 while 循环。在 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);



 }
}

我的电路图

在此处输入图像描述

4

1 回答 1

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。不用担心它不会做任何事情..除了吸收高频噪声..这是低通滤波器的特殊情况..

于 2015-03-24T11:34:23.330 回答