Page 2 of 2

Posted: 24 Feb 2009 04:56
by SNG
lolix69 wrote:dont work

if I call the function HID_enable, the LCD does not work
I got the same kind of problem when I tried to use a LCD with the PIC18Fxx8 series. Whatever I did, my LCD didn't work on PORT B and D....

until I found a sample how to connect two PICs by CAN... and found a schematic where the LCD was connected on PORT C... when I swapped it over to PORT C.... it worked without any problems... why I don't know, but it worked... maybe a try for you...

Posted: 25 Feb 2009 21:00
by louis, netherlands
Well, it seems to be that the Hitachi HD44780 LCD-controller is the mother of all LCD-controllers, so the KS0070B is a compatible version. You can find more information on http://en.wikipedia.org/wiki/HD44780_Character_LCD and even download the datasheet there.
On page 9 of the HD44780 datasheet you find the same information as I stated before:
Busy Flag (BF)
When the busy flag is 1, the HD44780U is in the internal operation mode, and the next instruction will not
be accepted. When RS = 0 and R/W = 1 (Table 1), the busy flag is output to DB7. The next instruction
must be written after ensuring that the busy flag is 0.

I have searched the MikroElectronica assembly-code several times, but still cannot find this BF-checking, so I think they just assume that the LCD-controller is ready, but with the high clockspeeds it is rather uncertain.
I also found out that switching off the onboard portleds causes less errors on the LCD, so this could indicate a better rise-and-fall of the signal-bit-slope.

The solution of SNG is nice, but when someone wants to use a PIC18F2550 is does not work. This PIC is a 28-pin version of the PIC18F4550 and has no PORTD.
So it is not a perfect solution for our problem, the LCD should have to work on PORTC as well.

But I want to use the PIC18F2550 with a USB at full speed so ...
I still think that MikroElectronica has to come in to help us out ...

Posted: 26 Feb 2009 17:46
by lolix69
Hi,

I'm having a lot of trouble to send data from the USB to LCD.

Someone can give me some examples?

Posted: 27 Feb 2009 10:50
by louis, netherlands
Hi lolix69,

As far as I can see there is nothing wrong with your software-coding.
But maybe you could try to do some experimenting with the clock-frequencies, see if this helps a bit.
Get the datasheet of the PIC18F2550/4550 and look at page 32. There is a table so you can see what clock-frequencys you can get with a 8MHz crystal. The clock-frecuency affects the behaviour of the USB-port because they are related.

At this moment I have decided to go on with development and using the USB at 48MHz and read some variables through the debugger insteadof the LCD-display.
The LCD does not work correct, that is right. But I have discovered that switching on/off the EasPic5 onboard LEDs , and switching on/off the pullup resistors at the PORTB pinheaders, affects the LCD. So I am more convinced that we have to deal with a timing problem at the control-bits for the LCD. I have informed the MikroElektronica-support team about our problems, so I wait and see if they have a nice solution for us.

Re: USB and LCD

Posted: 10 Aug 2010 17:48
by mduncan
Just to revive this problem.
I too am having the same issue - can't get HD44780 based LCD to display on an 18F458

Its not the 18F458 or the LCD (I tried 3 different ones). its the COMPILER!
I wrote an LCD test routine in picBASIC pro and the LCD worked.
picBASIC pro has options for LCD_commandus and LCD_dataus to set the command and data timings for LCD's
I also ran a logic analyser on the LCD interface while running the test code and can confirm the timing and data being sent to the LCD from the 18F458 as compiled under mikroBASIC is rubbish - no wonder the LCD won't initialise.

Strangely the LCD works flawlessly for a 16F877 at the same clock speed (10MHz), on the same board with the same mikroBASIC code just compiled for 16F877 instead. The logic analyser showed data sheet perfect timings for initialising the LCD. WTF??

I am using mikroBASIC Pro for PIC v3.8 (downloaded 2 weeks from mikroE web site)

This is a great compiler (compared to picBASIC pro) just not for 18F with LCD and no I can't just move it to PORTC, I am using the hardware SPI module on PORTC.

Re: USB and LCD

Posted: 11 Aug 2010 13:45
by tihomir.losic
Hello,

please, follow this code in order to PIC18F458 run your LCD display:

Code: Select all

// LCD module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){

  ADCON1 = 0x07;                     // Configure AN pins as digital I/O
  CMCON = 0x07;                      // Disable comparators

  Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row

  Lcd_Out(2,6,txt4);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row

  Delay_ms(2000);

  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }
}
For any further assistance, feel free to contact me.

Best regards,

Losic Tihomir

Re: USB and LCD

Posted: 11 Aug 2010 15:11
by mduncan
Thank you for the suggestion.

I want to use port D for the LCD. port B is half used for in circuit programming.

So I tried LATD and it now works, although not at first and I can't replicate the failure condition, which was missing/corrupted characters on LCD.

I had searched for 2 days, unsuccessfully, before posting here about this problem.

Again thank you so much for your help, you have breathed new life into this project.

Re: USB and LCD

Posted: 12 Aug 2010 16:06
by anikolic
Hello,

I have just tested LCD and HID example on mikroC PRO for PIC v4.00beta, and it worked perfectly well!
Please find the demonstration project in the attachment:
HID Read Write Interrupt.rar
(68.16 KiB) Downloaded 205 times
I warmly suggest you should consider switching over to PRO compilers, which are not only more stable and better looking, but provide new and enriched HID library, which is rewritten from scratch few releases ago, and which, besides HID, implements USB generic support.

Best of all – switching over to PRO is free of charge for users of non-PRO compilers!

Best regards,
Aleksandar

Re: USB and LCD

Posted: 13 Aug 2010 03:08
by mduncan
Thank you aleksandar.

I am using the pro version (I think?), it says "mikroBASIC Pro for PIC v3.8" in the About page.
I'm very interested in the features available in the upcoming 4.0x release.

I don't need HID at the moment but it is good to know it is available when I will need it.
The main attraction for me was the rich library support for many other peripherals eg. SD/CF cards, Graphic LCDs, Touch Screens etc. etc.

Thank you for your support. Its comforting to know its available and so prompt.

Regards,
Michael

Re: USB and LCD

Posted: 21 Aug 2010 21:04
by BlackBird
Hi,
As far as I know each LCD (I mean from different builders) has different tolerances to initialization commands. Of course you have to take in mind this all the time: commands you sent to your LCD are dependent on MCU clock speed. In your LCD datasheet you can find a table of commands, on it you will see the limit time for each LCD command, so you have to achieve this parameters to make your LCD works well.
I don't know if mikroC libraries related to LCD take that factor in mind. Any body does know?

Did you tested your USB and it's working fine?

Good luck !

Re: USB and LCD

Posted: 24 Aug 2010 15:28
by ranko.rankovic
Hello,

The mikroC PRO for PIC provides a library for communication with LCDs (with HD44780 compliant controllers) through the 4-bit interface. Also, all timing diagrams from Datasheet that are needed for controller to work properly with MCU's are observed in our LCD library.

Best regards