郭天祥的《51
单片机C语言教程》书上例6.6.1
file:///C:Documents and Set
tingsAdministratorApplication DataTencentUsers768125236QQWinTempRichOle\%PU(I}R]5(TO{BAVSA{X$ZC.jpg
调试下面的程序就出现上面的情况,连hex文件都生成不了,不知道怎么回事们请指点迷津!!!
#include<reg52.h>
#include<intrins.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^6;
sbit adrd=P3^7;
uchar flag,a;
unsigned char num,flag1,flagt,ad_val;
float ad_vo;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x21;
SCON=0x50;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TH1=0xfd;
TL1=0xfd;
TR1=1;
ET0=1;
// SM0=0;
// SM1=1;
// REN=1;
EA=1;
ES=1;
}
void display(uint temp)
{
uchar a1,a2,a3;
a1=temp/100;
a2=(temp%100)/10;
a3=temp%10;
dula=1;
P0=table[a1];
dula=0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delay(5);
dula=1;
P0=table[a2];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delay(5);
dula=1;
P0=table[a3];
dula=0;
P0=0xff;
wela=1;
P0=0x7b;
wela=0;
delay(5);
}
uchar get_ad()
{
uchar adval;
adwr=1;
_nop_();
adwr=0;
_nop_();
adwr=1;
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
return adval;
}
void main()
{
init();
wela=1;
P0=0x7f;
wela=0;
while(1)
{
if(flag==1)
{
flag=0;
ES=0;
TI=1;
switch(flag1)
{
case 0:puts("turn on ad!
");
TR0=1;
break;
case 1:printf("turn off ad!
");
TR0=0;
break;
case 2:puts("error!
");
break;
}
while(!TI);
TI=0;
ES=1;
}
if(flagt==1)
{
flagt=0;
ad_val=get_ad();
ad_vo=(float)ad_val*5.0/256.0;
ES=0;
TI=1;
printf("The voltage is %fV
",ad_vo);
while(!TI);
TI=0;
ES=1;
}
display(ad_val);
}
}
void time0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
num++;
if(num==20)
{
num=0;
flagt=1;
} ;
}
void ser()interrupt 4
{
RI=0;
a=SBUF;
flag=1;
if(a==1)
flag1=0;
else if(a==2)
flag1=1;
else
flag1=2;
}
一周热门 更多>