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

PIC-EL III - FLEX LCD help?
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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 3:03 pm     Reply with quote

The source is the same as your source. The compiler version is the same.

Are you sure you're using the 16x2 "flex" driver in the code library ?
It's at this link. Make sure you're not using some modified version
of it that was posted elsewhere. Use this one:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
Make sure you're not using the 16x1 or 20x4 flex drivers. Those are
at different links in the Code Library forum.

Also, you said you're using the R/W line. To use it, the following line
in the Flex driver code must be uncommented. It must look like this:
Code:

#define USE_LCD_RW   1   



CCS also has a Flex lcd driver. They added this capability to their lcd.c
driver file. The following program shows how to configure the pins for
their driver:
Code:

#include <16F88.H>
#fuses  XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(crystal=4Mhz)

#define LCD_DATA4       PIN_B0                                   
#define LCD_DATA5       PIN_B1                                   
#define LCD_DATA6       PIN_B2                                   
#define LCD_DATA7       PIN_B3     

#define LCD_ENABLE_PIN  PIN_B4
#define LCD_RW_PIN      PIN_B5                                   
#define LCD_RS_PIN      PIN_B6                                   

 // Use the CCS driver in c:\Program Files\Picc\Drivers
#include <lcd.c> 
   
//==========================
void main()
{
lcd_init();  // Always call this first.

while(1)
  {
   lcd_putc("\fHello World");
   delay_ms(500);
   lcd_putc("\nLine Number 2");
   delay_ms(500);
  }

}

Does that work ?
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

Heavy Sigh....
PostPosted: Thu Jul 08, 2010 6:25 pm     Reply with quote

Using a PIC16F628A I can get the LCD to run using either the CCS lcd driver or the flex lcd driver.

Using a 16F88 I get the same old poor results...
(I thought for a moment it might be a low current to the LCD issue, so I switched to a wall wart from a battery pack with no effect.)

I received this input from the Pic-El designer, so I tried to mimic this setup as best as I understood it.

Code:

A 16F88A-E/P works fine in the PIC-EL. I do this with a assembler, though. I
use these config tags in my app.

__config _CONFIG1, _INTRC_IO & _WDT_OFF & _BODEN_OFF & _LVP_OFF & _PWRTE_ON &
_CCP1_RB3 & _MCLR_OFF
__config _CONFIG2, _IESO_OFF & _FCMEN_OFF


Here is my initialization code (in assembler)
============
clrf INTCON ; No interrupts for now Any Bank

