📄 main.c
字号:
//
#include "REG52.h"
#include "LedLib.h"
#include "SensorLib.h"
void main(void){
unsigned char tempL,tempH;//the low byte and the high byte for the temperature
char temperature;//store the final result for the convertion
unsigned char ledTemp;
unsigned char bitCount;
unsigned int i;
bit minus;
//for debug
//unsigned char tmp;
//first we setting up the sensor
resetSensor();
writeSensor(SKIP_ROM);//skip search ROM, address all the ROM present on the bus
writeSensor(WRITE_RAM);//start to configuring the sensor
writeSensor(0x64);//Th = 100C
writeSensor(0x8a);//Tl = -10C
writeSensor(0x1f);//9 bit resolution,0.5C increasment
/*
//for debug
resetSensor();
writeSensor(READ_ROM);
tmp = readSensor();
readSensor();
readSensor();
resetSensor();
for(;1;){
ledTemp = tmp;
bitCount = 0;
do{
ledSetDigit((ledTemp % 10),bitCount,0);
ledTemp = ledTemp / 10;
bitCount ++;
}while(ledTemp != 0);
}
*/
//the whole program is a infinited loop
//we read the temperature sensor, and then send it to the led
for(;1;){
resetSensor();//reset the sensor
writeSensor(SKIP_ROM);//skip search ROM, address all the ROM present on the bus
writeSensor(CONVERT_T);//start temperature convert
for(i = 0;i < 1000;i++){//we show up the last result while we are waiting for the convertion
ledTemp = temperature;
if(minus == 1){
ledSetDigit(5,0,0);//set digit 5
}else{
ledSetDigit(0,0,0);//set digit 5
}
bitCount = 1;
do{
if(bitCount == 1){
ledSetDigit((ledTemp % 10),bitCount,1);
}else{
ledSetDigit((ledTemp % 10),bitCount,0);
}
ledTemp = ledTemp / 10;
bitCount ++;
}while(ledTemp != 0);
if(temperature < 0){
ledSetDigit(10,bitCount,0);
}
}
resetSensor();//reset the sensor
writeSensor(SKIP_ROM);//skip search ROM, address all the ROM present on the bus
writeSensor(READ_RAM);//read out the result
tempL = readSensor();//read out the higher byte for the temperature
tempH = readSensor();//read out the lower bute for the temperature
if(tempL & 0x08){
minus = 0x1;
}else{
minus = 0x0;
}
temperature = tempH << 4;
temperature = temperature + ((tempL & 0xf0) >> 4);
temperature = temperature - 10;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -