C 7段射频识别计数器
我有rfid电路。我想加一个7段的计数器。 我的七段给出了这样的随机数。 我认为这些数字与我的数字相反。我怎样才能解决这个问题C 7段射频识别计数器,c,pic,C,Pic,我有rfid电路。我想加一个7段的计数器。 我的七段给出了这样的随机数。 我认为这些数字与我的数字相反。我怎样才能解决这个问题 #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_
#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);
}
}
}
}
#包括
#保险丝XT、NOWDT、NOPROTECT、NOBROWNOUT、NOLVP、NOPUT、NOWRT、NODEBUG、NOCPD
#使用延迟(时钟=4m,振荡器)
#定义Dig1引脚\u D0
#定义Dig2引脚_D1
#定义rfid PIN_D2
#定义复位引脚A1
#使用快速io(b)
#使用快速io(d)
char-birler=0,onlar=0,sayi=0;
void main()
{
整数数字[10]={0b0111111,0b0000110,0B101111,0b1001111,0b1101101,0b1111101,0b0000111,0b1111111,0b1101111};
设置三个参数(0x00);
输出_b(1);
设置三者(0b11111100);
输出d(0b11111100);
输出_b(0b11111100);
而(1)
{
输出_b(数字[onlar]);
输出d(0b11111101);
延迟时间(5);
输出_b(数字[birler]);
输出d(0b11111110);
延迟时间(5);
如果(输入(rfid)==0)
{
sayi++;
birler=sayi%10;
onlar=sayi/10;
while(输入(rfid)==0)
{
输出_b(数字[onlar]);
输出d(0b11111101);
延迟时间(5);
输出_b(数字[birler]);
输出d(0b11111110);
延迟时间(5);
}
}
}
}
我认为这些数字与我的数字相反
检查您的七段是否正确,因为代码似乎是为公共阴极七段构建的
如果它是公共阳极,并且是您唯一的选择,您可以通过切换digit
数组中的所有位来简单地更改代码以适应它,因为exzero将是0b10000000
我认为这些数字与我的数字相反
检查您的七段是否正确,因为代码似乎是为公共阴极七段构建的
如果是公共阳极,它是您唯一的选择,您可以通过切换<代码>数字数组中的所有位来简单地更改代码以适应它,对于EXO 0将是代码> 0B10000< /Cord>
> P>您确实应该考虑将显示与主循环隔离,并且消除代码中的内联延迟。优点是增加了可读性,易于维护,并消除了实际工作的延迟 在准备此响应时,我发现您的segments表缺少条目。缺少“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.
}
}
#包括
#保险丝XT、NOWDT、NOPROTECT、NOBROWNOUT、NOLVP、NOPUT、NOWRT、NODEBUG、NOCPD
#使用延迟(时钟=4m,振荡器)
#定义Dig1引脚\u D0
#定义Dig2引脚_D1
#定义rfid PIN_D2
#定义复位引脚A1
#使用快速io(b)
#使用快速io(d)
//不要在堆栈上定义常量数组。
静态常量整数数字[10]={0b0111111、0b0000110、0B10110111、0b1001111、/*缺少“4”*/0,
0b1101101、0b1111101、0b0000111、0b1111111、0b1101111};
无效显示(无符号字符值)
{
静态字符数=0;
char dig=(十位)?(值/10):(值%10);
dig=数字[dig];
输出_高((十位数?Dig2:Dig1);
OutPuthBub(DIG);//您确实应该考虑将显示与主循环隔离开来,消除代码中的内联延迟。PROS增加了可读性,维护更容易,并且消除了实际工作中的延迟。
在准备此响应时,我发现您的segments表缺少条目。“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.
}
}
#包括
#保险丝XT、NOWDT、NOPROTECT、NOBROWNOUT、NOLVP、NOPUT、NOWRT、NODEBUG、NOCPD
#使用延迟(时钟=4m,振荡器)
#定义Dig1引脚\u D0
#定义Dig2引脚_D1
#定义rfid PIN_D2
#定义复位引脚A1
#使用快速io(b)
#使用快速io(d)
//不要在堆栈上定义常量数组。
静态常量整数数字[10]={0b0111111、0b0000110、0B10110111、0b1001111、/*缺少“4”*/0,
0b1101101、0b1111101、0b0000111、0b1111111、0b1101111};
无效显示(无符号字符值)
{
静态字符数=0;
char dig=(十位)?(值/10):(值%10);
dig=数字[dig];
输出_高((十位数?Dig2:Dig1);
OutPuthBub(DIG);//< P>如果您的数字没有正确显示,请考虑将数字数组更改为
digit[] = {0b1, 0b10, 0b100, 0b1000, 0b10000, 0b100000, 0b1000000};
并运行每个模式5秒。这将告诉你哪一位控制哪个片段。我注意到来自不同制造商的7段显示是,它们不总是以相同的方式编号段,所以0B111111可能出现为6或9:不一定是0。< /P> < P>如果您的数字没有正确显示,请考虑CH。将数字数组更改为
digit[] = {0b1, 0b10, 0b100, 0b1000, 0b10000, 0b100000, 0b1000000};
然后运行每个模式5秒钟。这将告诉您哪个位控制哪个段。我注意到不同制造商的7段显示器并不总是以相同的方式对段进行编号,因此0b111111可能显示为6或9:不一定是0。这是公共阴极,当代码发送11,22,33,44,55..nu时mbers代码工作正常。这是常见的阴极,当代码发送11,22,33,44,55..numbers代码时工作正常。我希望您了解到,没有只处理显示的专用函数会妨碍您调试程序。我希望您了解到,没有只处理显示的专用函数会妨碍您你调试程序的能力。