#include <xc.h> // CONFIGURATION BITS #pragma config OSC = HS // High-speed oscillator #pragma config PWRT = OFF #pragma config WDT = OFF #pragma config LVP = OFF // LCD control pins #define RS RC4 #define RW RC5 #define EN RC6 // Delay function void LCD_delay() { for(int i = 0; i < 1000; i++); } // Send command to LCD void LCD_cmd(unsigned char cmd) { RS = 0; // Command mode RW = 0; // Write mode PORTB = cmd; // Command on data lines EN = 1; LCD_delay(); EN = 0; } // Send data (character) to LCD void LCD_data(unsigned char data) { RS = 1; // Data mode RW = 0; // Write mode PORTB = data; // Data on data lines EN = 1; LCD_delay(); EN = 0; } // Initialize LCD void LCD_init() { LCD_cmd(0x38); // 8-bit, 2-line LCD_cmd(0x0E); // Display ON, cursor ON LCD_cmd(0x06); // Entry mode LCD_cmd(0x01); // Clear display LCD_cmd(0x80); // Set cursor to line 1 } // Write string to LCD void LCD_write_string(const char *str) { while(*str != '\0') { LCD_data(*str); str++; } } // Main function void main() { TRISB = 0x00; // PORTB as output (data lines) TRISC = 0x00; // PORTC as output (control lines) LCD_init(); // Initialize LCD // Display text LCD_write_string("St.MIRAS COLLEGE"); LCD_cmd(0xC0); // Move to line 2 LCD_write_string("ELECTRONICS LAB"); while(1); // Infinite loop }
Standard input is empty
#include <xc.h>
// CONFIGURATION BITS
#pragma config OSC = HS // High-speed oscillator
#pragma config PWRT = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF
// LCD control pins
#define RS RC4
#define RW RC5
#define EN RC6
// Delay function
void LCD_delay() {
for(int i = 0; i < 1000; i++);
}
// Send command to LCD
void LCD_cmd(unsigned char cmd) {
RS = 0; // Command mode
RW = 0; // Write mode
PORTB = cmd; // Command on data lines
EN = 1; LCD_delay(); EN = 0;
}
// Send data (character) to LCD
void LCD_data(unsigned char data) {
RS = 1; // Data mode
RW = 0; // Write mode
PORTB = data; // Data on data lines
EN = 1; LCD_delay(); EN = 0;
}
// Initialize LCD
void LCD_init() {
LCD_cmd(0x38); // 8-bit, 2-line
LCD_cmd(0x0E); // Display ON, cursor ON
LCD_cmd(0x06); // Entry mode
LCD_cmd(0x01); // Clear display
LCD_cmd(0x80); // Set cursor to line 1
}
// Write string to LCD
void LCD_write_string(const char *str) {
while(*str != '\0') {
LCD_data(*str);
str++;
}
}
// Main function
void main() {
TRISB = 0x00; // PORTB as output (data lines)
TRISC = 0x00; // PORTC as output (control lines)
LCD_init(); // Initialize LCD
// Display text
LCD_write_string("St.MIRAS COLLEGE");
LCD_cmd(0xC0); // Move to line 2
LCD_write_string("ELECTRONICS LAB");
while(1); // Infinite loop
}