用keil μVision V5.14.2 编写以下程序,
#define uchar unsigned char
#define uint unsigned int
#include <reg51.h>
#include <stdio.h>
void delay(void)
{
uchar a, b,C;
for (a = 20; a>0; a--)
for (b =20; b>0; b--)
for (C =248; C>0; C--);
}
void main()
{
while(1)
{
P2|=0x01;
delay();
P2&=~0x01;
delay();
}
}
能正常运行,结果正常。
可是程序写成下面这样,就是死活不运行,LED不显示或乱显示,板子确认是OK的,用别的芯片试过了!
#define uchar unsigned char
#define uint unsigned int
#include <reg51.h>
#include <stdio.h>
const uchar code tab[16]={0x81,0xf5,0x49,0x61,0x35,0x23,0x03,0xf1,0x01,0x21,0x11,0x07,0x8b,0x45,0x0b,0x1b};
void delay (uint ms)
{
uint i,j;
for (i=0;i<ms;i++)
{
for (j=0;j<1141;j++);
}
}
void ledshow (uchar ten,uchar one)
{
P2|= 0x01;
P0 = tab[one];
delay(10);
P2&=~0x01;
P2|= 0x02;
P0 = tab[ten];
delay(10);
P2&=~0x02;
}
int main (void)
{
uchar one=0,ten=0;
uchar enc_bef=0;
delay(1);
while(1)
{
one=counter%10;
ten=counter/10%10;
ledshow(ten,one);
}
}
|