#include <reg52.h> #include <intrins.h> typedef unsigned int uint; typedef unsigned char uchar; void display ( uint count ); void delay(uint i); sbit P2_0=P2^0; sbit P2_1=P2^1; sbit P2_2=P2^2; sbit P2_3=P2^3; sbit P3_4=P3^4; sbit P3_5=P3^5; sbit P1_0=P1^0; sbit P1_1=P1^1; uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//p0口决定亮什么 uint i; uint j; uint t; void main() { while(1) { if(P3_4==0) { delay(30000); P1_0=0; } if(P3_5==0) { delay(30000); P1_0=1; } for (j=9999;j>=0&&j<=9999;j--) { for(t=0;t<200;t++){ display(j); } } } } void delay(uint n) { uint i,j; for(i=n;i>0;i--); for(j=114;j>0;j--); } void display ( uint count ) { P0=table[count/1000]; P2_0=0; delay (100); P2_0=1; P0=table[count/100%10]; P2_1=0; delay (100); P2_1=1; P0=table[count/10%10]; P2_2=0; delay (100); P2_2=1; P0=table[count%10]; P2_3=0; delay (100); P2_3=1; }帮我把这个改成每隔一秒数码管数字加一修改好的代码发给我
时间: 2024-03-31 21:38:14 浏览: 73
#include <reg52.h>
#include <intrins.h>
typedef unsigned int uint;
typedef unsigned char uchar;
void display ( uint count );
void delay(uint i);
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//p0口决定亮什么
uint i;
uint j;
uint t;
void main() {
uint count = 0;
while(1) {
if(P3_4==0) {
delay(30000);
P1_0=0;
}
if(P3_5==0) {
delay(30000);
P1_0=1;
}
display(count);
count++;
if(count > 9999) count = 0;
delay(1000);
}
}
void delay(uint n) {
uint i,j;
for(i=n;i>0;i--)
for(j=114;j>0;j--);
}
void display ( uint count ) {
P0=table[count/1000];
P2_0=0;
delay (100);
P2_0=1;
P0=table[count/100%10];
P2_1=0;
delay (100);
P2_1=1;
P0=table[count/10%10];
P2_2=0;
delay (100);
P2_2=1;
P0=table[count%10];
P2_3=0;
delay (100);
P2_3=1;
}
以上是修改后的代码,每隔一秒钟数码管数字加一。
阅读全文