0% found this document useful (0 votes)
17 views3 pages

K 1

The document describes code to read voltage measurements from 3 ADC channels and display the results on an LCD. It includes functions to initialize the ADC and LCD, read ADC values, convert to voltages, and display the voltages on the LCD in a continuous loop.

Uploaded by

Panje Darlington
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

K 1

The document describes code to read voltage measurements from 3 ADC channels and display the results on an LCD. It includes functions to initialize the ADC and LCD, read ADC values, convert to voltages, and display the voltages on the LCD in a continuous loop.

Uploaded by

Panje Darlington
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Include required libraries

#include <built_in.h>

#include <lcd.h>

// Define ADC channels

#define ADC_CHANNEL_1 0 // ADC channel for phase 1 voltage

#define ADC_CHANNEL_2 1 // ADC channel for phase 2 voltage

#define ADC_CHANNEL_3 2 // ADC channel for phase 3 voltage

// Define ADC reference voltage

#define ADC_REFERENCE 5.0 // Reference voltage in volts (adjust according to your circuit)

// Function to convert ADC value to voltage

float adcToVoltage(unsigned int adcValue)

return ((float)adcValue * ADC_REFERENCE) / 1023.0;

void main()

unsigned int adcValue1, adcValue2, adcValue3;

float voltage1, voltage2, voltage3;

char lcdText[20];

// Set Port A as input


TRISA = 0xFF;

// Set Port B as output

TRISB = 0x00;

// Set Port C as output

TRISC = 0x00;

// Initialize LCD

LCD_Init();

LCD_Cmd(_LCD_CLEAR);

LCD_Cmd(_LCD_CURSOR_OFF);

// Initialize ADC

ADC_Init();

while (1)

// Read ADC values for each phase

adcValue1 = ADC_Read(ADC_CHANNEL_1);

adcValue2 = ADC_Read(ADC_CHANNEL_2);

adcValue3 = ADC_Read(ADC_CHANNEL_3);

// Convert ADC values to voltage measurements

voltage1 = adcToVoltage(adcValue1);
voltage2 = adcToVoltage(adcValue2);

voltage3 = adcToVoltage(adcValue3);

// Display voltages on LCD

LCD_Cmd(_LCD_CLEAR);

sprintf(lcdText, "Phase 1: %.2f V", voltage1);

LCD_Out(1, 1, lcdText);

sprintf(lcdText, "Phase 2: %.2f V", voltage2);

LCD_Out(2, 1, lcdText);

sprintf(lcdText, "Phase 3: %.2f V", voltage3);

LCD_Out(3, 1, lcdText);

// Delay between measurements (adjust as needed)

Delay_ms(1000);

You might also like