用KEIL软件调试程序的时候,显示程序跳过了红色方框里的三段程序!这是什么原因?难道是KEIL软件把这段程序优化了?如果是被优化了,那怎么使这段程序不被优化?求大神出招!
如图所示:
我给程序加了volatile,就解决了两条语句,但剩下一条不知道怎么解决!
完整代码如下:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P2^0;
sbit lcdrw=P2^1; //static
sbit lcdrs=P2^2;
sbit trig=P1^3;
sbit echo=P1^2;
uint n,val,bai,shi,ge;
uchar code table[]="The distant is:";
uchar code table1[]="cm";
uint code table2[]=
{0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
/*void t1_init()
{
TMOD=0x11;
TH1=0xfe;
TL1=0x73;
ET1=1;
EA=1;
}*/
void delay_nms(volatile uint nms)
{
uint n,m;
for(n=nms;n>0;n--)
for(m=110;m>0;m--);
}
void lcd_writecom(volatile uchar com)
{
lcdrs=0;
lcdrw=0;
P0=com;
delay_nms(5);
lcden=1;
delay_nms(5);
lcden=0;
}
void lcd_writedata(volatile uchar date)
{
lcdrw=0;
lcdrs=1;
P0=date;
delay_nms(5);
lcden=1;
delay_nms(5);
lcden=0;
}
void lcd_init()
{
lcden=0;
lcd_writecom(0x38);
lcd_writecom(0x0c);
lcd_writecom(0x06);
lcd_writecom(0x01);
}
void lcd_display()
{
uchar num;
lcd_writecom(0x80);
for(num=0;num<15;num++)
{
lcd_writedata(table[num]);
delay_nms(5);
}
/* lcd_writecom(0x80+0x40);
lcd_writedata(table2[val/100]);
delay_nms(5);
lcd_writedata(table2[val%100/10]);
delay_nms(5);
lcd_writedata(table2[val%10]);
delay_nms(5);
for(num=0;num<2;num++)
{
lcd_writedata(table1[num]);
delay_nms(5);
} */
while(1);
}
/*void sentultrasound()
{
trig=0;
echo=0;
trig=1;
delay_nms(1);
trig=0;
while(!echo);
TR1=1;
while(echo);
TR1=0;
val=n*50*(10^6)*34000/2;
} */
void main()
{
//t1_init();
lcd_init();
// sentultrasound();
lcd_display();
}
/*void t1() interrupt 3 //50us定时
{
TH1=0xff;
TL1=0xd8;
n++;
} */
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |