#include <REGX52.H>
void Delay(int xms)
{
while(xms--){
unsigned char j;
j = 278;
while (--j);
}
}
void smgca(locating,number){
P0 = 0xFF;
switch(locating)
{
case 1:P2=0x01;break;
case 2:P2=0x02;break;
case 3:P2=0x04;break;
case 4:P2=0x08;break;
case 5:P2=0x10;break;
case 6:P2=0x20;break;
case 7:P2=0x40;break;
case 8:P2=0x80;break;
}
switch(number)
{
case 0:P0 = 0xC0;break;
case 1:P0 = 0xF9;break;
case 2:P0 = 0xA4;break;
case 3:P0 = 0xB0;break;
case 4:P0 = 0x99;break;
case 5:P0 = 0x92;break;
case 6:P0 = 0x82;break;
case 7:P0 = 0xF8;break;
case 8:P0 = 0x80;break;
case 9:P0 = 0x90;break;
}
Delay(3);
}
void main(){
int i;
while(1){
for(i = 1;i<10;i++){
smgca(i,i);
}
}
}
#include <REGX52.H>
unsigned char g_number[10]={
0xC0,
0xF9,
0xA4,
0xB0,
0x99,
0x92,
0x82,
0xF8,
0x80,
0x90
};
unsigned char g_local[8]={
0x01,
0x02,
0x04,
0x08,
0x10,
0x20,
0x40,
0x80,
};
void main(){
int i=0;
int l=0;
int nu[6];
int n=0;
unsigned int count=0;
while(1){
for(i = 1;i<999999;i++){
nu[0]=i%10;
nu[1]=i/10%10;
nu[2]=i/100%10;
nu[3]=i/1000%10;
nu[4]=i/10000%10;
nu[5]=i/100000%10;
count+=1;
if (count>2){
count=0;
}
if(count==1){
P0 = 0xFF;
P2= g_local[l];
n=nu[5-l];
P0= g_number[n];
l+=1;
}
if(l>=6){
l=0;
}
}
}
}
标签:__,case,P0,C51,int,P2,number,break,数码管
From: https://www.cnblogs.com/zdjvimrc/p/16902704.html