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 CCS Technical Support

Problem in Flex_420 LCD Driver
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

Problem in Flex_420 LCD Driver
PostPosted: Fri Mar 25, 2011 1:13 pm     Reply with quote

I'm trying to interface my 20x4 LCD to 18F452 using flex_lcd driver posted on this forum

it won't show anything, just blanks forever !!

I've already tried the built-in LCD420.c
and checked the wiring million times, just nothing

I also tried to add delays to the flex_lcd functions, also didn't work

the only way I could get something on my lcd is by using MicroC Lcd8 library (8Bit interface), this works perfect

I also tried the 8-Bit code in this forum
http://www.ccsinfo.com/forum/viewtopic.php?t=38367

modified it to work on 4 lines, still nothing

P.S. all of my codes worked fine in simulation
my lcd uses KS0066 Controller
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 25, 2011 1:17 pm     Reply with quote

Post the manufacturer and part number of the LCD.

Post a link to the website for the LCD.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 25, 2011 1:25 pm     Reply with quote

Thanks for your fast response

it's BATRON model BT 42005P

couldn't find the same exact number for a datasheet
here's the one i'm using
http://www.datamodul.com/us/page/popup_pages/Standard%20monochromatic%20alpha/alphanumeric/BT%2042005/BTHQ_42005VSS-YETF-06-LED04GHK_5V_EasyFluid.pdf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 25, 2011 1:37 pm     Reply with quote

Batron has a special init code, just for their 4x20 lcd. See the last
two posts in this thread. Note that in addition to my code, the array
size must be increased to 7.
http://www.ccsinfo.com/forum/viewtopic.php?t=38076
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 25, 2011 1:44 pm     Reply with quote

did it
nothing happened
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 25, 2011 1:50 pm     Reply with quote

Quote:

the only way I could get something on my lcd is by using MicroC Lcd8
library (8Bit interface), this works perfect

Post a link to this source code.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 25, 2011 1:53 pm     Reply with quote

it's a built-in library (.mcl), it cannot be opened using text editors
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Fri Mar 25, 2011 2:48 pm     Reply with quote

i've tried adding the 3 extra commands to lcd420.c
it was the same

I also checked the datasheet for KS0066U, these commands are not the same as the comment says
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 25, 2011 4:16 pm     Reply with quote

What happens if you use the MikroC lcd4 library ? (not lcd8)

Post a list of the connections between your PIC and the LCD.

Post the list of #define statements that you edited for the pin numbers
in the Flex_lcd_420.c file. Also post the #define statement for the RW
pin. (if you commented it out, then post it as a commented out line).
In other words, show your code. (Do not post the complete 4x20
driver file. It's already in the code library. I don't need to see it here).
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sat Mar 26, 2011 2:15 am     Reply with quote

When I used MicroC lcd4 library i got the same problem, a blank LCD

when I used MicroC lcd8 I used this connection
Port B >> LCD_Data (DB0-DB7)
PIN_D4 >> RS
PIN_D5 >> RW
PIN_D6 >> Enable
this worked fine, the only problem is that I has a huge routine and I can't just convert it to MicroC simply because I can't run the LCD there !!

for the Flex_lcd_420.c i tried many connections, finally I kept trying this one
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_B1
#define LCD_RW    PIN_B2
#define LCD_E     PIN_B0

#define USE_RW_PIN   1     

the same connection as LCD420.c, to switch faster between them

the RW pin was commented sometimes, I tried every update I made to flex_lcd_420.c with and without the use of RW
whenever I comment RW usage, I tie the pin to the ground.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sat Mar 26, 2011 3:50 am     Reply with quote

I've got the lcd8_init commands from the asm file, can I post it here?

it shows a longer list of commands


Code:

0x30, 0x30, 0x30 , 0x38 , 0x08, 0x01, 0x0c, 0x06
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 26, 2011 11:23 am     Reply with quote

Quote:

I've got the lcd8_init commands from the asm file, can I post it here?
it shows a longer list of commands
Code:
0x30, 0x30, 0x30 , 0x38 , 0x08, 0x01, 0x0c, 0x06

See the explanation below. The commands shown above put the LCD in 8-bit mode.


Quote:
0x30, 0x30, 0x30

