CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Going mad with Pic16F627 and KS0066U LCD - Help needed!!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
F-omat



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

Going mad with Pic16F627 and KS0066U LCD - Help needed!!!!
PostPosted: Sat Apr 10, 2010 12:28 pm     Reply with quote

Hi everybody,

I'm going to get mad while trying go activate my 4x20 LCD display. The LCD controller is a KS0066U and the target uC is a PIC16F627. LCD's datasheet can be found here:
http://www.ampire.com.tw/Spec-AC/AC-204A.pdf

I have tried everything but the LCD won't work. I only get black blocks in the whole 1st and 2nd line and 14 black blocks in the 3rd and 4th line.

I have tried the ccs LCD.h , the LCD204.h, the flexLCD.h and finally I tried a 8bit version cause I'm not really sure if my display is able to do 4bit mode.
I have changed the delays between the single steps without success. How big can I make the delays? Is there a maximum or a range which shouldn't be passed? I have checked the connection of the data lines twice. everything is ok.

Here is my code:

main.c:
Code:

#include "main.h"
#include <Flex_LCD420_8bit.h>   

void main()
{
lcd_init();
delay_ms(500);

while(1)
  {
   printf(lcd_send_byte, "Time ");
  }
}


Main.h:
Code:

#include <16F627.h>

#FUSES INTRC_IO
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES MCLR                     //Master Clear enable
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#use delay(clock=4000000)      //4MHz


LCD driver - I call it: Flex_LCD420_8bit.h
Code:

#define    LCD_RS      PIN_A0
#define    LCD_RW      PIN_A1
#define    LCD_E       PIN_A2

int8 lcd_read_byte()
{
   int8 retval;
   output_high(LCD_RW);
   output_high(LCD_E);
   retval = input_b();
   delay_ms(5);
   output_low(LCD_E);
   output_low(LCD_RW);
   return(retval);
}

void lcd_send_byte(int8 data)
{
   while(bit_test(lcd_read_byte(),7));
   output_high(LCD_RS);
   output_b(data);
   output_high(LCD_E);
   delay_ms(5);
   output_low(LCD_E);
   output_low(LCD_RS);
}

void lcd_init()
{
   int8 i;

   output_low(LCD_RS);
   output_low(LCD_RW);
   output_low(LCD_E);
   delay_ms(500);

   for (i=0; i<3; i++)
   {
      output_b(0x38);
      output_high(LCD_E);
      delay_ms(5);
      output_low(LCD_E);
      delay_ms(50);
   }

   output_b(0x06);
   output_high(LCD_E);
   delay_ms(5);
   output_low(LCD_E);
   delay_ms(50);
   output_b(0x0E);
   output_high(LCD_E);
   delay_ms(5);
   output_low(LCD_E);
   delay_ms(50);
   output_b(0x01);
   output_high(LCD_E);
   delay_ms(5);
   output_low(LCD_E);
   delay_ms(2);
   output_b(0x80);
   output_high(LCD_E);
   delay_ms(5);
   output_low(LCD_E);
   delay_ms(100);
}

I've also tested the generated hex file with a simulator called "picsimulator". There is also a LCD inside this simulator and I can get it working with the code I posted. So where is the mistake to get it working in real life?

I hope anybody can help me. I have to get it working.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 1:58 pm     Reply with quote

Quote:
#include <16F627.h>

#FUSES INTRC_IO
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES MCLR //Master Clear enable
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000) //4MHz

You have two different oscillator fuses. The HS fuse expects an external
crystal. The INTRC_IO fuse uses the internal oscillator. Which one do
you want to use ?

If you compile your program and look at the .LST file (at the bottom)
you will see that the compiler resolves the oscillator fuse conflict by
selecting the HS fuse. So, if your intention was to use the internal
oscillator (with INTRC_IO), then by adding HS, you have caused it to fail.
Quote:
Configuration Fuses:
Word 1: 3F22 HS NOWDT PUT NOPROTECT NOBROWNOUT MCLR NOLVP NOCPD

