数组里面的元素会出现错误,求帮忙
- <div>#include<reg51.h></div><div>#define uchar unsigned char <span class="Apple-tab-span" style="white-space:pre"> </span> //用uchar替换unsigned char</div><div>#define uint unsigned int<span class="Apple-tab-span" style="white-space:pre"> </span> //用uint替换unsigned int</div><div>#define ulong unsigned long</div><div>uchar t0;</div><div>bit new_s;</div><div>unsigned char code LEDCode[] = {0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0x11,0xc1,0x63,0x85,0x61,0x71}; </div><div>void delay(uint z)<span class="Apple-tab-span" style="white-space:pre"> </span>//延时函数</div><div>{</div><div> uint x, y;</div><div> for(x = z; x > 0; x--) for(y = 100; y > 0; y--);</div><div>}</div><div>void Init(void)<span class="Apple-tab-span" style="white-space:pre"> </span> //初始化函数</div><div>{</div><div> TMOD=0x01; //设置定时器0工作再方式1</div><div> TR0=1; //启动定时器0,TR0必须置1</div><div> ET0=1; //开定时器中断</div><div> EA=1; //开总中断</div><div>}</div><div>uchar xdata alaclock_hour[4]=</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> 0x01,0x02,0x03,0x04</div><div>
- </div><div>};</div><div>int main(void)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>uchar temp;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> while(1) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> </div><div> </div><div>
- </div><div> P1 = 0xfe;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[0]];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P1 = 0xfd;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[1]];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P1 = 0xfb;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[2]];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div><div>
- </div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> } </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;</div><div>}</div>
如果把代码修改一下
- <div> P1 = 0xfe;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[0]/255];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P1 = 0xfd;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[1]/127];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P1 = 0xfb;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>P0 = LEDCode[alaclock_hour[2]/63];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>delay(20);</div>
说明 数组里面的元素都是 255
#include<reg51.h>
#define uchar unsigned char //用uchar替换unsigned char
#define uint unsigned int //用uint替换unsigned int
#define ulong unsigned long
uchar t0;
bit new_s;
unsigned char code LEDCode[] = {0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09,0x11,0xc1,0x63,0x85,0x61,0x71};
void delay(uint z) //延时函数
{
uint x, y;
for(x = z; x > 0; x--) for(y = 100; y > 0; y--);
}
void Init(void) //初始化函数
{
TMOD=0x01; //设置定时器0工作再方式1
TR0=1; //启动定时器0,TR0必须置1
ET0=1; //开定时器中断
EA=1; //开总中断
}
uchar xdata alaclock_hour[4]=
{
0x01,0x02,0x03,0x04
};
int main(void)
{
uchar temp;
while(1)
{
P1 = 0xfe;
P0 = LEDCode[alaclock_hour[0]];
delay(20);
P1 = 0xfd;
P0 = LEDCode[alaclock_hour[1]];
delay(20);
P1 = 0xfb;
P0 = LEDCode[alaclock_hour[2]];
delay(20);
}
return 0;
}
P1 = 0xfe;
P0 = LEDCode[alaclock_hour[0]/255];
delay(20);
P1 = 0xfd;
P0 = LEDCode[alaclock_hour[1]/127];
delay(20);
P1 = 0xfb;
P0 = LEDCode[alaclock_hour[2]/63];
delay(20);