发布网友 发布时间:2022-05-18 21:20
共2个回答
热心网友 时间:2023-11-05 02:45
#include <reg52.h>
#include <intrins.h>
sbit k_add = P3^1;
sbit k_sub = P3^4;
unsigned char code SEG7[] = {
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};
unsigned char DISP_BUFF[] = {
10, 10, 10, 10, 10, 10, 10, 10,
1, 3, 9, 2, 5, 8, 0, 7, 4, 6, 3, 2,
10, 10, 10, 10, 10, 10, 10, 10};
unsigned char j = 0, k = 1;
void DelayMS(unsigned int x)
{
unsigned char i;
while(x--) for(i = 200; i > 0; i--);
}
void display(unsigned char x)
{
unsigned char i, w = 128;
for(i = 0; i < 8; i++) {
P0 = SEG7[DISP_BUFF[i + k]];
P2 = w; DelayMS(1); P2 = 0;
w = _cror_(w, 1);
}
j++;
if (j > x) {
j = 0;
k++; if (k == 20) k = 0;
}
}
void main()
{
unsigned char d = 30;
while(1) {
if (!k_add) {
display(d);
if (!k_add) {
d += 2; if (d > 50) d = 50;
while (!k_add) display(d);
}
}
if (!k_sub) {
display(d);
if (!k_sub) {
d -= 2; if (d < 10) d = 10;
while (!k_sub) display(d);
}
}
display(d);
P1 = d;
}
}
热心网友 时间:2023-11-05 02:45
你好!是仿真实现还是有实物?要是实物的话,发一下原理图