When something works in the simulator but not on a real board, always
look for things that are likely not to be simulated (in detail). First thing
would be the oscillator. Other things would be fatal use of incorrect
fuses, such as selecting LVP mode. You have NOLVP, so you're OK on
that. That leaves the oscillator circuit, or MCLR circuit, or power supply,
or 100 nF bypass capacitors on Vdd pins, etc.

2nd thing. Your LCD supports the 4-bit mode interface, according to the
data sheet that you posted. You should use the 4x20 Flex driver in the
CCS code library. You shouldn't invent your own driver. Use one that
is known to work.
F-omat



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 11:04 am     Reply with quote

Hi PCM programmer. Regarding to your reply I returned to the original FlexLCD 420.h with the following pinout:
Code:
#define LCD_DB4   PIN_B4
#define LCD_DB5   PIN_B5
#define LCD_DB6   PIN_B6
#define LCD_DB7   PIN_B7

#define LCD_RS    PIN_B0
#define LCD_RW    PIN_B1
#define LCD_E     PIN_B2

I also changed the mentioned fuse. Now I use XT fuse at 4MHz. Wiring is as shown here: http://www.mikroe.com/en/books/picbook/7_09chapter.htm

MCLR pin is via 10k resistor wired to Vcc. Apart from that I have no other components in my circuit.

you pointed out:
Quote:
That leaves the oscillator circuit, or MCLR circuit, or power supply,
or 100 nF bypass capacitors on Vdd pins, etc.


In my opinion MCLR and oscillator circuit are ok. I use a regulated laboratory power supply. This shouldn't be the reason for my problems.
But, what do you mean with bypass capacitors? I have looked at several schematics in the internet and a bypass capacitor is mentioned anywhere.
With the mentioned changes I still get black blocks on the display.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 11:26 am     Reply with quote

Have you ever made this PIC (and the board) do anything, such as blink
an LED ? In other words, have you proved the PIC board can work OK
before adding the LCD ?
F-omat



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 11:40 am     Reply with quote

sure. i have a testboard (velleman p8048). there is an demo asm file to make led's blinking and you can change the blinking sequence by pushing one out of 4 buttons. so there are 4 sequences. i just programmed the pic with this demo and everythings working fine. so the pic is ok.

by the way i have noticed something strange:
when i place the pic in my display circuit and i change the value of the contrast resistor very fast i still get black blocks, but in the 4th line at the last 6 places strange signs are visible. any clue on that?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 12:20 pm     Reply with quote

I can't find a Velleman board with the name "P8048". There is one
named K8048. Is this your board ?
http://www.velleman.eu/downloads/0/illustrated/illustrated_assembly_manual_k8048_rev4.pdf

Quote:

#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7

For the LCD data bus, you are using pins B6 and B7. These pins are
permanently connected to the programmer circuit on the K8048 board.
I suggest that you choose two other pins to use with the LCD.
F-omat



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 12:29 pm     Reply with quote

you are right the board is called K8048. i use this board only for demo things NOT to program PICs. to program the PICs i use ICD2 via ICSP.
F-omat



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon Apr 12, 2010 9:13 am     Reply with quote

hello

According to my problem I tried to find a replacement. Today I talked to a friend of mine and he lent me his LCD. It is a 16x2 (W162B-N3LW) from electronic assembly. I don't really know the controller type but it is 100% hd44780 compatible. I left the setup as it was before, no changes in code or wiring.
AND tata, this display works. Not perfect, cause I used the flex 20x4 driver, but I can now see letters and numbers. After changing the driver to Flex 16x2 everything is fine.

I don't really know what went wrong with the other display but I bet it is the init timing. I have tried to decrease and to increase the delays but nothing works good for this display. Maybe someone has a clue to solve this problem.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group