#include <htc.h>
#include <stdio.h>
#include "lcd.h"
__CONFIG(FOSC_INTRC_NOCLKOUT&MCLRE_ON*WDTE_OFF&LVP_OFF);
#define _XTAL_FREQ 4000000
unsigned char temp;
//--------------------------------
//KHOI TAP PORT
void port_init()
{
ANSEL|=1<<3;
ANSELH|=0; //RA3 LA INPUT
TRISA3=1;
TRISB=0X00; //PORTB LA OUTPUT
PORTB=0X00;
TRISE=0X00;
PORTE=0X00;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
}
//-------------------------------
void adc_init()
{
ADCS1=1; //CHON TAN SO LAY MAU
ADCS0=0; //suy ra toc do chuyen doi ADC la Fosc/32.
VCFG1=0; // chon dien ap lay mau la dien ap noi
VCFG0=0;
CHS3=0;
CHS2=0; //chon kenh AN3
CHS1=1;
CHS0=1;
ADFM=1; //CHON DINH DANG KET QUA ADC
ADON=1; //KET QUA DICH PHAI
}
//-------------------------
void interrupt_init()
{
PEIE=1; //VI NGAT NGOAI VI NEN SET=1
ADIF=0;
ADIE=1;
}
//---------------------------
void interrupt isr()
{
unsigned long read_adc;
if(ADIE&&ADIF)
{
ADIF=0;
read_adc=(ADRESH<<8)|ADRESL;
read_adc=read_adc*5000/1024;
temp=read_adc/10;
}
}
//------------------------------------------
void lcd_adc(unsigned char i)
{
char a,b,c,d;
a=i/1000;
b=(i-a*1000)/100;
c=(i-a*1000-b*100)/10;
d=i-a*1000-b*100-c*10;
lcd_putc(a+0x30);
lcd_puts(".");
lcd_putc(b+0x30);
lcd_putc(c+0x30);
lcd_putc(d+0x30);
lcd_puts(" C");
}
//-----------------------------
void main()
{
port_init();
adc_init();
interrupt_init();
lcd_init();
__delay_ms(100);
while(1)
{
lcd_clear();
lcd_puts("DO NHIET DO=LM35");
lcd_gotoxy(4,1);
lcd_adc(temp);
GO_nDONE;
__delay_ms(100);
}
}
#include <htc.h>
#include <stdio.h>
#include "lcd.h"
__CONFIG(FOSC_INTRC_NOCLKOUT&MCLRE_ON*WDTE_OFF&LVP_OFF);
#define _XTAL_FREQ 4000000
unsigned char temp;
//--------------------------------
//KHOI TAP PORT
void port_init()
{
ANSEL|=1<<3;
ANSELH|=0; //RA3 LA INPUT
TRISA3=1;
TRISB=0X00; //PORTB LA OUTPUT
PORTB=0X00;
TRISE=0X00;
PORTE=0X00;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
}
//-------------------------------
void adc_init()
{
ADCS1=1; //CHON TAN SO LAY MAU
ADCS0=0; //suy ra toc do chuyen doi ADC la Fosc/32.
VCFG1=0; // chon dien ap lay mau la dien ap noi
VCFG0=0;
CHS3=0;
CHS2=0; //chon kenh AN3
CHS1=1;
CHS0=1;
ADFM=1; //CHON DINH DANG KET QUA ADC
ADON=1; //KET QUA DICH PHAI
}
//-------------------------
void interrupt_init()
{
PEIE=1; //VI NGAT NGOAI VI NEN SET=1
ADIF=0;
ADIE=1;
GIE=1;
}
//---------------------------
void interrupt isr()
{
int read_adc;
if(ADIE&&ADIF)
{
ADIF=0;
read_adc=(ADRESH<<8)|ADRESL;
read_adc=read_adc*4.883; //em thay 5000/1024=4.883
temp=read_adc/10;
}
}
//------------------------------------------
void lcd_adc(int i)
{
char a,b,c,d;
a=i/1000;
b=(i-a*1000)/100;
c=(i-a*1000-b*100)/10;
d=i-a*1000-b*100-c*10;
lcd_putc(a+0x30);
lcd_puts(".");
lcd_putc(b+0x30);
lcd_putc(c+0x30);
lcd_putc(d+0x30);
lcd_puts(" C");
}
//-----------------------------
void main()
{
port_init();
adc_init();
interrupt_init();
lcd_init();
__delay_ms(100);
while(1)
{
lcd_clear();
lcd_puts("DO NHIET DO=LM35");
lcd_gotoxy(4,1);
lcd_adc(temp);
GO_nDONE;
__delay_ms(100);
}
}
#include <htc.h>
#include <stdio.h>
#include "lcd.h"
__CONFIG(FOSC_INTRC_NOCLKOUT&MCLRE_ON*WDTE_OFF&LVP_OFF);
#define _XTAL_FREQ 4000000
unsigned long temp;
//--------------------------------
//KHOI TAP PORT
void port_init()
{
ANSEL|=1<<3;
ANSELH|=0; //RA3 LA INPUT
TRISA3=1;
TRISB=0X00; //PORTB LA OUTPUT
PORTB=0X00;
TRISE=0X00;
PORTE=0X00;
PSA=0;
PS2=1;
PS1=1;
PS0=1;
}
//-------------------------------
void adc_init()
{
ADCS1=1; //CHON TAN SO LAY MAU
ADCS0=0; //suy ra toc do chuyen doi ADC la Fosc/32.
VCFG1=0; // chon dien ap lay mau la dien ap noi
VCFG0=0;
CHS3=0;
CHS2=0; //chon kenh AN3
CHS1=1;
CHS0=1;
ADFM=1; //CHON DINH DANG KET QUA ADC
ADON=1; //KET QUA DICH PHAI
}
//-------------------------
void interrupt_init()
{
GIE=1;
PEIE=1; //VI NGAT NGOAI VI NEN SET=1
ADIF=0;
ADIE=1;
}
//------------------------------------------
void lcd_adc(unsigned long i)
{
char a,b,c,d;
a=i/1000;
b=(i-1000*a)/100;
c=(i-1000*a-100*b)/10;
d=i-1000*a-100*b-10*c;
if(a>=1)
{
lcd_putc(a+0x30);
}
if(b>=1)
{
lcd_putc(b+0x30);
}
lcd_putc(c+0x30);
lcd_putc(d+0x30);
lcd_puts(" C");
}
//---------------------------
void interrupt isr()
{
unsigned long read_adc;
if(PEIE&&ADIE&&ADIF)
{
ADIF=0;
read_adc=(ADRESH<<8|ADRESL);
read_adc=read_adc*5*1000/1023;
temp=read_adc/10;
}
}
//-----------------------------
void main()
{
port_init();
adc_init();
interrupt_init();
lcd_init();
__delay_ms(100);
while(1)
{
lcd_clear();
lcd_puts("DO NHIET DO=LM35");
lcd_gotoxy(4,1);
lcd_adc(temp);
GO_nDONE=1;
__delay_ms(100);
}
}