新手学习51单片机,虽然编译没问题,可是烧到板子里没反应,不知道是哪里出了问题,求指教 #include<reg51.h>
#include<math.h>
#include<intrins.h>
unsigned char code tab[]={0x3f,0x06,0x5b,
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39
,0x5e,0x79,0x71,0x00,0x40};
sbit DQ=P3^3;
unsigned char dat;
unsigned char tempL=0;
unsigned char tempH=0;
float temperature;
void delay(unsigned int count){
unsigned int i;
i=0;
while(i<count){
i++;
}return;
}
void delay1(void){
int k;
for(k=0;k<400;k++);
}
void display(int k){
P2=0xfe;
P0=tab[k/1000];
delay1();
P2=0xfd;
P0=tab[k%1000/100];
delay1();
P2=0xfb;
P0=tab[k%100/10];
delay1();
P2=0xf7;
P0=tab[k%10];
delay1();
P2=0xff;}
void init(){
unsigned char x=0;
DQ=1;
delay(8);
DQ=0;
delay(85);
DQ=1;
delay(14);
}
unsigned char readone(){
unsigned char i=0;
unsigned char dat=0;
for(i=8;i>0;i--){
DQ=1;
delay(1);
DQ=0;
dat>>=1;
DQ=1;
if(DQ){
dat|=0x80;
delay(4);
}
}return(dat);
}
void writeone(unsigned char dat){
unsigned char i=0;
for(i=8;i>0;i--){
DQ=0;DQ=dat&0x01;
delay(5);
DQ=1;
dat>>=1;
}
delay(4);}
readtem(void){
init();
writeone(0xcc);
writeone(0x44);
delay(125);
init();
writeone(0xcc);
writeone(0xbe);
tempL=readone();
tempH=readone();
temperature=((tempH*256)+tempL)*0.0625;
delay(200);
return(temperature);
}
void main(){
float i;
while(1){
i=readtemperature();
display(i);}} |