Timing help / LCD

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

Timing help / LCD

Jump to solution
565 Views
jonathan_abbati
Contributor III

Hello Friends!

 

I am working with the MC9S12DG128 and attempting to utilize the onboard timer defined as TCNT. I am attempting to program the HD44780 LCD which is integrated on my EVALH1 board from technological arts. I have been following various online examples for 4 bit initialization and I believe that timing is the issue which I am having right now. My questions would have to be:

 

1) Is there a better timing method that you could think of?

2) Within code warrior is there a way that I can test if my delay is delaying to the proper time, I cannot seem to see where it shows the clock cycles.

 

Here is my timer & main code given in that order code:

 

Timer:

void timer_init(void)
{
  TSCR1 = 0x80; // SET TEN (TIMER ENABLE BIT)
  TSCR2 = 0x03; // SET PRESCALER TO DIVIDE BUS CLOCK BY 8 WHICH GIVES US A PERIOD OF 1uS
}

    void timer_wait1us(unsigned short z)
    {
      unsigned short start1; // NOTE THAT THE FIRST VALUE OF THE FOR LOOP HAS BEEN LEFT EMPTY SO WE MAY DEFINE IT WITHIN THE PROGRAM
        for(;z>0;z--)
        {
         
          start1 = TCNT;
          while ((TCNT - start1) <=1)  // -start1 IS USED TO SET THE TIMER BACK TO 0 BEFORE WE READ FROM IT
          {} 

        }
    }
     
  
   
        void timer_wait1ms (unsigned short x)
        {
          unsigned short start2;
            for(;x>0;x--)
            {
              start2 = TCNT;
              while ((TCNT - start2) <= 1000)
              {}

            }
        }

 

 

Main:

 

#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#include "Timer.h"

void toggle_enable(void);
void outcmd(unsigned char command);
void clear (void);
void output(unsigned char letter);

 


void main(void) {
unsigned long z;
DDRS = 0xFF;
DDRE = 0xFF;

timer_init();


timer_wait1ms(20);
outcmd(0x30);
timer_wait1ms(5);
outcmd(0x30);
timer_wait1us(160);
outcmd(0x30);
timer_wait1us(160);
outcmd(0x20);
timer_wait1ms(5);
outcmd(0x28);
timer_wait1ms(5);

outcmd(0x08);
timer_wait1ms(5);

clear();


outcmd(0x0E);
timer_wait1ms(50);


// CONSISTANT UNTIL HERE

outcmd(0x06);
timer_wait1ms(50);
outcmd(0x0C);
timer_wait1ms(50);

output(0x48);

 

 


EnableInterrupts;


  for(;:smileywink: {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}


void toggle_enable(void){

  PORTE_BIT4 = 1;
  timer_wait1us(2);
  PORTE_BIT4 = 0;
  timer_wait1ms(5);
}

void outcmd(unsigned char command){

  PTS = 0xF0 & command;
  toggle_enable();
  PTS = 0xF0 & (command<<4);
  toggle_enable();
}

void clear(void){
 
  outcmd(0x01);
  timer_wait1ms(5);
  outcmd(0x02);
  timer_wait1ms(5);
 
}

void output(unsigned char letter){
 
  PORTE_BIT7 = 1;
  toggle_enable();
  PTS = 0xF0 & letter;
  toggle_enable();
  PTS = 0xF0 & (letter<<4);
  toggle_enable();
}

 

Thank you so very much for your time I greatly appreciate anything you may be able to help me with!

Labels (1)
0 Kudos
1 Solution
452 Views
jonathan_abbati
Contributor III

Within the FCS ( full chip simulation) you can find time testing capabilities for your microcontroller based off of your bus clock. I have found that the easiest way to make a proper delay was through using for loops and creating a formula to find out how long each will be.

View solution in original post

0 Kudos
1 Reply
453 Views
jonathan_abbati
Contributor III

Within the FCS ( full chip simulation) you can find time testing capabilities for your microcontroller based off of your bus clock. I have found that the easiest way to make a proper delay was through using for loops and creating a formula to find out how long each will be.

0 Kudos