Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/15/04 03:29
Read: times


 
#83116 - The wanted code...
Responding to: ???'s previous message
Hi Gokul,

I have been an assembler guy for long- but now migrating to "C" with Keil. Looks like I have been missing out lots of fun all these days and once comfortable with "C" may never return to Assembly unless for tight time specific code.

Here is something that I wrote for the job what you want to do - just as a means to refurbish my C -skills which were left at the college. Normally full code is not given but I am doing it as a special case since you hail from the lovely Madurai where I did my engineering!! ( This code works for HD44780 type LCDs) Not commented in great detail. But I guess its OK for a small code like this..

/* =============== 2L_x_16C_TEST=============*/


/*====== Brief Description of program =======*/

/* Program to test out a 2 line LCD 
on 0803 PCB. It also toggles a LED.
Code compiled and checked OK 
on hardware. - 12 Nov 2004: 5.00PM */

/*==============Include Files ===============*/

#include <reg52.h>

/*============== Type Defines ================*/

typedef unsigned char tChar;
typedef unsigned int  tInt;
typedef unsigned long tLong;

/*============== Bit Defines =================*/

sbit LCD_RS = P1^0 ;
sbit LCD_R_W = P1^1;
sbit LCD_ENB = P1^2;

sbit TST_LED = P2^0;
bit  FLG_CPL;

/*==========Function Prototypes ==============*/

void ready(void);
void command(tChar);
void display(tChar *);
void msDelay(tInt);

/*================== MAIN ====================*/


void main(void)
{
  
  command(0x38);
  msDelay(1);
  command(0x38);
  msDelay(1);
  command(0x38);
  msDelay(1);
  command(0x0c);
  command(0x01);
  msDelay(5);

  display("PROGRAM TO TEST THE LCD MODULE..");

 while(1)
  {
   msDelay(10);

   if (FLG_CPL == 1)           // Toggle test LED 
   {
    FLG_CPL = 0;
    TST_LED = 0;
   }
   else
   {
    FLG_CPL = 1;
    TST_LED = 1;
   }
  }
    
}

/*=============================================*/

void command(tChar cmd)
{

ready();

P0 = cmd;

LCD_RS = 0;
LCD_R_W = 0;
LCD_ENB = 1;
LCD_ENB = 0;

}

/*=============================================*/

void ready(void)
{

msDelay(1);

}

/*==============================================*/

void display(tChar *msg)
{

 tInt count;

 for (count=0; count <= strlen(msg)-1; ++count)
     {
       if(count == 16)
       command(0xc0);

       ready();

       P0 = msg[count];

       LCD_RS = 1;
       LCD_R_W = 0;
       LCD_ENB = 1;
       LCD_ENB = 0;

      }
}

/*===============================================*/
void msDelay(tInt msec)
{

tInt cntr_1, cntr_2;

for (cntr_1 = 0; cntr_1 <= msec; ++cntr_1 )
    {
      for ( cntr_2 = 0; cntr_2 <= 5000; ++cntr_2);
    }
}
/*================================================*/



Revert back if it was of any help at all.

Raghu



List of 22 messages in thread
TopicAuthorDate
Help LCD--89C51 using KEIL            01/01/70 00:00      
   RE            01/01/70 00:00      
   Keil?            01/01/70 00:00      
      Keil App Notes            01/01/70 00:00      
   Assembler programmer learning C?            01/01/70 00:00      
   So what happened to the USB, then?            01/01/70 00:00      
   The wanted code...            01/01/70 00:00      
      code            01/01/70 00:00      
         Tips and Tricks.....Andy            01/01/70 00:00      
            volatile.            01/01/70 00:00      
               Not so volatile ?            01/01/70 00:00      
                  optimiser            01/01/70 00:00      
                     Volatile warning?            01/01/70 00:00      
                        not here            01/01/70 00:00      
                        re: volatile            01/01/70 00:00      
                           volatile            01/01/70 00:00      
      Another comment - symbolic names            01/01/70 00:00      
   c code for lcd            01/01/70 00:00      
      code            01/01/70 00:00      
         symbolic Port names            01/01/70 00:00      
   There's Gratitude for you! :-(            01/01/70 00:00      
   A better method in C            01/01/70 00:00      

Back to Subject List