Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nokia 3510i LCD with PIC24

Status
Not open for further replies.

mdanh2002

Member
Hi,

My Nokia 3510i LCD has been working well with a PIC16f88 for a while. Now I am trying to migrate the same code to a PIC24FJ64GA002. I am using MPLab C30 compiler. The PIC is configured to run on internal oscillator @ 8MHz. I am not using the PIC SPI module, just bit-banging. However, it doesn't work on the 24F. The LCD doesn't seem to initialize.

My connection from the PIC to the LCD is as follows (the PIC is running from 3.3V):

#define sclk PORTBbits.RB15
#define sdata PORTBbits.RB14
#define rest PORTBbits.RB9
#define cs PORTBbits.RB8

I have tried to test outputting square wave to these individual pins, just to confirm they can be used for output, and it works. Is there anything special about these pins, e.g. analog, comparators, oscillators that need to be disabled?

My code for the LCD (lcd.c) is attached. My main program code to initialize the LCD is:

_CONFIG2(FNOSC_FRCPLL & OSCIOFNC_ON & POSCMOD_NONE & I2C1SEL_PRI) // Internal FRC OSC = 8 MHz
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx1) //turn off junk we don't need

int main()
{
TRISB = 0x00;

CLKDIVbits.RCDIV0=0;
AD1PCFG = 0xFFFF;
AD1CON1 = 0; // Disable Analog
OSCCONbits.SOSCEN=0; //Disables the secondary oscilator

LCD_Initialize();
LCD_ColorSet(0); //256-color mode
LCD_Clear(255,0); //set all pixels to white
....
}

What could be the problems or where can I find proper SPI tutorials for the PIC24f? Many Thanks :)
 
Last edited:
To add on, one thing I don't really understand is the delay function on this PIC24, which I took from somewhere earlier:

#include <libpic30.h>

/*
delay_us(x) and delay_ms(x) for C30
*/
#ifndef __DELAY_H
#define FOSC 8000000LL // clock-frequecy in Hz with suffix LL (64-bit-long), eg. 32000000LL for 32MHz
#define FCY (FOSC/2) // MCU is running at FCY MIPS
#define delay_us(x) __delay32(((x*FCY)/1000000L)) // delays x us
#define delay_ms(x) __delay32(((x*FCY)/1000L)) // delays x ms
#define __DELAY_H 1
#endif

If the FOSC frequency is set properly, delay_us will be correct, e.g. delay_us(1) will delay 1 microsecond as checked by my scope. However, delay_ms(1) will only delay 250 microseconds, and not 1 milisecond. The only difference between these 2 functions is the divider, 1000000L and 1000L. I need to "patch" it for it to work correctly:

#define delay_ms(x) __delay32(((4*x*FCY)/1000L)) // delays x ms

I am not sure if this is related, but it seems that there are aspects of the PIC24 that I take for granted. Any ideas?
 
Last edited:
Any ideas? Strangely no response from the experts.

Both my Nokia 3510i and 5110 LCD works fine with a PIC 18F4550, but when the code is migrated to a 24F, both just fail to work.

Any advice is appreciated.
 
Okay, since nobody replies (and noone downloads the code), I am answering my own question.

The attached code is correct and there is nothing wrong. The only problem here is that the pin needs to be set via the latch register, LATBbits, and not the port register, PORTBbits. The reason for this is unclear (perhaps some timing issue). Most sites I found recommend using the LAT register for writing, and the PORT register for reading. I changed the code to:

#define sclk LATBbits.LATB9
#define sdata LATBbits.LATB8
#define rest LATBbits.LATB7
#define cs LATBbits.LATB6

and the LCD starts to initialize and works perfectly.

I hope this will help other with similar problems.
 
Sorry if no-one has replied... It may just be that no-one has tried to interface that LCD..... I believe they are nine bit serial displays that are difficult to set up a protocol.

There are newer displays that directly interface to an 8 bit parallel port... Some just don't like getting it wrong..
 
Hi Ian,

It's ok. I got it working. The LCD is using SPI and I am operating in 8-bit mode, e.g. you write one byte to change the color of one pixel at a time. I guess the title of the topic scares many people away, haha.

Btw, do you perhaps know the difference between writing to the latch and writing to the PORT register? I know the recommendation is to use latch for writing and PORT for reading, but again, both give the same waveform, so why doesn't writing to the PORT work as well? (On a PIC18, using both PORT and LAT will work for this LCD).
 
The only problem here is that the pin needs to be set via the latch register, LATBbits, and not the port register, PORTBbits. The reason for this is unclear (perhaps some timing issue).

Hi the Latch registers are a double-buffered register for the ports. The reason is to prevent Read-Modify-Write errors. When you write to the Port (rather than latch), the CPU actually reads the port and writes the values back. If any pins on the port are read as a 0 due to a high load on the port, and are set as a 1 in program, then you will get a RMW error when it writes the incorrect value back to the port.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top