数码管显示0-9
#include "reg52.h"
unsigned char code duanma[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90};
void SelectHC573(unsigned char n){
switch(n)
{
case 4:
P2 = (P2 & 0x1f) | 0x80;
break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;
break;
case 6:
P2 = (P2 & 0x1f) | 0xc0;
break;
case 7:
P2 = (P2 & 0x1f) | 0xe0;
break;
}
}
void delay(unsigned int t){
while(t--);
while(t--);
while(t--);
}
int i;
void show(){
SelectHC573(6);
P0=0xff;
for(i=0;i<10;i++){
SelectHC573(7);
P0 = duanma[i];
delay(90000);
}
}
void initSystem(){
SelectHC573(4);
P0=0xff;
SelectHC573(5);
P0=0x00;
}
int main(){
initSystem();
while(1){
show();
}
}