processor expert, the mc9s08dz128mll and an 8bit 2x16 LCD

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

processor expert, the mc9s08dz128mll and an 8bit 2x16 LCD

1,609 Views
GMVS
Contributor III

hi

 

this is the first time i use the freescale technology and i'm having a couple of problems getting used to the processor expert

 

right now i', trying to connect a NHD‐0216K1Z‐FL‐YBW LCD to it. i attach the datasheets. i checked out the components library for 8bit 2x16 LCD but theres nothing about it, so i have to make the code myself.

 

it really confuses me the amount of files the pe has generated for it so far

 

i selected port K for my databus and pe created

Byte1.h

Byte1.c

where Byte1.h has methods for the byte and bit direct manipulation

and Byte1.c has a lot of stuff i dont quite get. well i do know what they are (more or less): methods for the byte and bit masked manipulation. but i dont understand what to do with such a file. the includes are for .h, so if i ever wanted to use the other methods how would i do that? what are the .c files for?

 

then i used port H for the extra signals and again i got

Bits1.h

Bits1.c

same problem

 

 

this files contributed to my headache also while trying to write the code for the LCD

 

lets see for example

sendCommand(cmd) //method in LCD.h that i made

it calls for

Byte1_PutVal(cmd) //method in Byte1.h that processor expert made

which calls for

setReg8(PTKD, Val) //stuff in the library? dunno who made that...

 

those kind of names, Byte1_PutVal(cmd), are completely meaningless to me. if i were using all available ports

Byte3_PutVal(a)

Byte5_PutVal(c)

Byte1_PutVal(d)

Byte2_PutVal(b)...

what the hell am i doing??

that kind of code is unreadable.  aint' there a way to change such generic names for something like

 

 

 

 

PutPortH(a)

PutPortA(c)

PutPortK(d)

PutPortC(b)

or better yet

PutLCDControlLines(a)

PutMemory1Address(c)

PutLCDBus(d)

PutLEDsData(b)

and such?

 

this problem, with the bits is a bigger nightmare

i have 20 files named from Bit1 to Bit20

each time i want to set or cleat a bit pin i have to go through all the files to check which one is the one i need, because neither the file name nor the method name say anything about the ports they mess around with

 

another problem

the initLCD() routine i made needs a busy wait of some ms

what would be the best way to implement this?

 

at first i thought about a flag4ms: i'd clear the flag and do a while(!flag4ms); waiting for the flag to be turmed on inside a timer interrupt (never do this on multithread system), but the isr is in one file and the initLCD is in another: how do i make flag4ms global?

 

or what better way is there to make the busy wait?

i'd count uint i; for (i=0; i<65535;i++) but

i don't think thats valid

i don't know how much time would that be, but i'm working at 16MHz so i dont think its enough

 

if i could make flag4ms global i could use the same interrupt to debounce buttons and other stuff

 

 

please help

i'm really confused

 

 

 

 

but everything

Labels (1)
4 Replies

1,158 Views
bigmac
Specialist III

Hello,

I have attached some LCD driver code that you may wish to consider, instead of using PE for the display interface.  The code actually uses 4-bit mode, which means that the interface can be accomplished using 7 bits of a single GPIO port.  The required delays are achieved using simple "calibrated" loops that can take into account the bus frequency used (see LCD.h file).

Regards,

Mac

0 Kudos
Reply

1,158 Views
GMVS
Contributor III

hi

still can't make the LCD work...

about this lines in the code you sent me

// This function for delays of up to 3000 cycles

// Delay formula: (12 * n + 30) cycles

static void delay( byte n)

{

   for ( ; n; n--);

}

please explain me what are the 12 and the 30 you use

btw i'm using a 16MHz mode

thanks

0 Kudos
Reply

1,158 Views
GMVS
Contributor III

hi

i'm still cant make the lcd work

when i'm running the debug everything seems to work

but when i run the program on the chip i don't see any signals being sent to the lcd

is there some special way to wire either?

this is my code...

////Procesorexpert.c

/* Including needed modules to compile this module/procedure */

#include "Cpu.h"

#include "Events.h"

//PTK - LCD.BUS

#include "LCDBus.h"

//PTD.6:7 - LCD.RS:ES

#include "LCDControlLines.h"

//PTL.5 - ALV

#include "ALV.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

#include "LCD.h"

/* Global variables*/

void main(void)

{

  /* Write your local variable definition here */

  char blaf[]= "hello world";

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

  PE_low_level_init();

  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */

  /* For example: for(;;) { } */

   

  initLCD();

  sendCharacter(blaf[0]);

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

////LCD.h

void waitu(word n)

{

  word x;

  ALV_PutVal(FALSE); //this is just to catch on the oscilloscope how many times i enter this routine. alv is normally high

  for (x=n ; x >0 ; x--);

  for (x=n ; x >0 ; x--);

  for (x=n ; x >0 ; x--);

  for (x=n ; x >0 ; x--);

  ALV_PutVal(TRUE);

}

void sendCommand(char a)

{

  LCDBus_PutVal(a); //put data on output Port

  LCDControlLines_PutVal(0); // RS=LOW : send instruction

  //R/W=LOW : Write by default

  LCDControlLines_PutVal(1); // E = 1: enable LCD;

  waitu(0x0001); //enable pulse width >= 300ns

  LCDControlLines_PutVal(0); // E = 0; Clock enable: falling edge

}

void sendCharacter(char a)

{

  LCDBus_PutVal(a); //put data on output Port

  LCDControlLines_PutVal(2); // RS=high : send data

  //R/W=LOW : Write by default

  LCDControlLines_PutVal(3); // E = 1: enable LCD;

  waitu(0x0001); //enable pulse width >= 300ns

  LCDControlLines_PutVal(2); // E = 0; Clock enable: falling edge

}

void initLCD()

{

  LCDControlLines_PutVal(0); // E = 0; Clock enable: falling edge

  waitu(0x1000); //48ms //Wait 20 msec after power is applied

  sendCommand(0x30); //command 0x30 = Wake up

  waitu(0x0110); //must wait 5ms, busy flag not available

  sendCommand(0x30); //command 0x30 = Wake up #2

  waitu(0x0010); //must wait 160us, busy flag not available

  sendCommand(0x30); //command 0x30 = Wake up #3

  waitu(0x0010); //must wait 160us, busy flag not available

  sendCommand(0x38); //Function set: 8-bit/2-line

  sendCommand(0x10); //Set cursor

  sendCommand(0x0c); //Display ON; Cursor ON

  sendCommand(0x06); //Entry mode set

}

it just ocurred to me... the processor expert turns on the watchdog by default?

0 Kudos
Reply

1,158 Views
eckhard
Contributor V

Hello,

if you switch to advanced or expert mode in the component inspector, you can change the component name.

You can look here for some good information on using Processor Expert MCU on Eclipse | Everything on CodeWarrior, Microcontrollers and Eclipse

You will find a link to the PE Components for Erich Styger to. There is a wait component that you can use for your Busy wait.

Eckhard