Analog to digital 8 bits For CSS Compiler

Summary of Analog to digital 8 bits For CSS Compiler


This code configures a PIC 16F877 microcontroller to read analog data from channel AN0 and display the raw ADC value (0-1023) on an LCD screen in real-time. It initializes the internal clock, disables unused peripherals, sets Port D as output for the LCD, and continuously loops to update the display with the current sensor reading converted via a hex-to-BCD function.

Parts used in the PIC 16F877 ADC LCD Monitor:

  • PIC 16F877 Microcontroller
  • LCD Display Module
  • Analog Sensor connected to AN0
  • 4MHz Clock Oscillator

 

#include <16F877.h>
#device adc=8
#FUSES NOWDT ,XT                                        
#use delay(clock=4000000) 

#include <Lcd_4bit.c>
int8  value; 

void main()
{
   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1); 
   set_adc_channel(0);
   set_tris_d(0x00);
   set_tris_A(0xff);
   Lcd_init();

while(true){ 
   set_adc_channel(0);
   delay_ms(10);
   value = read_adc(); // 0-1023  
   Lcd_row_col(1,0);   
   Lcd_putc("setpoint=");
   hex_bcd(value);lcd_row_col(1,9);sent_Lcd(); 
   delay_ms(50);   
  }
}

Quick Solutions to Questions related to PIC 16F877 ADC LCD Monitor:

  • What is the primary function of this program?
    The program reads analog values from channel AN0 and displays them on an LCD.
  • How does the code initialize the LCD?
    The Lcd_init function is called within the main setup section before the loop begins.
  • Which ADC channel is selected for reading data?
    The set_adc_channel function selects channel 0 for reading analog input.
  • What range of values does the read_adc function return?
    The function returns integer values ranging from 0 to 1023.
  • How long is the delay between ADC readings?
    A 10 millisecond delay occurs after setting the ADC channel before reading the value.
  • What port is configured as output for the LCD?
    Port D is configured as output using the set_tris_d command with a value of zero.
  • Is the Watchdog Timer enabled in this code?
    No, the FUSES directive explicitly disables the watchdog timer with NOWDT.
  • What clock speed is used for the system delay?
    The system uses a 4 MHz clock speed defined by the device delay directive.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter