If valore_ra1 =riferimento THEN segno = $20 Temperatura=abs(valore_ra1 - riferimento) Valore_ra1= (valore_ra1*10) */ quantizza 'quantizzazione Loop: loop: ADCIN 1, valore_ra1 'inizia conversione su ra1Īdcin 2, valore_ra2 ' inizia la conversione su ra2 TRISA = %11111111 ' Setta tutte le PORTA come inputĪDCON1 = %10000010 ' Setta la PORTA come analogica e giustifica il risult a destra Temperatura var word 'variabile per calcolo temp Valore_ra2 var word 'riusltato della conv.
Valore_ra1 var word 'risultato della conv.
' Data Memory Code DEVICE pic16F876, PROTECT_OFFĭefine ADC_BITS 10 ' Set number of bits in resultĭefine ADC_CLOCK 3 ' Set clock source (3=rc)ĭefine ADC_SAMPLEUS 50 ' Set sampling time in uS This is my code with a ref at 2,5 v and not zero, so you must subtract the read value at 25000 (2,5 v) for read negative DEVICE pic16F876, WDT_OFF With 10 bits conversion you must divide by 1250. Maybe you don't have considered the quantization I was wondering what was the problem cos the code looks OK for me. I decided to remove the output of LM35DZ from PIC and measure the output voltage again, which is the correct now, 0.28V (28 deg C). The output of LM35DZ is direct input to AN0, when I measured the output voltage of LM35DZ, it is 4.06V. LCD is working fine, by showing the word "Temp =", but the reading of temperature is wrong, which is "417C"! Since I am new, so I started by doing the simple thing, which is to show the temperature reading of single LM35DZ using a LCD. When there is huge difference of reading between atmospheric temperature with any of the temperature sensor inside, PIC16F877A will turn on a buzzer. I'm working on a project which I was required to use several temperature sensors (LM35DZ) to measure the temperature inside each room and another temperature sensor to measure the atmospheric temperature. The following C code is for mikroC PRO for PIC compiler, it was tested with version 7.2.0.Hi, I'm new here and new to PICBasic as well. Interfacing PIC12F1822 microcontroller with I2C LCD C code: In this project the PIC12F1822 microcontroller runs with its internal oscillator 8 MHz, MCLR pin is configured as an input pin. PCF8574A can be used instead of the PCF8574, the I2C address becomes: 0x7E.
The 10k ohm resistors for A2, A1 and A0 are optional and each pin can be connected directly to +5V. SDA and SCL pins of the PIC12F1822 MCU are connected to SDA (#15) and SCL (#14) pins of the PCF8574 I/O expander respectively.Ī2, A1 and A0 pins of the PCF8574 are connected to +5V (each one through 10k resistor) which means the I2C address of the PCF8574 (therefor the I2C LCD) is: 0 1 0 0 A2 A1 A0 0 = 0 1 0 0 1 1 1 0 = 0x4E. The PIC12F1822 microcontroller has one hardware I2C module with SDA on pin RA2 (#5) and SCL on pin RA1 (#6). (All grounded terminals are connected together) Interfacing PIC12F1822 microcontroller with I2C LCD circuit:Įxample circuit schematic diagram is shown in the image below. 10k ohm variable resistor or potentiometer.PCF8574 I/O expander (or PCF8574A) -> PCF8574 datasheet.PIC12F1822 microcontroller -> datasheet.The components listed below are required for this project. PIC MCU with I2C LCD and DS3231/DS1307 RTC | mikroC Projects
I2C LCD driver for mikroC PRO for PIC compiler
This driver is just a C file named (with extension) I2C_LCD.c, we’ve to add this file to project folder, download link is below: An I2C LCD driver for mikroC PRO for PIC compiler is required to simplify example C code. The compiler used in this project is mikroElektronika mikroC PRO for PIC. This project works also with DFRobot I2C LCD displays. This small post shows an example for connecting LCD (with HD44780 or complaint controller) with Microchip PIC12F1822 8-bit microcontroller, this microcontroller has only 8 pins of which 5 can be used as outputs, therefore an I2C LCD is required. The I2C LCD is connected with the microcontroller via 2 lines: SDA (serial data) and SCL (serial clock). Adding the I2C I/O expander builds an I2C LCD.
Number of pins needed for the LCD can be reduced to 2 by using an I2C I/O (Input/Output) expander like PCF8574 or PCF8574A. Interfacing LCD display with PIC microcontroller requires at least 6 data pins (for LCD pins: RS, E, D4, D5, D6 and D7).