#include<reg52.h> #define uint unsigned int #define uchar unsigned char uchar code temp[]={0x80,0xe3,0x44,0x41,0x23,0x11,0x10,0xc3,0x00,0x01};//數(shù)碼管由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)//延時函數(shù) { while(time--); } void main() //主函數(shù) { 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口不能同時獨立工作!