Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] Controlling an LCD via a port expander

Status
Not open for further replies.

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Hi, I am using the PICDEM PIC18 Explorer with the PIC18f8722 micro. It connects to its LCM-S01602 DTR/m display via the MCP23S17 port expander. I am using the mikroC PRO compiler for programming.

Here is my code:

Code:
// Port Expander module connections
sbit  SPExpanderRST at RF6_bit;
sbit  SPExpanderCS  at RA2_bit;
sbit  SPExpanderRST_Direction at TRISF6_bit;
sbit  SPExpanderCS_Direction  at TRISA2_bit;
// End Port Expander module connections

void main() {

CMCON = 0x07;  // turn off comparators
ADCON1 = 0x3f; // set analog pins to digital I/O

SPI1_Init();

  SPI_Lcd8_Config(0);                     // Initialize Lcd over SPI interface
  SPI_Lcd8_Cmd(_LCD_CLEAR);               // Clear display
  SPI_Lcd8_Cmd(_LCD_CURSOR_OFF);          // Turn cursor off
  SPI_Lcd8_Out(1,3, "HELLO");            // Print text to Lcd, 1st row, 3rd column

}
When I program my PIC nothing is shown on the LCD, does anyone know why this is happening?

Thanks in advance,
Ely
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,664
Helped
14,077
Reputation
28,411
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,914
I don't see, that you setup the pin configuration according to the mikroC manual. Apparently you're not using the default pin assignments for the expander interface, then the assignment expected to be specified with the SPI_Lcd8_Config() command.
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Hi, thanks for the reply. I'm unsure what you mean. Here is the example schematic from mikroC PRO help files.

scheme_spi_lcd8.gif

The only difference between that and my own is that I have used PIC18f8722 and different ports.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,664
Helped
14,077
Reputation
28,411
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,914
I'm unsure what you mean.
According to the manual, rst and cs pins need to be specified.
Code:
void Spi_Lcd8_Config(char DeviceAddress, unsigned char * rstport, unsigned char rstpin, unsigned char * csport, unsigned char cspin);

Initializes LCD via SPI interface with pin settings (Reset pin and Chip Select pin) you specify.
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Both of those pins are specified as here:
Code:
// Port Expander module connections
sbit  SPExpanderRST at RF6_bit;
sbit  SPExpanderCS  at RA2_bit;
sbit  SPExpanderRST_Direction at TRISF6_bit;
sbit  SPExpanderCS_Direction  at TRISA2_bit;
// End Port Expander module connections
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
FvM, I think you are referring to older versions of mikroC. In the newer mikroC PRO for PIC versions, they are configured as Elyments has shown. The corrected code is:
Code:
// Port Expander module connections
sbit  SPExpanderRST at RF6_bit;
sbit  SPExpanderCS  at RA2_bit;
sbit  SPExpanderRST_Direction at TRISF6_bit;
sbit  SPExpanderCS_Direction  at TRISA2_bit;
// End Port Expander module connections

void main() {

     CMCON = 0x07;  // turn off comparators
     ADCON1 = 0x3f; // set analog pins to digital I/O

     SPI1_Init();

     SPI_Lcd8_Config(0);                     // Initialize Lcd over SPI interface
     SPI_Lcd8_Cmd(_LCD_CLEAR);               // Clear display
     SPI_Lcd8_Cmd(_LCD_CURSOR_OFF);          // Turn cursor off
     SPI_Lcd8_Out(1,3, "HELLO");            // Print text to Lcd, 1st row, 3rd column

     while(1);

}
I just added the while(1); line. This makes the microcontroller continuously loop over there. Unless you do that, the microcontroller does the job then goes back, restarts operations, undergoes all initialization, etc. You need to prevent the microcontroller from doing that.

I hope you made the necessary changes to the hardware.

Hope this helps.
Tahmid.
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Hi Tahmid, thanks for your reply. I added the while(1); line but still nothing is seen on the display when I program it. I cannot yet find the problem!
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Did you set the configuration bits properly? Did you adjust the pot (Contrast Adjustment)? Did you make the necessary changes in the hardware? Did you connect RST to RF6 and CS to RA2 instead of how they are shown in the mikroC example file?
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
RST is connected to RF6 and CS to RA2 so that part is ok.

There is no pot on this demo board to adjust contrast and the configuration bits are set in the code.

What do you mean by the necessary changes in the hardware?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,664
Helped
14,077
Reputation
28,411
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,914
A fixed contrast voltage of reasonable value would be O.K. as well.

Did you connect the SPI1 lines (SCK1, SDO1,SDI1) correctly?
Did you check, if SPI_Lcd8_Config(0) or the succeding commands change the level on any port expander output?
The ultimate test method would be either probing SPI respectively LCD line with a digital storage oscilloscope or logic analyzer. Or single stepping the code with a debug adapter in MPLAB.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
The configuration bits are set from Project > Edit Project. But I think you already know this.
What did you set for the oscillator? What is the oscillator frequency?
Does your hardware match the selected oscillator mode. If you selected HS or XT, did you use a crystal oscillator or resonator of the correct frequency?

---------- Post added at 21:54 ---------- Previous post was at 21:51 ----------

Did you connect pin9 (RG5 / MCRL) to +5v? Or did you disable MCLR?
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Hi, I can successfully program the port expander on its own so I think the problem is with the SPI_Lcd8_Config() command. I am wondering if this LCD display is controllable via this library?
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
Possibly not.

While there are several LCD controllers which claim to be HD44780 compatible, many have subtle differences in timing and delay requirements.

And unfortunately this illustrates one of the major problems with the MikroC Library Functions, without access to the source you can never be sure what is going on behind the scenes.

You might want to try adding a 20ms delay before call the LCD initialization routine, most LCDs require between 10ms and 20ms to run through their powerup cycle after voltage has stabilized to a required level. Any attempt to issue commands to the LCD before that point will result in improper initialization and operation of the LCD.

BigDog

---------- Post added at 19:18 ---------- Previous post was at 19:10 ----------

Are you using an LCD with HD44780 controller?
The Lumex LCM-S01602 DTR/M does not specific the controller use in their display in any of their documentation.

And from personal experience, does suffer from certain timing issues.
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
Tahmid, the display is a LCM-S01602 DTR/m, I cant find anywhere that says whether it is compatible.

BigDog, thanks for the idea; I added the delay but still nothing on the screen.
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
Yes the Lumex LCM-S01602 DTR/M can be finicky. I'll got close to a dozen on various Microchip dev boards here.

Have you thought about using the MikroC port expander channel with the LCD delay and command sequences from Microchip's demo program for that board?

By the way, what exactly are you getting on the display?

BigDog
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
There is a back light on the display but no text. The demo program for the board is written in assembly so I don't know how I can use this in mikroC.
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
There is a back light on the display but no text. The demo program for the board is written in assembly so I don't know how I can use this in mikroC.
Sounds like the LCD is not being initialized properly. I'll see if I can find some C18 or PICC18 code for the Explorer PIC18 board using the display.

Do you think you could pipe commands through the SPI expander channel setup by the MikroC library?

BigDog
 

Elyments

Junior Member level 3
Joined
Apr 11, 2010
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Cambridge, UK
Activity points
1,493
That's very kind of you!

Hopefully if the C18 code is simple enough for me to understand I can send the commands the mirkroC way!
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top