fork download
  1. #include <xc.h>
  2.  
  3. // CONFIGURATION BITS
  4. #pragma config OSC = HS // High-speed oscillator
  5. #pragma config PWRT = OFF
  6. #pragma config WDT = OFF
  7. #pragma config LVP = OFF
  8.  
  9. // LCD control pins
  10. #define RS RC4
  11. #define RW RC5
  12. #define EN RC6
  13.  
  14. // Delay function
  15. void LCD_delay() {
  16. for(int i = 0; i < 1000; i++);
  17. }
  18.  
  19. // Send command to LCD
  20. void LCD_cmd(unsigned char cmd) {
  21. RS = 0; // Command mode
  22. RW = 0; // Write mode
  23. PORTB = cmd; // Command on data lines
  24. EN = 1; LCD_delay(); EN = 0;
  25. }
  26.  
  27. // Send data (character) to LCD
  28. void LCD_data(unsigned char data) {
  29. RS = 1; // Data mode
  30. RW = 0; // Write mode
  31. PORTB = data; // Data on data lines
  32. EN = 1; LCD_delay(); EN = 0;
  33. }
  34.  
  35. // Initialize LCD
  36. void LCD_init() {
  37. LCD_cmd(0x38); // 8-bit, 2-line
  38. LCD_cmd(0x0E); // Display ON, cursor ON
  39. LCD_cmd(0x06); // Entry mode
  40. LCD_cmd(0x01); // Clear display
  41. LCD_cmd(0x80); // Set cursor to line 1
  42. }
  43.  
  44. // Write string to LCD
  45. void LCD_write_string(const char *str) {
  46. while(*str != '\0') {
  47. LCD_data(*str);
  48. str++;
  49. }
  50. }
  51.  
  52. // Main function
  53. void main() {
  54. TRISB = 0x00; // PORTB as output (data lines)
  55. TRISC = 0x00; // PORTC as output (control lines)
  56.  
  57. LCD_init(); // Initialize LCD
  58.  
  59. // Display text
  60. LCD_write_string("St.MIRAS COLLEGE");
  61. LCD_cmd(0xC0); // Move to line 2
  62. LCD_write_string("ELECTRONICS LAB");
  63.  
  64. while(1); // Infinite loop
  65. }
  66.  
Success #stdin #stdout 0.04s 25544KB
stdin
Standard input is empty
stdout
#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
}