PIC16F84A was a popular embedded controller in the last decades. It comes with only basic MCU components without ADC/DAC, hardware PWM etc.
Some temperature sensor such as LM35 or PTC have only analog output, need an ADC module of MCU to the convert temperature data.
DS18B20 is a digital temperature sensor, interface to the MCU only one digital pin. But the communication protocol is such complex.
CCS PICC compiler has a built in library for DS1920 digital thermometer. The ds1920 has a similar data format with DS18B20.
In this case, I use ds18B20 which nearly identical to ds18S20. But ds18B20 has more precise floating point number.
The driver file touch.c is a ready to use library come with CCS PICC after the installation. It has reset(), read(), and write() function to
process the one-wire bus data.
Source Code written in CCS PICC, could be downloaded here:
#include <16F84A.h>
#fuses XT
#use delay(clock=4000000)
#define LCD_ENABLE_PIN PIN_B3
#define LCD_RS_PIN PIN_B1
#define LCD_RW_PIN PIN_B2
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <lcd.c>
#include <touch.c>
#include <string.h>
#include <stdlib.h>
#define RELAY PIN_A0
#define TEMP 30
void main() {
byte buffer[2];
lcd_init();
set_tris_a(0x00);
output_a(0x00);
while (TRUE) {
if(touch_present()) {
touch_write_byte(0xCC);
touch_write_byte (0x44);
output_high(TOUCH_PIN);
delay_ms(2000);
touch_present();
touch_write_byte(0xCC);
touch_write_byte (0xBE);
buffer[0] = touch_read_byte();
buffer[1] = touch_read_byte();
buffer[0]=(buffer[1]<<5)|(buffer[0]>>3);
lcd_gotoxy(1,1);
LCD_PUTC("TEMPERATURE:");
lcd_gotoxy(1,2);
printf(LCD_PUTC,"%c",(buffer[1]&0b11111000)?'-':' ');
if(buffer[1]&0b11111000) buffer[0]=-buffer[0];
lcd_gotoxy(2,2);
printf(LCD_PUTC,"%d.%c C",buffer[0]/2,((buffer[0])&0x01)?'5':'0');
delay_ms (500);
lcd_putc(" ");
if((buffer[0]/2)>TEMP) output_high(RELAY);
else output_low(RELAY);
}
}
}
No comments:
Post a Comment