This is the normal HD44780-compatible lcd start-up sequence.

Quote:
0x38

Set the lcd interface for 8-bit mode. (0x28 = 4-bit mode).

Quote:
0x08

Display off.

Quote:
0x01

Clear display.

Quote:
0x0c

Display on.

Quote:
0x06

Select "increment cursor" mode.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sat Mar 26, 2011 11:54 am     Reply with quote

yes I've noticed that I followed SAMSUNG KS0066U and understood those codes

now that we know mikroC uses the same sequence, what's your suggestions??

I managed to convert your flex_420 library to handle 8-Bit interface
works fine on the simulator, still nothing on the hardware

here is the edit code:
Code:


#define LCD_RS    PIN_D4
#define LCD_E     PIN_D6

#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54



int8 lcd_line;

int8 const LCD_INIT_STRING[8] =
{ 0x30,0x30,0x30,
 0x38,  // Set mode: 8-bit, 2+ lines, 5x8 dots
 8,                   
 1,                       
 12,
 6                       
 };
                             

void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
delay_us(50); 

if(address)
   output_high(LCD_RS);
else
   output_low(LCD_RS);


output_low(LCD_E);
 delay_us(50);
 output_b(n);
 delay_us(1);
 output_high(LCD_E);
 delay_us(1);
 output_low(LCD_E);
 delay_us(50);

}
//----------------------------

void lcd_init(void)
{

int8 i;

lcd_line = 1;

output_low(LCD_RS);
output_low(LCD_E);
delay_ms(50);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
    delay_ms(5);
   }
 
}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;


switch(y)
  {
   case 1:
     address = LCD_LINE_1_ADDRESS;
     break;

   case 2:
     address = LCD_LINE_2_ADDRESS;
     break;

   case 3:
     address = LCD_LINE_3_ADDRESS;
     break;

   case 4:
     address = LCD_LINE_4_ADDRESS;
     break;

   default:
     address = LCD_LINE_1_ADDRESS;
     break;
     
  }

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      lcd_line = 1;
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1, ++lcd_line);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}

//------------------------------


RW is tied to the ground
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 26, 2011 1:50 pm     Reply with quote

Does your current hardware run OK with the 8-bit MikroC LCD library code ?

If it does, then there is still a difference between the drivers, somewhere.
demonspells



Joined: 06 Jan 2011
Posts: 26

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sat Mar 26, 2011 2:03 pm     Reply with quote

yes it still works
here is the .asm file for Lcd8_Init(&PORTD, &PORTB);
Code:



