以下是小弟C51单片机显示交通灯的代码,个人觉得逻辑上没问题,编译也没错误没警告,但是程序跑起来是彻底乱套,于是想通过debug观察其中每一个变量的值,特别是 uchar xianshi[8] 这一个数组中的值,于是我在主函数的第一条语句设置了断点以后,设置了watch1,但是始终没有显示uchar xianshi[8] 中的内容,而是
D:0x0B xianshi[] "" 是什么意思?
以下是小弟我的单片机交通灯代码:
# include "reg52.h"
typedef unsigned int uint;
typedef unsigned char uchar;
sbit traffic = P1;
sbit duanxuan = P0;
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
sbit bao_ren_hong = P1^0;
sbit bao_ren_lv = P1^1;
sbit bao_ma_hong = P1^2;
sbit bao_ma_huang = P1^3;
sbit bao_ma_lv = P1^4;
sbit qian_ma_hong = P1^5;
sbit qian_ma_huang = P1^6;
sbit qian_ma_lv = P1^7;
sbit qian_ren_hong = P3^0;
sbit qian_ren_lv = P3^1;
uchar num = 0;
code uchar smgdx[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴
uchar xianshi[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void delay(uint i)
{
while(i--);
}
void Timer0() interrupt 1
{
static uint a;
TH0 = 0xfc;
TL0 = 0x18;
a++;
if(a==1000) //定时一秒
{
num++;
a = 0;
}
}
void display()
{
uchar j;
for(j=0;j<8;j++)
{
switch(j)
{
//case 0: LSA=0,LSB=0,LSC=0;break;
//case 1: LSA=1,LSB=0,LSC=0;break;
case 2: LSA=0,LSB=1,LSC=0;break;
case 3: LSA=1,LSB=1,LSC=0;break;
//case 4: LSA=0,LSB=0,LSC=1;break;
//case 5: LSA=1,LSB=0,LSC=1;break;
case 6: LSA=0,LSB=1,LSC=1;break;
case 7: LSA=1,LSB=1,LSC=1;break;
}
if(num<31)
{
xianshi[0] = 0x00;
xianshi[1] = 0x00;
xianshi[2] = smgdx[(30-num)/10];
xianshi[3] = smgdx[(30-num)%10];
xianshi[4] = 0x00;
xianshi[5] = 0x00;
xianshi[6] = smgdx[(30-num)/10];
xianshi[7] = smgdx[(30-num)%10];
duanxuan = xianshi[j];
delay(50);
duanxuan = 0x00;
}
if((31<=num)&&(num<36))
{
xianshi[0] = 0x00;
xianshi[1] = 0x00;
xianshi[2] = smgdx[(35-num)/10];
xianshi[3] = smgdx[(35-num)%10];
xianshi[4] = 0x00;
xianshi[5] = 0x00;
xianshi[6] = smgdx[(35-num)/10];
xianshi[7] = smgdx[(35-num)%10];
duanxuan = xianshi[j];
delay(50);
duanxuan = 0x00;
}
if((36<=num)&&(num<66))
{
xianshi[0] = 0x00;
xianshi[1] = 0x00;
xianshi[2] = smgdx[(66-num)/10];
xianshi[3] = smgdx[(66-num)%10];
xianshi[4] = 0x00;
xianshi[5] = 0x00;
xianshi[6] = smgdx[(66-num)/10];
xianshi[7] = smgdx[(66-num)%10];
duanxuan = xianshi[j];
delay(50);
duanxuan = 0x00;
}
if((num<=66)&&(num<71))
{
xianshi[0] = 0x00;
xianshi[1] = 0x00;
xianshi[2] = smgdx[(71-num)/10];
xianshi[3] = smgdx[(71-num)%10];
xianshi[4] = 0x00;
xianshi[5] = 0x00;
xianshi[6] = smgdx[(71-num)/10];
xianshi[7] = smgdx[(71-num)%10];
duanxuan = xianshi[j];
delay(50);
duanxuan = 0x00;
}
}
}
void Timer0_open()
{
TMOD = 0x01;
EA = 1;
ET0 = 1;
TR0 = 1;
TH0 = 0xfc; //定时1ms
TL0 = 0x18;
}
void main()
{
Timer0_open();
while(1)
{
if(num<31)
{
traffic = 0xff; //先让全部交通灯熄灭
bao_ren_hong = 0;
bao_ma_hong = 0;
qian_ma_lv = 0;
qian_ren_lv = 0;
display();
}
if((31<=num)&&(num<36))
{
traffic = 0xff; //先让全部交通灯熄灭
bao_ren_hong = 0;
bao_ma_hong = 0;
qian_ma_huang = 0;
qian_ren_lv = 0;
display();
}
if((36<=num)&&(num<66))
{
traffic = 0xff; //先让全部交通灯熄灭
bao_ren_lv = 0;
bao_ma_lv = 0;
qian_ma_hong = 0;
qian_ren_hong = 0;
display();
}
if((num<=66)&&(num<71))
{
traffic = 0xff; //先让全部交通灯熄灭
bao_ren_lv = 0;
bao_ma_huang = 0;
qian_ma_hong = 0;
qian_ren_hong = 0;
display();
}
if(num==70)
num = 0;
}
}
小弟我就想问一下keil 5 的debug中如何显示一个数组的值,是需要手动输入数组的初值吗? watch 1中显示的D:0x0B xianshi[] "" 是什么意思呢?谢谢各位大佬!
|