Use the ADC of the PIC 16F887 microcontroller and the LM35 sensor to measure the temperature and display it on 3 led 7 segments common anode
- Requirements: Use the ADC of the PIC16F887 microcontroller and the LM35 sensor to measure the temperature displayed on 3 led 7 segments common anode using 3 ports, only displaying units, tens and hundreds. Use a reference voltage source VREF+ connected to VDD with 5V and VREF- connected to a VSS source of 0V
- Circuit diagram on Proteus simulation software
Figure 1. Circuit diagram for measuring temperature using PIC16F887 displayed on 3 leds directly |
- Main program:
___________________
#INCLUDE<TV_16F887.C>
UNSIGNED INT16 KQADC;
UNSIGNED INT J,MATRAM;
VOID HIEN_THI()
{
MATRAM = MA7DOAN[KQADC/100];
IF (MATRAM == 0XC0) MATRAM=0XFF;
OUTPUT_B(MA7DOAN[KQADC%10]);
OUTPUT_D(MA7DOAN[KQADC/10%10]);
OUTPUT_C(MATRAM);
}
VOID MAIN()
{
SET_TRIS_B(0x00); SET_TRIS_D(0x00);
SET_TRIS_C(0x00); SET_TRIS_A(0xFF);
SETUP_ADC(ADC_CLOCK_DIV_2);
SETUP_ADC_PORTS(SAN0);
SET_ADC_CHANNEL(0);
WHILE(TRUE)
{
KQADC=0;
FOR (J=0; J<200; J++)
{
KQADC=KQADC+READ_ADC();
DELAY_MS(1);
}
KQADC= KQADC /2.046;
KQADC=KQADC/200;
HIEN_THI();
}
}
_____________
- TV_16F887.c Library:
___________________
#INCLUDE <16F887.H>
#DEVICE ADC=10
#FUSES NOWDT,PUT,HS,NOPROTECT,NOLVP
#USE DELAY(CLOCK=20M)
CONST UNSIGNED CHAR MA7DOAN [10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90};
___________________
Comments
Post a Comment