烧写程序显示成功,但是板子没反应
在开发板上使用时,是成功地,然后烧写的时候也是成功了,但是自己的板子上没有反应是什么原因,程序如下:#include<reg51.h>
#include<math.h>
#include<string.h>
#define uchar unsigned char
#define uint unsigned int
uint d=0,h=0,temper,band_value;
uchar num;
uchar Set_Temper;
uchar code a[16]="Set:";
uchar code b[16]="Now:";
/*sbit LCD_RS=P0^0;
sbit LCD_RW=P0^1;
sbit LCD_E=P0^2; */
sbit LCD_RS = P1^0;//根据实际情况来。
sbit LCD_RW = P1^1;
sbit LCD_E = P1^2;
//原来是P2端口的第二个
sbit dula = P2^6;//可以去掉
sbit wela = P2^7;//可以去掉
/***********延时函数*********/
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/**********************LCD1602***********************/
/*****LCD1602写命令******/
void write_command(uchar command)
{
delay(5);
LCD_RS=0;
LCD_RW=0;
LCD_E=1;
P0=command;
delay(5);
LCD_E=0;
}
/********LCD写数据函数*********/
void write_date(uchar date)
{
delay(5);
LCD_RS=1;
LCD_RW=0;
LCD_E=1;
P0=date;
delay(5);
LCD_E=0;
}
/*********LCD1602初始化***********/
void LCD_intinal(void)
{
uchar num;
write_command(0x38);//设置8位格式,2行,5x7
write_command(0x0c);//整体显示,关光标,不闪烁
write_command(0x06);//设定输入方式,增量不移位
write_command(0x01);//清除屏幕显示
write_command(0x80);
for(num=0;num<4;num++)//在第一行写入Set:
{write_date(a[num]);
delay(5);}
delay(10);
write_command(0x80+0x40);
for(num=0;num<4;num++)//在第二行写Now:
{write_date(b[num]);
delay(10);}
delay(10);
}
/********************************/
void writeString(uchar * str, uchar length)
{
uchar i;
for(i = 0; i < length; i++)
{
write_date(str[i]);
}
}
/***********18B20相关*************************************/
sbit ds = P3^0;//ds即为DQ
void dsInit()
{
unsigned int i;
ds = 0;
i = 100;
while(i>0) i--;
ds = 1;
i = 4;
while(i>0) i--;
}
void dsWait()//等待延时
{
unsigned int i;
while(ds);
while(~ds);
i = 4;
while(i > 0) i--;
}
bit readBit()//读一个字节
{
unsigned int i;
bit b;
ds = 0;
i++;
ds = 1;
i++; i++;
b = ds;
i = 8;
while(i>0) i--;
return b;
}
unsigned char readByte()
{
unsigned int i;
unsigned char j, dat;
dat = 0;
for(i=0; i<8; i++)
{
j = readBit();
dat = (j << 7) | (dat >> 1);
}
return dat;
}
void writeByte(unsigned char dat)
{
unsigned int i;
unsigned char j;
bit b;
for(j = 0; j < 8; j++)
{
b = dat & 0x01;
dat >>= 1;
if(b)
{
ds = 0; i++; i++;
ds = 1;
i = 8; while(i>0) i--;
}
else
{
ds = 0;
i = 8; while(i>0) i--;
ds = 1;
i++; i++;
}
}
}
void sendChangeCmd()
{
dsInit();
dsWait();
delay(1);
writeByte(0xcc);
writeByte(0x44);
}
void sendReadCmd()
{
dsInit();
dsWait();
delay(1);
writeByte(0xcc);
writeByte(0xbe);
}
int getTmpValue()
{
unsigned int tmpvalue;
int value;
float t;
unsigned char low, high;
sendReadCmd();
low = readByte();
high = readByte();
tmpvalue = high;
tmpvalue <<= 8;
tmpvalue |= low;
value = tmpvalue;
\
t = value * 0.0625;
\
value = t * 100 + (value > 0 ? 0.5 : -0.5); //大于0加0.5, 小于0减0.5
return value;
}
void display(int v)
{
unsigned char count;
unsigned char datas[] = {0, 0, 0, 0, 0};
unsigned int tmp = abs(v);
datas[0] = tmp / 10000;
datas[1] = tmp % 10000 / 1000;
datas[2] = tmp % 1000 / 100;
datas[3] = tmp % 100 / 10;
datas[4] = tmp % 10;
write_command(0xc0+4);
if(v < 0)
{
writeString("- ", 2);
}
else
{
writeString("+ ", 2);
}
if(datas[0] != 0)
{
write_date('0'+datas[0]);
}
for(count = 1; count != 5; count++)
{
write_date('0'+datas[count]);
if(count == 2)
{
write_date('.');
}
}
}
/**//*****************************DS18B20*******************************/
void main()
{
LCD_intinal();
while(1)
{
delay(100); //温度转换时间需要750ms以上
write_command(0xc5);
display(getTmpValue());
sendChangeCmd();
}
}
原理图如下:
求解