Summary of One wire bus (DS1820) Control For CSS Compiler
This project reads temperature from a DS18B20 sensor using a PIC16F877A microcontroller, converts it to BCD, and displays it via a shift register (74HC595) driven routine. The main loop polls the sensor, updates a value, converts for display, sends data, and repeats with delays.
Parts used in the DS18B20 Temperature Display Project:
- PIC16F877A microcontroller
- DS18B20 temperature sensor (read_ds1820)
- 74HC595 shift register (Shift_595_C.c routines)
- Supporting header/source files: Shift_595_C.c
- Supporting header/source files: read_temp.c (read_ds1820)
- Power supply (suitable for 4 MHz crystal operation)
- Crystal or oscillator providing 4 MHz clock
- Wiring, resistors, and connectors as required for sensor and shift register interfacing
#include <16F877A.h> #device adc=8 #FUSES NOWDT,XT //No Watch Dog Timer #use delay(clock=4000000) #include <Shift_595_C.c> // 25.5 C 0.5 to step #include <read_temp.c>void main(){ setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); set_tris_a(0xff); set_tris_b(0x00); value = 0; display(); delay_ms(100); while(true){ read_ds1820(); value = temp; hex_bcd(value*10); sent_data(); delay_ms(100); } }
- What microcontroller is used in the project?
The PIC16F877A microcontroller is used. - How is the temperature sensor read?
The temperature is read using the read_ds1820 function from read_temp.c which interfaces with the DS18B20 sensor. - How is the temperature value prepared for display?
The code assigns temp to value and calls hex_bcd(value*10) to convert it for display. - How is the display driven?
The display data is sent using routines in Shift_595_C.c and the sent_data function. - What clock speed is the microcontroller configured for?
The microcontroller is configured for a 4 MHz clock via #use delay(clock=4000000). - Are analog inputs enabled in this setup?
No, analog inputs are disabled with setup_adc_ports(NO_ANALOGS) and setup_adc(ADC_OFF). - What I/O directions are set for ports A and B?
Port A is set as input with set_tris_a(0xff) and Port B as output with set_tris_b(0x00). - How often is the temperature updated?
The main loop reads and updates the temperature approximately every 100 ms due to delay_ms(100) calls.
void main(){
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
set_tris_a(0xff);
set_tris_b(0x00);
value = 0;
display();
delay_ms(100);
while(true){
read_ds1820();
value = temp;
hex_bcd(value*10);
sent_data();
delay_ms(100);
}
}