还是昨天的问题,这两个程序分别如下:
这两个程序唯一的差别在于程序一循环有两个,程序二循环是一个。
但是运行的结果是程序一单片机并不变化,程序二单片机可以正常变化数字
而且通过电压表可以看出,虽然程序赋值相同,这两个单片机空闲接口电压根本不一样
这个问题困扰我很长时间了,谁能解答一下?不胜感激!
程序一:
- #include<reg51.h>
- #define uchar unsigned char
- xdata uchar num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- void delay(uchar i)
- {
- uchar t;
- while(i--)
- {
- for(t=0;t<120;t++);
- }
- }
- void main()
- {
- uchar i;
- while(1)
- {
- for(i=0;i<10;i=i+2)
- {
- P2=num[i];
- delay(500);
- }
- for(i=0;i<10;i++)
- {
- P2=num[i];
- delay(500);
- }
- }
- }
- 程序二:
- #include<reg51.h>
- #define uchar unsigned char
- uchar code num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- void delay(uchar i)
- {
- uchar t;
- while(i--)
- {
- for(t=0;t<120;t++);
- }
- }
- void main()
- {
- uchar i;
- while(1)
- {
- for(i=0;i<10;i++)
- {
- P2=num[i];
- delay(500);
- }
- }
- }
复制代码 |