新手刚学习,按照教程自己编写的程序老是没有达到效果。程序如下
单片机源程序如下:
- #include<reg52.h>
- sbit led1=P2^2;
- sbit led2=P2^3;
- sbit led3=P2^4;
- unsigned char code LEDchar[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- unsigned int i,j;
- void shumaguan()
- {
- for(i=0;i<8;i++);
- {
- switch(i)
- {
- case(0):
- led1=1;led2=1;led3=1;break;
- case(1):
- led1=1;led2=1;led3=0;break;
- case(2):
- led1=1;led2=1;led3=0;break;
- case(3):
- led1=1;led2=0;led3=1;break;
- case(4):
- led1=1;led2=0;led3=0;break;
- case(5):
- led1=0;led2=1;led3=1;break;
- case(6):
- led1=0;led2=1;led3=0;break;
- case(7):
- led1=0;led2=0;led3=1;break;
- }
- P0=LEDchar[i];
- for(j=0;j<1000;j++);
- P0=0x00;
- }
- }
- void main()
- {
- while(1)
- {
- shumaguan();
- }
- }
复制代码
最后数码管就显示一个8
|