0% found this document useful (0 votes)
10 views8 pages

Voi

This document describes how to interface an LCD module with a PIC16F877A microcontroller. It defines the LCD pin connections and directions, initializes the LCD, reads analog voltages from three phases using the ADC, calculates RMS voltages, displays the voltages on the LCD, and continuously monitors the voltages.

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)
10 views8 pages

Voi

This document describes how to interface an LCD module with a PIC16F877A microcontroller. It defines the LCD pin connections and directions, initializes the LCD, reads analog voltages from three phases using the ADC, calculates RMS voltages, displays the voltages on the LCD, and continuously monitors the voltages.

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/ 8

//Title: LCD interfacing with PIC16f877a

//LCD module connections

sbit LCD_RS at RB0_bit; //LCD reset

sbit LCD_EN at RB1_bit; //LCD enable

sbit LCD_D4 at RB4_bit; //Data

sbit LCD_D5 at RB5_bit; //Data

sbit LCD_D6 at RB6_bit; //Data

sbit LCD_D7 at RB7_bit; //Data

//LCD Pin Direction

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB4_bit;

sbit LCD_D5_Direction at TRISB5_bit;

sbit LCD_D6_Direction at TRISB6_bit;

sbit LCD_D7_Direction at TRISB7_bit;

char i;

float ac_peak_voltage = 230.0;

float adc_resolution = 5.0/1023;


void main() {

Lcd_Init();

// Configure Port A as input

TRISA = 0xFF; // set all pins of Port A as inputs

// Configure Port B as output

TRISB = 0x00; // set all pins of Port B as outputs

// Initialize ADC module

ADC_Init(); // ADC_Initialisation

Lcd_cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_out(1,1,"MONITORING AND PROTECTION SYSTEM");

Delay_ms(500);

for(i=0; i<32; i++){

lcd_cmd(_lcd_shift_left);

delay_ms(250);

Lcd_cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

while(1)

// READ ADC VALUES FOR THREE PHASES

float phase_a_voltage = ADC_Read(0); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

float phase_b_voltage = ADC_Read(1); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

float phase_c_voltage = ADC_Read(2); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

// CONVERT ADC VALUES TO VOLTAGES

float phase_a_voltage_actual = phase_a_voltage * adc_resolution;

float phase_b_voltage_actual = phase_b_voltage * adc_resolution;

float phase_c_voltage_actual = phase_c_voltage * adc_resolution;

// CALCULATE AC VOLTAGES FOR EACH PHASE

float phase_a_ac_voltage = (phase_a_voltage_actual / 5.0) * ac_peak_voltage; // Assuming 5V


peak-to-peak AC source

float phase_b_ac_voltage = (phase_b_voltage_actual / 5.0) * ac_peak_voltage;

float phase_c_ac_voltage = (phase_c_voltage_actual / 5.0) * ac_peak_voltage;

// CONVERT AC VOLTAGES TO STRINGS

char phase_a_voltage_text[16]; // Assuming a maximum of 15 characters for voltage display

char phase_b_voltage_text[16];

char phase_c_voltage_text[16];
FloatToStr(phase_a_ac_voltage, phase_a_voltage_text);

FloatToStr(phase_b_ac_voltage, phase_b_voltage_text);

FloatToStr(phase_c_ac_voltage, phase_c_voltage_text);

// DISPLAY VOLTAGES ON LCD

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1, 1, "RED: ");

Lcd_Out(1, 10, phase_a_voltage_text);

Lcd_Out(2, 1, "YELLOW: ");

Lcd_Out(2, 10, phase_b_voltage_text);

Lcd_Out(3, 1, "BLUE: ");

Lcd_Out(3, 10, phase_c_voltage_text);

Delay_ms(1000); // Delay for readability

} //while loop

} //main loop
void main() {

// Define the peak voltage of the AC source

float ac_peak_voltage = 220.0; // Replace with the actual peak voltage of your AC source
// Configure Port A as input

TRISA = 0xFF; // Assuming all pins of Port A are used as input

// Configure Port B as output

TRISB = 0x00; // Assuming all pins of Port B are used as output

// Initialize ADC module

ADC_Init(); // Assuming ADC_Init() is a function provided by mikroC PRO for PIC

// Initialize LCD module

Lcd_Init_PortB(); // Assuming Lcd_Init_PortB() is a function to initialize LCD on Port B

while(1) {

// Read ADC values for three phases

float phase_a_voltage = ADC_Read(0); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

float phase_b_voltage = ADC_Read(1); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

float phase_c_voltage = ADC_Read(2); // Assuming ADC_Read() is a function provided by mikroC


PRO for PIC

// Convert ADC values to voltages

float phase_b_voltage_actual = phase_b_voltage * adc_resolution;

float phase_c_voltage_actual = phase_c_voltage * adc_resolution;


// Calculate AC voltages for each phase

float phase_a_ac_voltage = (phase_a_voltage_actual / 5.0) * ac_peak_voltage; // Assuming 5V


peak-to-peak AC source

float phase_b_ac_voltage = (phase_b_voltage_actual / 5.0) * ac_peak_voltage;

float phase_c_ac_voltage = (phase_c_voltage_actual / 5.0) * ac_peak_voltage;

// Convert AC voltages to strings

char phase_a_voltage_text[16]; // Assuming a maximum of 15 characters for voltage display

char phase_b_voltage_text[16];

char phase_c_voltage_text[16];

FloatToStr(phase_a_ac_voltage, phase_a_voltage_text);

FloatToStr(phase_b_ac_voltage, phase_b_voltage_text);

FloatToStr(phase_c_ac_voltage, phase_c_voltage_text);

// Display voltages on LCD

Lcd_Cmd(_LCD_CLEAR);

Lcd_Out(1, 1, "Phase A: ");

Lcd_Out(1, 10, phase_a_voltage_text);

Lcd_Out(2, 1, "Phase B: ");

Lcd_Out(2, 10, phase_b_voltage_text);

Lcd_Out(3, 1, "Phase C: ");

Lcd_Out(3, 10, phase_c_voltage_text);

Delay_ms(1000); // Delay for readability, adjust as needed

You might also like