Ds18b20_ManualConvert();
>
DS18B20_StartAll(&OneWire);
OneWire_Reset(OneWire);
// 리셋
OneWire_WriteByte(OneWire, ONEWIRE_CMD_SKIPROM);
// 전체선택
OneWire_WriteByte(OneWire, DS18B20_CMD_CONVERTTEMP);
// 온도 변환 시작 명령어
>
OneWire_WriteByte(OneWire, ONEWIRE_CMD_SKIPROM);
> // 0xCC : Skip ROM 모든 slave들에게 동시 전송
OneWire_WriteByte(OneWire, DS18B20_CMD_CONVERTTEMP);
> // 0x44 : function 명령어 > convert T : 온도 변화의 시작
// 신호선 > HIGH 진행 <> (외부전원)진행 : 0, 완료 : 1
while (!DS18B20_AllDone(&OneWire))
//진행중 > !0 > 1
//완료 > !1 > 0
{
Ds18b20Delay(10); // 10ms 씩 딜레이
Ds18b20Timeout-=1; // 500
if(Ds18b20Timeout==0) // >> 5000 ms
break;
}
>
if(Ds18b20Timeout>0)
// 완료가 되면 이전 while문 종료> if문 안으로 들어옴
>
DS18B20_Read(&OneWire, ds18b20[i].Address, &ds18b20[i].Temperature);
>
bool DS18B20_Read(OneWire_t* OneWire, uint8_t *ROM, float *destination)
>// 온도정보 읽어옴
if (!DS18B20_Is(ROM)) : 0x28 이 아니면 false
OneWire_SelectWithPointer(OneWire, ROM);
if (temperature & 0x8000) // 음수면 > 1
// 2의보수 MSB : 1
digit = temperature >> 4; // 소수점 4칸을 제외한 나머지 > 정수
decimal = temperature & 0x0F; // 0~4bit 소수점
> decimal = digit + decimal;
>
&ds18b20[i].Temperature = destination
>
*destination = ds18b20[i].Temperature = decimal;
'임베디드 > 고추건조기' 카테고리의 다른 글
난방실 만들기 (0) | 2024.12.11 |
---|---|
릴레이 모듈 (0) | 2024.12.10 |
Rom search (0) | 2024.12.07 |
1-wire, 프로토콜 (0) | 2024.12.06 |
온도센서 (0) | 2024.12.05 |