1. Giới thiệu.
- Là cảm biến nhiệt độ cho ra các mức điện áp tương ứng với độ Kelvin
- Sai số +/- 1 độ C
- Hoạt động trong dải từ 400uA - 5 mA
- Trở kháng nội < 1 Ω
- Dải nhiệt độ đo được -55˚C đến 150˚C
2 .Sơ đồ chân.
- Sai số +/- 1 độ C
- Hoạt động trong dải từ 400uA - 5 mA
- Trở kháng nội < 1 Ω
- Dải nhiệt độ đo được -55˚C đến 150˚C
2 .Sơ đồ chân.
ADJ - Chân hiệu chuẩn
V+ - Chân cấp nguồn 5V
V- - Chân GND
V+ - Chân cấp nguồn 5V
V- - Chân GND
- Đây là code chương trình.
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000 // ADC chon tan so thach anh = 4Mhz
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include <xc.h>
#include "lcd.h"
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
void ADCinit (void); // ADC chon tan so thach anh = 4Mhz
unsigned int ReadADC (void);
unsigned int ADCvalue = 0;
float f;
unsigned int voltage;
void main(void)
{
ADCinit();
char s[20];
TRISD = 0x00;
TRISA0 = 1;
Lcd_Init();
while(1)
{
ADCvalue = ReadADC();
voltage = (5000.0f / 1023) * ADCvalue;
//f= 34765.46392/voltage - 4.793814433; //GP2D12 cam bien khoang cach
Lcd_Set_Cursor(1,1);
Lcd_Write_String(" Demo LM335");
f = (voltage / 10) - 273;
sprintf(s,"Temp is = %g ",f);
Lcd_Set_Cursor(2,1);
Lcd_Write_String(s);
Lcd_Write_Char(223);// ky tu
Lcd_Write_String("C");
}
}
void ADCinit (void)// adc
{
// chon tan so clock cho bo adc
ADCON1bits.ADCS2 = 0, ADCON0bits.ADCS1 = 0,ADCON0bits.ADCS0 = 1;
// chon kenh adc la kenh an0
ADCON0bits.CHS2 = 0, ADCON0bits.CHS1 = 0, ADCON0bits.CHS0 = 0;
// chon cach luu data
ADCON1bits.ADFM = 1;
// cau hinh cong vao
ADCON1bits.PCFG3 = 1, ADCON1bits.PCFG2 = 1, ADCON1bits.PCFG1 = 1, ADCON1bits.PCFG0 = 0;
// cap nguon cho khoi adc
ADCON0bits.ADON = 1;
}
unsigned int ReadADC (void)// doc len 7 doan
{
unsigned int TempValue = 0;
ADCON0bits.GO_nDONE = 1;
while(ADCON0bits.GO_nDONE);
TempValue = ADRESH*256 + ADRESL;
return (TempValue);
}
- Link download project. Click here#include <stdlib.h>
#define _XTAL_FREQ 4000000 // ADC chon tan so thach anh = 4Mhz
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include <xc.h>
#include "lcd.h"
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
void ADCinit (void); // ADC chon tan so thach anh = 4Mhz
unsigned int ReadADC (void);
unsigned int ADCvalue = 0;
float f;
unsigned int voltage;
void main(void)
{
ADCinit();
char s[20];
TRISD = 0x00;
TRISA0 = 1;
Lcd_Init();
while(1)
{
ADCvalue = ReadADC();
voltage = (5000.0f / 1023) * ADCvalue;
//f= 34765.46392/voltage - 4.793814433; //GP2D12 cam bien khoang cach
Lcd_Set_Cursor(1,1);
Lcd_Write_String(" Demo LM335");
f = (voltage / 10) - 273;
sprintf(s,"Temp is = %g ",f);
Lcd_Set_Cursor(2,1);
Lcd_Write_String(s);
Lcd_Write_Char(223);// ky tu
Lcd_Write_String("C");
}
}
void ADCinit (void)// adc
{
// chon tan so clock cho bo adc
ADCON1bits.ADCS2 = 0, ADCON0bits.ADCS1 = 0,ADCON0bits.ADCS0 = 1;
// chon kenh adc la kenh an0
ADCON0bits.CHS2 = 0, ADCON0bits.CHS1 = 0, ADCON0bits.CHS0 = 0;
// chon cach luu data
ADCON1bits.ADFM = 1;
// cau hinh cong vao
ADCON1bits.PCFG3 = 1, ADCON1bits.PCFG2 = 1, ADCON1bits.PCFG1 = 1, ADCON1bits.PCFG0 = 0;
// cap nguon cho khoi adc
ADCON0bits.ADON = 1;
}
unsigned int ReadADC (void)// doc len 7 doan
{
unsigned int TempValue = 0;
ADCON0bits.GO_nDONE = 1;
while(ADCON0bits.GO_nDONE);
TempValue = ADRESH*256 + ADRESL;
return (TempValue);
}
EmoticonEmoticon