LCD not intialiseing

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

Post Reply
Posts: 2
Joined: Sat Sep 11, 2010 7:46 pm

LCD not intialiseing

Post by AcHmed »

I recently purchased flow code V3.6 From Newark.

I'm having difficulty in understanding why I cant get the LCD to initialize properly. I am just using TUT_26.FCF changing the ports and bits and config settings to match my 16F887 Demo board from Microchip, I'm also using PICKIT2 for programing. I only get one line of a 16x2 display visible and its blank no writing is done from the PIC to the LCD.

I have tried a similiar program written in MikroC to perform the same function read the ADC and display the reading on the LCD (CONVERT TO VOLTS). This works as it should meaning my hardware must be correct and the error is something in FLOWCODE.

This is the MikroC version of what I'm trying to do in Flowcode, and not having any success :mrgreen: Below is the modified TUT26 FCF file. If someone could tell me whats wrong Please? It simulates properly but that's useless I need it to work on hardware.

Code: Select all

// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

unsigned char ch;                    //
unsigned int adc_rd;                 // Declare variables
char *text;                          //
long tlong;                          //

void main() {
    INTCON = 0;                      // All interrupts disabled
    ANSEL = 0x00;                    // Pin RA0 is configured as an analog input
    TRISA = 0x00;
    ANSELH = 0;                      // Rest of pins are configured as digital

    Lcd_Init();                      // LCD display initialization
    Lcd_Cmd(_LCD_CURSOR_OFF);        // LCD command (cursor off)
    Lcd_Cmd(_LCD_CLEAR);             // LCD command (clear LCD)

    text = "Achmed";       // Define the first message
    Lcd_Out(1,1,text);               // Write the first message in the first line
    text = "LCD example";            // Define the second message
    Lcd_Out(2,1,text);               // Define the first message

    ADCON1 = 0x82;                   // A/D voltage reference is VCC
    TRISA = 0xFF;                    // All port A pins are configured as inputs

    text = "Current:";               // Define the third message

    while (1) {
        adc_rd = ADC_Read(0);        // A/D conversion. Pin RA0 is an input.
        Lcd_Out(2,1,text);           // Write result in the second line
        tlong = (long)adc_rd * 5000; // Convert the result in millivolts
        tlong = tlong / 1023;        // 0..1023 -> 0-5000mV
        ch = tlong / 1000;           // Extract volts (thousands of millivolts)
                                     // from result
        Lcd_Chr(2,9,48+ch);          // Write result in ASCII format
        ch = (tlong / 100) % 10;     // Extract hundreds of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        ch = (tlong / 10) % 10;      // Extract tens of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        ch = tlong % 10;             // Extract digits for millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
(6.5 KiB) Downloaded 208 times

User avatar
Matrix Staff
Posts: 14865
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd

Re: LCD not intialiseing

Post by Benj »


First of all the project options are set to use an 8MHz clock source. Is this correct for your hardware?

In the Chip -> Configure -> Expert screen you are using the internal RC clock. Here I would disable the Low Voltage Programming configuration as this could be causing the display not to work.

Lastly the internal clock will run at 4MHz by default. To get this to run at 8MHz to match your project option settings you will need to add a C code icon to the start of your program containing the following line of code.

osccon = 0x71;

Let me know how you get on.
(7.5 KiB) Downloaded 241 times

Posts: 2
Joined: Sat Sep 11, 2010 7:46 pm

Re: LCD not intialiseing

Post by AcHmed »

Thanks Benj

I performed the changes you suggested and it works. It was starting to drive me nuts.

Post Reply