数码管最右边一位从0到9无限循环
#include<STC15F2K60S2.H>
#include"intrins.h"
#define uint unsigned int
#define uchar unsigned char
#define led_output P0
#define led_duan_and_wei P2 //定义段选和位选
unsigned char add1,add2;
unsigned int num=52700,index=52700;
uchar code tabe[ ]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//显示1,2,3,4,5,6,7,8,9
uchar code tabe1[ ]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; // 从第八位到第一位
void main( )
{
while(1)
{
num++;
if(num>=52700) //计时
{
num=0;
led_output=tabe1[add2];//位选
led_duan_and_wei=0xdf;//
led_duan_and_wei&=0x1f;//
add2++;
add2&=0xf8;
}
index++;
if(index>=52700)
{
index=0;
led_output=tabe[add1];//È¡ÓàÑ¡ÔñÁÁµÄ¶ÎÑ¡Êý¾Ý
led_duan_and_wei=0xff;//´ò¿ª¶ÎÑ¡¿ØÖÆY7ÐźÅ
led_duan_and_wei&=0x1f; //ÇåÁ㣬¹Ø±ÕU7Ëø´æÆ÷
add1++;
if(add1==10)
{
add1=0;
}
}
}
}