Lcd Code

Discussion to talk about software related topics only.
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Lcd Code

Post by chrispol »

Hi I'm looking to interface a 4bit lcd, to my mod5282, this is my first netburner project moving from pics, can anyone help me out?
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Lcd Code

Post by v8dave »

Hi Chris,

Is this a mono LCD? Can you give a part no. so we can see the interface for it?

If it is, then the S1D13700 from Epson is a likely controller that you can hook up to the Netburner modules. You can also use the RA8835 from RAiO in Taiwan which is a replacement for the older Epson SED1335 but it requires external RAM, whereas the S1D13700 has this built into the controller.

There is also the older SED1335 from Epson but I would avoid this as it has a nasty hardware bug that causes flicking on the display if you are using fast updates to the LCD. Not sure if the RA8835 has this fixed as not tried it yet.

I found this in one quick search.

http://www.lcdinfo.com/products/usb13700.html

Good luck.
Dave...
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Re: Lcd Code

Post by chrispol »

QY-162A 8 bit parallel, would like to run it in 4 bit, also trying to figure out the pwm, whats the lowest frequency hardware pwm can do on the 5282?

Thanks
Chris
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Lcd Code

Post by v8dave »

Hi, you can run this LCD as 4 bit and you can ignore my first posting as I hadn't realised it was a text display.

There is hundreds of drivers out there for these displays. They are easy to hook up to micros so you should be able to get it going quite quickly.

The driver is based around the Hitach HD44780.

Good luck
Dave...
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Re: Lcd Code

Post by chrispol »

I was looking around, but i am a bit confused on how to set the gpio's
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Re: Lcd Code

Post by chrispol »

Ok wired up a lcd

#define lcdRS J1[23]
#define lcdE J1[22]
#define lcdD4 J1[25]
#define lcdD5 J1[24]
#define lcdD6 J1[27]
#define lcdD7 J1[26]

been looking for docs on how to write the data lines, instead of doing it by bits,

for init could send 0x2,0xc0xc,0x1,0x6 instead of setting each pin and sending 0010,1100,0001,0110 etc.....
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Re: Lcd Code

Post by chrispol »

Can anyone give me a hand with this? i've put together some code but having issues.... this is on a mod5282

lcdRS J1[5]
lvdE J1[6]

Code: Select all

void lcdSendCmd(char c)
{
  int h=c/16;
  int l=c%16;

  lcdRS = 0;
  lcdE  = 0;
  sim.gpt[1].port = h;
  lcdE  = 1;
  OSTimeDly(1); //450ns min

  lcdE = 0;
  OSTimeDly(1); //5ms command 200us data


  sim.gpt[1].port = l;
  OSTimeDly(1); //450ns min

  lcdE  = 0;
  OSTimeDly(1); //5ms command 200us data
}

void lcdSendChar(char c)
{
  int h=c/16;
  int l=c%16;

  lcdRS = 1;
  lcdE  = 0;
  sim.gpt[1].port = h;
  lcdE  = 1;
  OSTimeDly(1); //450ns min

  lcdE = 0;
  OSTimeDly(1); //5ms command 200us data


  sim.gpt[1].port = l;
  OSTimeDly(1); //450ns min

  lcdE  = 0;
  OSTimeDly(1); //5ms command 200us data
}

void lcdPutString(char  str[])
{
    for (unsigned int i=0; i<strlen(str); i++)
    {
       lcdSendChar(str[i]);
       OSTimeDly(2);
    }
}

void InitLcd()
{
   /*
   * lcdRW
   * lcdRS
   * lcdE
   * Data sim.gpt[1]
   */

  sim.gpt[1].scr1 = 0;          //turn off gpt

  OSTimeDly(1);

  for(int i=0;i<3;i++)
  {
      lcdSendCmd(0x03);
  }

  lcdSendCmd(0x28);             //4 bits 2 lines
  lcdSendCmd(0x08);             //enable & display cursor
  lcdSendCmd(0x01);             //clear
  lcdSendCmd(0x06);             //cursor positioning
  lcdSendCmd(0x0C);             //turn on display
}

thanks
Chris
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Lcd Code

Post by Ridgeglider »

Looks like your 2nd line has a typo:
lcdRS J1[5]
lvdE J1[6]

Looks like your first two lines may need a typedef:
typedef lcdRS J1[5]
typedef lcdE J1[6]

Looks like there are some issues with the delays:
OSTimeDly(1) will be 1/20th of a sec, or 50mSec.

Not sure what you are upto with these lines:
sim.gpt[1].port = h;
sim.gpt[1].port = l;

There are many other GPT, PIT or DMA timers if you need shorter durations. See:
1) TheStopwatch.h and stopwatch.cpp app posted to this forum:
http://forum.embeddedethernet.com/viewt ... f=7&p=1945 or
2) The PIT appnote on the 5258 page:
http://www.netburner.com/downloads/mod5 ... ppNote.pdf
chrispol
Posts: 30
Joined: Mon Mar 08, 2010 8:46 am

Re: Lcd Code

Post by chrispol »

the first 2 lines are actually defines, i just included them so you could know what pins they are on....

i saw an example somewhere where the guy was just using OSTimeDly(1) seconds

sim.gpt[1].port = h; high part of the byte
sim.gpt[1].port = l; low part of the byte
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Lcd Code

Post by Ridgeglider »

Take a look at the descriptions and use of OSTimeDly( n ) in

C:\Nburn\docs\NetworkProgrammersGuide\NNDKProgMan.pdf
C:\Nburn\docs\NetBurnerRuntimeLibrary\uCOSLibrary.pdf

By default, each tick "n" in OSTimeDly() is worth 50mSec. This can be changed by edits to the TICKS_PER_SECOND macro in ucos.h. The default for TICKS_PER_SECOND is 20, ie 1/20th sec = 50 mSec. If you edit ucos.h, rebuild the system. However, in my experience there are much better ways to create short delays than by changing the number of TICKS_PER_SECOND.

There is no need to fool around with the sim.gpt[1].port = h; calls to create these simple delays.
Post Reply