gpt4 book ai didi

c - 7 段射频识别计数器

转载 作者:太空宇宙 更新时间:2023-11-04 04:22:28 24 4
gpt4 key购买 nike

我有 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);

}
}
}
}

最佳答案

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

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

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

我已经复制/粘贴了您应用的大部分内容,并添加了评论...

#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.
}
}

关于c - 7 段射频识别计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45236565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com