PIC16F18044 MCU NOT ABLE TO INTEFACE WITH JHD162A

Thread Starter

uthblao

Joined Sep 29, 2022
6
PIC16F18044
I am new to pic MCU. Can some one tell me whats wrong with the code . LCD jhd162a is not displaying the desired result, i am attaching the lcd display pic , please help me resolve the problem.

C-like:
// PIC16F18044 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1

#pragma config FEXTOSC = OFF // External Oscillator Selection bits (Oscillator not enabled)

#pragma config RSTOSC = HFINTOSC_1MHz// Reset Oscillator Selection bits (HFINTOSC (1MHz))

#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)

#pragma config VDDAR = HI // VDD Range Analog Calibration Selection bit (Internal analog systems are calibrated for operation between VDD = 2.3 - 5.5V)

// CONFIG2

#pragma config MCLRE = INTMCLR // Master Clear Enable bit (If LVP = 0, MCLR is port-defined function; If LVP = 1, RA3 pin function is MCLR)

#pragma config PWRTS = PWRT_OFF // Power-up Timer Selection bits (PWRT is disabled)

#pragma config WDTE = OFF // WDT Operating Mode bits (WDT disabled; SEN is ignored)

#pragma config BOREN = ON // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit is ignored)

#pragma config DACAUTOEN = OFF // DAC Buffer Automatic Range Select Enable bit (DAC Buffer reference range is determined by the REFRNG bit)

#pragma config BORV = LO // Brown-out Reset Voltage Selection bit (Brown-out Reset Voltage (VBOR) set to 1.9V)

#pragma config ZCD = OFF // ZCD Disable bit (ZCD module is disabled; ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)

#pragma config PPS1WAY = ON // PPSLOCKED One-Way Set Enable bit (The PPSLOCKED bit can be cleared and set only once after an unlocking sequence is executed; once PPSLOCKED is set, all future changes to PPS registers are prevented)

#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset)

// CONFIG3

// CONFIG4

#pragma config BBSIZE = BB512 // Boot Block Size Selection bits (512 words boot block size)

#pragma config BBEN = OFF // Boot Block Enable bit (Boot Block disabled)

#pragma config SAFEN = OFF // Storage Area Flash (SAF) Enable bit (SAF disabled)

#pragma config WRTAPP = OFF // Application Block Write Protection bit (Application Block is NOT write protected)

#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block is NOT write protected)

#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration Register is NOT write protected)

#pragma config WRTD = OFF // Data EEPROM Write-Protection bit (Data EEPROM is NOT write-protected)

#pragma config WRTSAF = OFF // Storage Area Flash (SAF) Write Protection bit (SAF is NOT write protected)

#pragma config LVP = OFF // Low Voltage Programming Enable bit (High Voltage on MCLR/Vpp must be used for programming)

// CONFIG5

#pragma config CP = OFF // Program Flash Memory Code Protection bit (Program Flash Memory code protection is disabled)

#pragma config CPD = OFF // Data EEPROM Code Protection bit (EEPROM code protection is disabled)

// #pragma config statements should precede project file includes.

// Use project enums instead of #define for ON and OFF.


#include <xc.h>

#include <pic16f18044.h>

#include <stdint.h>

// Define MCU frequency

#define _XTAL_FREQ 1000000

// Define LCD pin connections

#define LCD_RS PORTBbits.RB4

#define LCD_RW PORTBbits.RB5

#define LCD_EN PORTBbits.RB6

#define LCD_DATA PORTC

// Define named constants

#define LCD_FUNCTION_SET_8BIT 0x38

#define LCD_DISPLAY_CONTROL_ON 0x0C

#define LCD_CLEAR_DISPLAY 0x01

#define LCD_ENTRY_MODE_INCREMENT_CURSOR 0x06

#define MAX_DIGITS 10

// Function to send command to LCD

void lcd_command(uint8_t command) {

LCD_RS = 0;

LCD_RW = 0;

LCD_DATA = command;

LCD_EN = 1;

__delay_us(1);

LCD_EN = 0;

__delay_us(100);

}

// Function to send data to LCD

void lcd_data(uint8_t data) {

LCD_RS = 1;

LCD_RW = 0;

LCD_DATA = data;

LCD_EN = 1;

__delay_us(1);

LCD_EN = 0;

__delay_us(100);

}

// Function to initialize LCD

void lcd_init() {

// Wait for LCD to power up

__delay_ms(20);

// Function set: 8-bit mode, 2 lines, 5x8 font

lcd_command(LCD_FUNCTION_SET_8BIT);

// Display control: display on, cursor off, blink off

lcd_command(LCD_DISPLAY_CONTROL_ON);

// Clear display

lcd_command(LCD_CLEAR_DISPLAY);

// Entry mode: increment cursor, no shift

lcd_command(LCD_ENTRY_MODE_INCREMENT_CURSOR);

}

// Function to display an integer on LCD

void lcd_display_integer(uint32_t num) {

// Maximum 10 digits

char buf[MAX_DIGITS + 1];

// Convert integer to string manually

int i = MAX_DIGITS - 1;

while (num > 0 && i >= 0) {

buf[i--] = (num % 10) + '0';

num /= 10;

}

while (i >= 0) {

buf[i--] = '0';

}

// Display string on LCD

for (int i = 0; i < MAX_DIGITS; i++) {

lcd_data(buf);

}

}

void main() {

// Initialize LCD

lcd_init();

while (1) {

// Display integer on LCD

lcd_display_integer(123456789);

// Wait for a short period of time

__delay_ms(1000);

// Clear the display

lcd_command(0x01);

// Display integer on LCD in reverse order

lcd_display_integer(987654321);

// Wait for a short period of time

__delay_ms(1000);

// Clear the display

lcd_command(0x01);

}

}
 

Attachments

Last edited by a moderator:

bidrohini

Joined Jul 29, 2022
190
I can't see any issues with the code. Let's see if anyone else says otherwise. In the meantime, make sure that your LCD is good. You can check that separately. Also make sure that there is nothing wrong with the jumper wires that you're using.
 
Top