Introduction to the function of the PIC16F877 A/D converter

Crystal oscillator
Quartz Oscillator 3225 20M OSC

The PIC16F877 features eight 10-bit analog-to-digital (A/D) converters. Pins 2 to 5 are designated as AN0 to AN3, while pins 7 to 10 correspond to AN4 to AN7. The RAO port of the MPA-ICD is connected to a 10kΩ potentiometer, and 8 LEDs are linked to the D port (RDO to RD7), as illustrated in the figure. One of the A/D channels is used to demonstrate the process of A/D conversion programming, along with online debugging and firmware updates.

42563

As shown in the diagram, the variable output voltage from R6 is connected to RAO/ANO as an analog input. The 8 LEDs on the D port (RDO to RD7) display the result of the A/D conversion in binary format.

When setting up an A/D conversion program, it's essential to understand several special function registers (SFRs) within the PIC16F877. Here are some key registers involved in the A/D process:

  • ADCON1: This register controls the configuration of the A/D inputs. Bits PCFG0 to PCFG3 determine which pins are used for analog input. For example, setting them to 1110 selects AN0 (RAO) as the analog input, while the rest are configured as digital I/O.
  • ADCON0: This register manages the A/D conversion process. Bit 0 (ADON) enables or disables the A/D converter. Bit 2 (GO/DONE) starts or indicates the completion of the conversion. Bits 3–5 select the channel for conversion, and bits 6–7 (ADCS0, ADCS1) set the conversion clock source.
  • ADRESH: This register stores the high byte of the A/D conversion result.
  • PIR1: The ADIF bit in this register indicates whether the A/D conversion has completed.

Writing A/D code can be challenging for beginners because it requires precise control over these registers. Additionally, understanding the timing and configuration of the A/D clock is crucial for accurate results.

Below is an example of an ASM code snippet for A/D conversion on the PIC16F877:

48763

588

55 Inch Education Interactive Board

55 Inch Education Interactive Board,Conference All-In-One Machine,Conference Machine,Smart Conference Tablet

Jiangsu Qilong Electronic Technology Co., Ltd. , https://www.qilongtouch.com