我下了你的C程序怎么在我的keil51上运行不了 我是才开始学的 麻烦高手指点一下.谢谢! 下面的程序在这个仿真图上运行是在什么问题??
#include <reg51.h> #include <intrins.h> #define uint unsigned int #define uchar unsigned char sbit DQ=P3^3; uint lp,hp,a,b,shi,ge,xs; void Delay(uint num); DS18B20_init(void); eadOneChar(void) ; WriteOneChar(uchar dat) ; Read_Temperature(void); Disp_Temperature() ; void Delay1mS(unsigned int tt); uchar code LEDData[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
bit flag_init=0;
void main(void) {
DS18B20_init(); while(1) { Read_Temperature(); Disp_Temperature();
}
} DS18B20_init(void) { flag_init=1; DQ = 1; _nop_();
DQ = 0; Delay(52); DQ= 1; Delay(5); flag_init= DQ; Delay(25); } Readonechar(void) { uchar i = 0; uchar dat = 0; for (i = 8; i > 0; i--) { DQ = 0; dat >>= 1; DQ = 1;
if(DQ) dat |= 0x80; Delay(5); } return (dat); } WriteOneChar(uchar dat) { uchar i = 0; for (i = 8; i > 0; i--) { DQ = 0; DQ = dat&0x01; Delay(5); DQ = 1; dat>>=1; } } Read_Temperature(void) {
DS18B20_init(); WriteOneChar(0xcc); WriteOneChar(0x44); DS18B20_init(); WriteOneChar(0xcc); WriteOneChar(0xbe); lp=Readonechar(); hp=Readonechar(); hp<<=8; hp|=lp; a=hp*625/10000; b=a*10+5/10; shi=b/100; ge=b/10%10; xs=b%10;
} Disp_Temperature() { P2=0xfe; P0=LEDData [shi]; Delay1mS(5); P2=0xfd; P0=LEDData [ge]|0x80; Delay1mS(5); P2=0xfb; P0=LEDData [xs]; Delay1mS(5); }
void Delay1mS(unsigned int tt) { unsigned char i; while(tt--) { for(i=113;i>0;i--); } }
void Delay(uint num) { while( --num ); }
|