; ADDRESS   OPCODE   ASM
; ----------------------------------------------
$0000   $EF90   F000         GOTO   _main
$0142   $   _Delay_1us:
;Delays.c,7 ::          void Delay_1us() {
;Delays.c,8 ::          Delay_us(1);
$0142   $0000                NOP
;Delays.c,9 ::          }
$0144   $0012                RETURN
$0102   $   _Delay_5500us:
;Delays.c,31 ::          void Delay_5500us() {
;Delays.c,32 ::          Delay_us(5500);
$0102   $0E08                MOVLW   8
$0104   $6E0B                MOVWF   STACK_11, 0
$0106   $0EFF                MOVLW   255
$0108   $6E0A                MOVWF   STACK_10, 0
$010A   $2E0B                DECFSZ   STACK_11, F, 0
$010C   $D001                BRA   $+2
$010E   $D003                BRA   $+4
$0110   $2E0A                DECFSZ   STACK_10, F, 0
$0112   $D7FE                BRA   $-1
$0114   $D7FA                BRA   $-5
$0116   $0E1E                MOVLW   30
$0118   $6E0A                MOVWF   STACK_10, 0
$011A   $2E0A                DECFSZ   STACK_10, F, 0
$011C   $D7FE                BRA   $-1
;Delays.c,33 ::          }
$011E   $0012                RETURN
$0136   $   _Delay_50us:
;Delays.c,19 ::          void Delay_50us() {
;Delays.c,20 ::          Delay_us(50);
$0136   $0E10                MOVLW   16
$0138   $6E0A                MOVWF   STACK_10, 0
$013A   $2E0A                DECFSZ   STACK_10, F, 0
$013C   $D7FE                BRA   $-1
$013E   $0000                NOP
;Delays.c,21 ::          }
$0140   $0012                RETURN
$00A4   $   _Lcd8_Cmd:
$00A4   $C015   FFE9         MOVFF   Lcd8bit_main_global_dataAddress, FSR0L
$00A8   $C016   FFEA         MOVFF   Lcd8bit_main_global_dataAddress+1, FSR0H
$00AC   $C017   FFE1         MOVFF   Lcd8bit_main_global_ctrlAddress, FSR1L
$00B0   $C018   FFE2         MOVFF   Lcd8bit_main_global_ctrlAddress+1, FSR1H
$00B4   $6AEF                CLRF   INDF0, 0
$00B6   $521E                MOVF   FARG_Lcd8_Cmd+0, 1, 0
$00B8   $E000                BZ   L_Lcd8_Cmd_0
$00BA   $   L_Lcd8_Cmd_0:
$00BA   $BE1E                BTFSC   FARG_Lcd8_Cmd+0, 7, 0
$00BC   $8EEF                BSF   INDF0, __LCD8_DB7, 0
$00BE   $BC1E                BTFSC   FARG_Lcd8_Cmd+0, 6, 0
$00C0   $8CEF                BSF   INDF0, __LCD8_DB6, 0
$00C2   $BA1E                BTFSC   FARG_Lcd8_Cmd+0, 5, 0
$00C4   $8AEF                BSF   INDF0, __LCD8_DB5, 0
$00C6   $B81E                BTFSC   FARG_Lcd8_Cmd+0, 4, 0
$00C8   $88EF                BSF   INDF0, __LCD8_DB4, 0
$00CA   $B61E                BTFSC   FARG_Lcd8_Cmd+0, 3, 0
$00CC   $86EF                BSF   INDF0, __LCD8_DB3, 0
$00CE   $B41E                BTFSC   FARG_Lcd8_Cmd+0, 2, 0
$00D0   $84EF                BSF   INDF0, __LCD8_DB2, 0
$00D2   $B21E                BTFSC   FARG_Lcd8_Cmd+0, 1, 0
$00D4   $82EF                BSF   INDF0, __LCD8_DB1, 0
$00D6   $B01E                BTFSC   FARG_Lcd8_Cmd+0, 0, 0
$00D8   $80EF                BSF   INDF0, __LCD8_DB0, 0
$00DA   $5019                MOVF   Lcd8bit_main_global_cmd, 0, 0
$00DC   $0A01                XORLW   1
$00DE   $E103                BNZ   L_Lcd8_Cmd_1
$00E0   $98E7                BCF   INDF1, __LCD8_RS, 0
$00E2   $EF74   F000         GOTO   L_Lcd8_Cmd_2
$00E6   $   L_Lcd8_Cmd_1:
$00E6   $88E7                BSF   INDF1, __LCD8_RS, 0
$00E8   $   L_Lcd8_Cmd_2:
$00E8   $8CE7                BSF   INDF1, __LCD8_ENABLE, 0
$00EA   $ECA1   F000         CALL   _Delay_1us
$00EE   $9CE7                BCF   INDF1, __LCD8_ENABLE, 0
$00F0   $5019                MOVF   Lcd8bit_main_global_cmd, 0, 0
$00F2   $0A01                XORLW   1
$00F4   $E103                BNZ   L_Lcd8_Cmd_3
$00F6   $EC81   F000         CALL   _Delay_5500us
$00FA   $D002                BRA   L_Lcd8_Cmd_4
$00FC   $   L_Lcd8_Cmd_3:
$00FC   $EC9B   F000         CALL   _Delay_50us
$0100   $   L_Lcd8_Cmd_4:
$0100   $0012                RETURN
$0008   $   _Lcd8_Init:
$0008   $EC81   F000         CALL   _Delay_5500us
$000C   $EC81   F000         CALL   _Delay_5500us
$0010   $EC81   F000         CALL   _Delay_5500us
$0014   $C01C   F015         MOVFF   FARG_Lcd8_Init+2, Lcd8bit_main_global_dataAddress
$0018   $C01D   F016         MOVFF   FARG_Lcd8_Init+3, Lcd8bit_main_global_dataAddress+1
$001C   $C01A   F017         MOVFF   FARG_Lcd8_Init+0, Lcd8bit_main_global_ctrlAddress
$0020   $C01B   F018         MOVFF   FARG_Lcd8_Init+1, Lcd8bit_main_global_ctrlAddress+1
$0024   $C01A   FFE9         MOVFF   FARG_Lcd8_Init+0, FSR0L
$0028   $C01B   FFEA         MOVFF   FARG_Lcd8_Init+1, FSR0H
$002C   $9AEF                BCF   INDF0, __LCD8_RW, 0
$002E   $C01C   FFE1         MOVFF   FARG_Lcd8_Init+2, FSR1L
$0032   $C01D   FFE2         MOVFF   FARG_Lcd8_Init+3, FSR1H
$0036   $6AE6                CLRF   POSTINC1, 0
$0038   $0E11                MOVLW   17
$003A   $24E1                ADDWF   FSR1L, 0, 0
$003C   $6E00                MOVWF   STACK_0, 0
$003E   $C000   FFE1         MOVFF   STACK_0, FSR1L
$0042   $6AE7                CLRF   INDF1, 0
$0044   $0E12                MOVLW   18
$0046   $5C00                SUBWF   STACK_0, 0, 0
$0048   $6EE1                MOVWF   FSR1L, 0
$004A   $0E12                MOVLW   18
$004C   $26E9                ADDWF   FSR0L, 1, 0
$004E   $9CEF                BCF   INDF0, __LCD8_ENABLE, 0
$0050   $98EF                BCF   INDF0, __LCD8_RS, 0
$0052   $9AEF                BCF   INDF0, __LCD8_RW, 0
$0054   $0E12                MOVLW   18
$0056   $5EE9                SUBWF   FSR0L, 1, 0
$0058   $98EF                BCF   INDF0, __LCD8_RS, 0
$005A   $9CEF                BCF   INDF0, __LCD8_ENABLE, 0
$005C   $9AEF                BCF   INDF0, __LCD8_RW, 0
$005E   $0E30                MOVLW   48
$0060   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$0062   $EC52   F000         CALL   _Lcd8_Cmd
$0066   $0E30                MOVLW   48
$0068   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$006A   $EC52   F000         CALL   _Lcd8_Cmd
$006E   $0E30                MOVLW   48
$0070   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$0072   $EC52   F000         CALL   _Lcd8_Cmd
$0076   $0E38                MOVLW   56
$0078   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$007A   $EC52   F000         CALL   _Lcd8_Cmd
$007E   $0E08                MOVLW   8
$0080   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$0082   $EC52   F000         CALL   _Lcd8_Cmd
$0086   $0E01                MOVLW   1
$0088   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$008A   $EC52   F000         CALL   _Lcd8_Cmd
$008E   $0E06                MOVLW   6
$0090   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$0092   $EC52   F000         CALL   _Lcd8_Cmd
$0096   $0E0C                MOVLW   12
$0098   $6E1E                MOVWF   FARG_Lcd8_Cmd+0, 0
$009A   $EC52   F000         CALL   _Lcd8_Cmd
$009E   $0E01                MOVLW   1
$00A0   $6E19                MOVWF   Lcd8bit_main_global_cmd, 0
$00A2   $0012                RETURN
$0120   $   _main:
;microc_420.c,1 ::          void main() {
;microc_420.c,3 ::          Lcd8_Init(&PORTD, &PORTB);
$0120   $0E83                MOVLW   PORTD
$0122   $6E1A                MOVWF   FARG_Lcd8_Init+0, 0
$0124   $0E0F                MOVLW   @PORTD
$0126   $6E1B                MOVWF   FARG_Lcd8_Init+1, 0
$0128   $0E81                MOVLW   PORTB
$012A   $6E1C                MOVWF   FARG_Lcd8_Init+2, 0
$012C   $0E0F                MOVLW   @PORTB
$012E   $6E1D                MOVWF   FARG_Lcd8_Init+3, 0
$0130   $EC04   F000         CALL   _Lcd8_Init
;microc_420.c,6 ::          }
$0134   $D7FF                BRA   $

_________________
Badr Ghatasheh
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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