#include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar code temp[]={0x80,0xe3,0x44,0x41,0x23,0x11,0x10,0xc3,0x00,0x01};//数码管由0~9的显示 char code b[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, 0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff, 0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//流水灯先是逐个闪动,后反向闪动,再全部闪动,再反向全部闪动。 void delay(uint time)//延时函数 { while(time--); } void main() //主函数 { uint k,l; uchar i,j; j=0; while(1) { for(i=0;i<10;i++) { P1=temp; P2=b[j]; for(l=0;l<100;l++) for(k=0;k<5;k++) delay(10); j++; if(j==38)j=0; } } } 缺点:单片机两个IO口不能同时独立工作!