7 段射频识别计数器

7 Segment Rfid Counter

我有 rfid 电路。我正在尝试添加一个带有 7 个七段的计数器。 我的七段给出这样的随机数。Photo 我认为这些数字与我的数字相反。我该如何解决这个问题?

 #include <16F887.h>    
    #fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
    #use delay(clock=4m,oscillator) 
    #define Dig1 PIN_D0
    #define Dig2 PIN_D1
    #define rfid PIN_D2
    #define reset PIN_A1
    #use fast_io(b)
    #use fast_io(d)
    char birler = 0, onlar = 0, sayi = 0;
       void main() 
    {
       int digit[10]={0b0111111,0b0000110,0b1011011,0b1001111,0b1101101,0b1111101,0b0000111,0b1111111,0b1101111};

       set_tris_b(0x00);
       output_b(1);
       set_tris_d(0b11111100);
       output_d(0b11111100);
       output_b(0b11111100);

       while(1)
         {
         output_b(digit[onlar]);
         output_d(0b11111101);
         delay_ms(5);
         output_b(digit[birler]);
         output_d(0b11111110);
         delay_ms(5);

         if(input(rfid) == 0)
         {
            sayi++;
            birler = sayi%10;
            onlar = sayi/10;
            while(input(rfid) == 0)
            {
              output_b(digit[onlar]);
              output_d(0b11111101);
              delay_ms(5);
              output_b(digit[birler]);
              output_d(0b11111110);
              delay_ms(5);

             }
          } 
          }
       }

I think these numbers are opposite of my numbers.

看看你的七段是不是common cathode,代码好像是共阴七段的

如果它是普通阳极并且它是您唯一的选择,您可以通过切换 digit 数组中的所有位来简单地更改代码以适合它,因为前零将是 0b10000000

您确实应该考虑将显示与主循环隔离开来,并消除代码中的内联延迟。优点是提高了可读性、更容易维护并消除了实际工作的延迟。

在准备此回复时,我发现您的段 table 缺少条目。缺少“4”条目。

下面的代码远未完成。 LED 段中缺少一个数字 table,您使用的是需要去抖动的开关,并且它缺少用于非阻塞计时器的时钟。

我 copy/pasted 了解了您的大部分应用,并添加了评论...

#include <16F887.h>    
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4m,oscillator) 
#define Dig1 PIN_D0
#define Dig2 PIN_D1
#define rfid PIN_D2
#define reset PIN_A1
#use fast_io(b)
#use fast_io(d)

// never define const arrays on the stack.
static const int digit[10]= { 0b0111111, 0b0000110, 0b1011011, 0b1001111, /* missing '4' */ 0,
                              0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };

void display(unsigned char value)
{
    static char tens = 0;
    char dig = (tens) ? (value / 10) : (value % 10);
    dig = digit[dig];
    output_high((tens} ? Dig2 : Dig1);
    output_b(dig);                     // <-- clobbers the high bit of B
    output_low((tens} ? Dig1 : Dig2);  // preventing other uses for it.
    tens = !tens;
}

void main() 
{
   char sayi = 0;

   output_b(1);
   output_d(0b11111100);
   output_b(0b11111100);  // why set PORTB to 1 earlier?  is that a bug?

   set_tris_b(0x00);      // always init tristate AFTER setting output 
   set_tris_d(0b11111100);

   while(1)
   {
     display(sayi);

     if(input(rfid) == 0) // debouncing needed. 30ms is a good delay for debouncing
     {
        sayi++;           // what happens when we reach 100 ???
     }
     delay_ms(30);        // in real-life, this should not be there.
                          // there are better ways to throttle a program, 
                          // including going to sleep/idle.
   }
}

如果您的数字显示不正确,请考虑将数字数组更改为

digit[] = {0b1, 0b10, 0b100, 0b1000, 0b10000, 0b100000, 0b1000000};

和运行每个模式5秒。这将告诉您哪个位控制哪个段。关于来自不同制造商的 7 段显示器,我注意到它们并不总是以相同的方式对段进行编号,因此 0b111111 可能显示为 6 或 9:不一定是 0。