Skip to main content

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:
File: main.c
___________________
#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:
File: TV_16F887.c
___________________
#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

Popular posts from this blog

Privacy Policy

Introduce We always strive to protect our customers' personal information. Customer Data The application fully commits not to collect and share data with third parties.

Bài 2: Dùng vi điều khiển 16F887 điều khiển 8 led đơn sáng dần tắt dần từ phải sang trái mô phỏng trên Proteus

Sơ đồ mạch:   Hình 1.  Sơ đồ mạch  điều khiển 8 led đơn sáng dần tắt dần từ phải sang trái Chương trình: #INCLUDE <16F887.H> #FUSES NOWDT,PUT,HS,NOPROTECT,NOLVP #USE DELAY(CLOCK=20M) UNSIGNED INT8 I, X; VOID MAIN() {      SET_TRIS_D(0x00); X=0X00; OUTPUT_D(X); DELAY_MS(500);      WHILE(TRUE)      {            FOR (I=0;I<8;I++)           {                 X = (X<<1)+0X01; OUTPUT_D(X); DELAY_MS(500);           }           FOR (I=0;I<8;I++)           {                 X = (X<<1); OUTPUT_D(X); DELAY_MS(500);           }      } } Giải thích chương trình: Khởi tạo portD là xuất dữ liệu, gán biến X bằng 0x00, xuất giá trị của X ra portD làm 8 led tắt, delay. Vòng lặp for thứ nhất thực hiện 8 lần: tiến hành xoay trái dữ liệu của X và cộng với 0x01. Khi xoay trái dữ liệu thì số 0 được đẩy vào, cộng với 0x01 là để đẩy số 1 vào X. Dữ liệu biến X được xuất ra portD điều khiển led sáng dần, sau 8 lần thì X sẽ bằng 1111_1111 – 8 led sáng hết. Vòng lặp for thứ hai thực hiện