banksel OSCCON ; Switch to bank 1
movlw 0x70 ; Set IRCF<2:0> = 7 (for 8 MHz Internal Osc)
movwf OSCCON ; Bank 1
movlw 0x07 ; Code to turn off the analog comparitors
movwf CMCON ; Turn off comparators (CM2,CM1,CM0 = 1)
; (16F88-> Bank 1)
clrf ANSEL ; Turn off Analog ('88 ONLY) Bank 1
bcf OPTION_REG,NOT_RBPU ; Enable weak pullups (!RBPU) Bank 1
movlw b'11100111' ; RA3,4 Outputs, all others Inputs
movwf TRISA ; Bank 1
movlw b'10000000' ; Port B is
movwf TRISB ; all outputs except RB7 is input Bank 1
banksel PORTA ; Switch back to bank 0
;
; New code for timer 1 and interrupt.
;
movlw 0xC0 ; Get GIE and PEIE bits
movwf INTCON ; Enable general interrupts
banksel PIE1 ; Switch to bank 1 to enable timer 1
movlw 0x01 ; Get bit to enable timer 1 interrupt
movwf PIE1 ; Set TMR1IE
banksel PORTA ; Switch to bank 0
============

Hope this helps. You will have to change it to run your analog ports but this
may be a good starting point for getting the LCD to work.

Best Regards,
-Craig, AA0ZZ



Attached is my exact test program.
If you change a few lines you can switch between the two chip types and re-compile. (Note that in flex_lcd.c on my system I have commented out the pin defines at the beginning so they would not overwrite what was in my program.


Code:
#include <16F88.H>
#fuses  XT, NOWDT, BROWNOUT, NOPUT, NOLVP
#use delay (internal=4MHz)


//defines for flex_lcd.c
#define LCD_DB4   PIN_B0
#define LCD_DB5   PIN_B1
#define LCD_DB6   PIN_B2
#define LCD_DB7   PIN_B3

#define LCD_E     PIN_B4
#define LCD_RW    PIN_B5
#define LCD_RS    PIN_B6
#define USE_LCD_RW   1 

// defines for lcd.c
#define LCD_DATA4       PIN_B0                                   
#define LCD_DATA5       PIN_B1                                   
#define LCD_DATA6       PIN_B2                                   
#define LCD_DATA7       PIN_B3     

#define LCD_ENABLE_PIN  PIN_B4
#define LCD_RW_PIN      PIN_B5                                   
#define LCD_RS_PIN      PIN_B6                                   

 // Use the CCS driver in c:\Program Files\Picc\Drivers
//#include <lcd.c>
// use the flex_lcd.c driver in c:\Program Files\Picc\Drivers
#include <flex_lcd.c>
   
//==========================
void main()
{


setup_comparator(NC_NC_NC_NC);
// comment out next line for 16F628A - it has no ADC ports
setup_adc_ports(ALL_ANALOG);
set_tris_a(0x11100111);
set_tris_b(0x10000000);
port_b_pullups(true);


// flash a few LEDs
volatile int8 i;
for (i=0 ; i<3; i++){
output_high(LCD_DB5);
output_high(LCD_DB6);
output_high(LCD_DB7);
delay_ms(200);
output_low(LCD_DB7);
delay_ms(200);

}

lcd_init();  // Always call this first.

switch (restart_cause()){
case WDT_FROM_SLEEP: lcd_putc("\fWDT From Sleep");
 break;
case WDT_TIMEOUT: lcd_putc("\fWDT Timeout");
 break;   
case MCLR_FROM_SLEEP: lcd_putc("\fMCLR From Sleep");
 break;   
case MCLR_FROM_RUN: lcd_putc("\fMCLR From Run");
 break; 
case NORMAL_POWER_UP: lcd_putc("\fNormal Power Up");
 break;   
case BROWNOUT_RESTART: lcd_putc("\fBrownout Restart");
 break;     
default:  lcd_putc("\fUnknown");
}
delay_ms(2000);

while(1)
  {
   lcd_putc("\fHello World");
   delay_ms(500);
   lcd_putc("\nLine Number 2");
   delay_ms(500);
  }

}


If Mr. PCM Programmer wants to take a crack at it, I am willing to send you my hardware.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 10:58 pm     Reply with quote

Ask him if he has code that will run a 16x2 LCD with the 16F88 on that
board (using the built-in LCD connector pins). Even if it's ASM code,
you could assemble it in MPLAB and at least prove that it works (or not).
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

Curiouser and Curiouser
PostPosted: Fri Jul 09, 2010 6:03 pm     Reply with quote

I am 'this close' to concluding that the PIC16F88 will not work in my board in spite of what the designer says. Shocked
I googled up some 'hello world' ASM code (attached - apologies to Nigel)

Once again, when targeted for the 16F628A it works, but not on the 16F88.

Here is what is interesting.
On my board, there are LEDS multiplexed on the pins that drive the LCD data lines.

This ASM program is designed to spell out the messages one char at a time with delays in between. I slowed that way down. This allows me to visually track the LEDs as the program goes through the loops.

The LED patterns and timing on the 628A and the 88 are identical.
I can tell where the program is by the pattern and speed of the LEDs.

Is this an electrical problem? My completely uneducated speculation is that the LCD needs more voltage or current than the 16F88 can provide.

I am gonna ask the designer to try this code on his board.

One final thought. Any idea what the difference between 16F88-E/P(automotive spec) and 16F88-I/P (industrial spec) is besides cost and temp range. (Do I have the wrong stupid part!!!!)

Any other ideas out there in PIC land? I am truly stumped.

K0JDD


Code:
;LCD text demo - 4 bit mode
;Nigel Goodwin 2002

;   LIST   p=16F628A      ;tell assembler what chip we are using
;   include "P16F628A.inc"      ;include the defaults for the chip
   LIST   p=16F88      ;tell assembler what chip we are using
   include "P16F88.inc"      ;include the defaults for the chip
   ERRORLEVEL   0,   -302   ;suppress bank selection messages

;   __config  _WDT_OFF & _XT_OSC & _LVP_OFF   
   __config _CONFIG1, _WDT_OFF & _XT_OSC & _LVP_OFF & _DEBUG_OFF         ;sets the configuration settings (oscillator type etc.)
   __config _CONFIG2, _FCMEN_OFF & _IESO_OFF


      cblock   0x20         ;start of general purpose registers
         count         ;used in looping routines
         count1         ;used in delay routine
         counta         ;used in delay routine
         countb         ;used in delay routine
         tmp1         ;temporary storage
         tmp2
         templcd         ;temp store for 4 bit mode
         templcd2   
      endc

LCD_PORT   Equ   PORTB
LCD_TRIS   Equ   TRISB
LCD_RS      Equ   0x06         ;LCD handshake lines
LCD_RW      Equ   0x05
LCD_E      Equ   0x04

      org   0x0000
;      clrf   ANSEL
      movlw   0x07
      movwf   CMCON         ;turn comparators off (make it like a 16F84)

Initialise   clrf   count
      clrf   PORTA
      clrf   PORTB



SetPorts   bsf    STATUS,      RP0   ;select bank 1
      movlw   0x00         ;make all pins outputs
      movwf   LCD_TRIS
      bcf    STATUS,      RP0   ;select bank 0

      call   Delay100      ;wait for LCD to settle


      call   LCD_Init      ;setup LCD


      clrf   count         ;set counter register to zero
Message      movf   count, w      ;put counter value in W
      call   Text         ;get a character from the text table
      xorlw   0x00         ;is it a zero?
      btfsc   STATUS, Z
      goto   NextMessage
      call   LCD_Char
      call   Delay255
      call   Delay255
      call   Delay255
      call   Delay255
      incf   count, f
      goto   Message

NextMessage   call   LCD_Line2      ;move to 2nd row, first column

      clrf   count         ;set counter register to zero
Message2   movf   count, w      ;put counter value in W
      call   Text2         ;get a character from the text table
      xorlw   0x00         ;is it a zero?
      btfsc   STATUS, Z
      goto   EndMessage
      call   LCD_Char
      call   Delay255
      incf   count, f
      goto   Message2

EndMessage   
      
Stop      goto   Initialise         ;endless loop




;Subroutines and text tables

;LCD routines

;Initialise LCD
LCD_Init   
      movlw   0x03      
      call   LCD_Cmd
      movlw   0x03         
      call   LCD_Cmd
      movlw   0x03      
      call   LCD_Cmd
      movlw   0x02         
      call   LCD_Cmd


      movlw   0x20         ;Set 4 bit mode
      call   LCD_Cmd

      movlw   0x28         ;Set display shift
      call   LCD_Cmd

      movlw   0x06         ;Set display character mode
      call   LCD_Cmd

      movlw   0x0d         ;Set display on/off and cursor command
      call   LCD_Cmd

      call   LCD_Clr         ;clear display

      retlw   0x00

; command set routine
LCD_Cmd      movwf   templcd
      swapf   templcd,   w   ;send upper nibble
      andlw   0x0f         ;clear upper 4 bits of W
      movwf   LCD_PORT
      bcf   LCD_PORT, LCD_RS   ;RS line to 0
      call   Pulse_e         ;Pulse the E line high

      movf   templcd,   w   ;send lower nibble
      andlw   0x0f         ;clear upper 4 bits of W
      movwf   LCD_PORT
      bcf   LCD_PORT, LCD_RS   ;RS line to 0
      call   Pulse_e         ;Pulse the E line high
      call    Delay5
      retlw   0x00

LCD_CharD   addlw   0x30
LCD_Char   movwf   templcd
      swapf   templcd,   w   ;send upper nibble
      andlw   0x0f         ;clear upper 4 bits of W
      movwf   LCD_PORT
      bsf   LCD_PORT, LCD_RS   ;RS line to 1
      call   Pulse_e         ;Pulse the E line high

      movf   templcd,   w   ;send lower nibble
      andlw   0x0f         ;clear upper 4 bits of W
      movwf   LCD_PORT
      bsf   LCD_PORT, LCD_RS   ;RS line to 1
      call   Pulse_e         ;Pulse the E line high
      call    Delay5
      retlw   0x00

LCD_Line1   movlw   0x80         ;move to 1st row, first column
      call   LCD_Cmd
      retlw   0x00

LCD_Line2   movlw   0xc0         ;move to 2nd row, first column
      call   LCD_Cmd
      retlw   0x00

LCD_Line1W   addlw   0x80         ;move to 1st row, column W
      call   LCD_Cmd
      retlw   0x00

LCD_Line2W   addlw   0xc0         ;move to 2nd row, column W
      call   LCD_Cmd
      retlw   0x00

LCD_CurOn   movlw   0x0d         ;Set display on/off and cursor command
      call   LCD_Cmd
      retlw   0x00

LCD_CurOff   movlw   0x0c         ;Set display on/off and cursor command
      call   LCD_Cmd
      retlw   0x00

LCD_Clr      movlw   0x01         ;Clear display
      call   LCD_Cmd
      retlw   0x00

LCD_HEX      movwf   tmp1
      swapf   tmp1,   w
      andlw   0x0f
      call   HEX_Table
      call   LCD_Char
      movf   tmp1, w
      andlw   0x0f
      call   HEX_Table
      call   LCD_Char
      retlw   0x00

Delay255   movlw   0xff      ;delay 255 mS
      goto   d0
Delay100   movlw   d'100'      ;delay 100mS
      goto   d0
Delay50      movlw   d'50'      ;delay 50mS
      goto   d0
Delay20      movlw   d'20'      ;delay 20mS
      goto   d0
Delay5      movlw   0x05      ;delay 5.000 ms (4 MHz clock)
d0      movwf   count1
d1      movlw   0xC7         ;delay 1mS
      movwf   counta
      movlw   0x01
      movwf   countb
Delay_0
      decfsz   counta, f
      goto   $+2
      decfsz   countb, f
      goto   Delay_0

      decfsz   count1   ,f
      goto   d1
      retlw   0x00

Pulse_e      bsf   LCD_PORT, LCD_E
      nop
      bcf   LCD_PORT, LCD_E
      retlw   0x00

;end of LCD routines

HEX_Table     ADDWF   PCL       , f
               RETLW   0x30
               RETLW   0x31
               RETLW   0x32
               RETLW   0x33
               RETLW   0x34
               RETLW   0x35
               RETLW   0x36
               RETLW   0x37
               RETLW   0x38
               RETLW   0x39
               RETLW   0x41
               RETLW   0x42
               RETLW   0x43
               RETLW   0x44
               RETLW   0x45
               RETLW   0x46


Text      addwf   PCL, f
      retlw   'H'
      retlw   'e'
      retlw   'l'
      retlw   'l'
      retlw   'o'
      retlw   0x00

Text2      ADDWF   PCL, f
               RETLW   'R'
               RETLW   'e'
               RETLW   'a'
               RETLW   'd'
               RETLW   'y'
               RETLW   '.'
               RETLW   '.'
               RETLW   '.'
               RETLW   0x00


      end
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 09, 2010 6:16 pm     Reply with quote

I was reluctant to suggest this, because I don't know how good you are
at soldering and rework. If you don't have the skills or the rework
station, you could burn off or tear up the pads on your board.
But...

1. Isolate all circuits on the board from the LCD.
Warm up the solder on one leg of each LED resistor and pull it the leg up
so it's not in contact with the pad. You need the FET circuits in place to
program the PIC, so you can't remove them. But you could at least
move the LCD pin from pin B6 to some other pin.

or,

2. Try breadboarding the 16F88 and LCD on a 3M protostrip.
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

Thanks for a new idea...
PostPosted: Fri Jul 09, 2010 6:45 pm     Reply with quote

I would definitely end up making trash out of the board. Shocked

I started with the PIC-EL at first because I wanted code that I knew worked...Embarassed Great plan, eh?

However, I do have a proto-board of the 'real' project I am trying to work on. The proto-board has an LCD wired into it and I can re-wire that board to use a pin other than B6.Cool

I will let you know...

(PS - I have challenged the Board Designer to make the 16F88 work...)
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

A closer look at pin b6
PostPosted: Sat Jul 10, 2010 9:53 am     Reply with quote

I looked closer at the Pic-El II schematic.
J1-2 on HDR1 allows me to disconnect B6 from everything except the LCD

Did it - no change.

Waiting to hear from other Pic-El users on other message board.
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

WHAT A MORON I AM!!
PostPosted: Sat Jul 10, 2010 1:19 pm     Reply with quote

Code:
setup_adc_ports(ALL_ANALOG);


is not the way to set ports to digital mode, that would be

Code:
setup_adc_ports(NO_ANALOGS);


Needless to say that was it... The forest obscurred the trees Embarassed

Thanks so much your help and more importantly for your patience...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 10, 2010 1:52 pm     Reply with quote

Right, but the little test program that I posted for you didn't have that
line in it:
http://www.ccsinfo.com/forum/viewtopic.php?t=42989&start=10
In your next post, you implied that you ran that program and it failed.
Were you actually editing the program and adding lines to it ?
If you were, that was the wrong way to use the help.
k0jdd



Joined: 06 Jul 2010
Posts: 13

View user's profile Send private message Send e-mail

Well...
PostPosted: Sat Jul 10, 2010 6:36 pm     Reply with quote

No deliberate were made changes. I ran your program just "as is" and it failed. But at the time I was very frustrated, and it was very late, and it is ENTIRELY possible I screwed it up unintentionally.

Sorry if I somehow appeared to be unappreciative of the help -- I REALLY AM!!! Thank you, Thank you, Thank you.


BTW I was able to learn a lot in the process. For example, I have redesigned my underlying project because I have learned that pin RA4 is an open collector and RA5 is an input only on a lot of PICS including the 16F88.

That would have caused problems in my design for sure.

Thanks once again.

John
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