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

Back to Subject List

Thread Closed: Issue successfully resolved

???
12/18/04 18:42
Read: times


 
#83427 - C Code for LCD
Hi,
I was looking for a C source code for my Display with HD44780 using KEIL C51. Finally I've found the code what I exactly need, on these Message Boards. This code is written by Raghunathan. Then I made a few small changes on it and tried to apply it on my own SAB80C537 Microcontroller Board with 12 MHz Oszilator. The problem is; I didn't get any reactions from the display. The final code which I tried to execute on my Board is given below;

/* =============== 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>
#include <string.h>

/*============== Type Defines ================*/
typedef unsigned char tChar;
typedef unsigned int tInt;
typedef unsigned long tLong;

/*============== Bit Defines =================*/
sfr P4 = 0xe8;
sbit LCD_RS = P4^0;
sbit LCD_R_W = P4^1;
sbit LCD_ENB = P4^2;

sbit TST_LED = P3^0;
bit FLG_CPL;

/*==========Function Prototypes ==============*/
void ready(void);
void command(tChar);
void display(tChar *);
void msDelay(tInt);

/*================== MAIN ====================*/
void main(void)
{
msDelay(3);
command(0x38);
msDelay(1);
command(0x38);
msDelay(1);
command(0x38);
msDelay(1);
command(0x0c);
command(0x01);
msDelay(5);

display("TEST");

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

/*===============COMMAND==============================*/
void command(tChar cmd)
{
ready();
P1 = cmd;

LCD_RS = 0;
LCD_R_W = 0;
LCD_ENB = 1;
msDelay(2);
LCD_ENB = 0;
}

/*================READY=============================*/
void ready(void)
{
msDelay(1);
}

/*================DISPLAY==============================*/
void display(tChar *msg)
{
tInt count;
for (count=0; count <= strlen(msg)-1; ++count)
{
if(count == 16)
command(0xc0);
ready();
P1 = msg[count];
LCD_RS = 1;
LCD_R_W = 0;
LCD_ENB = 1;
msDelay(1);
LCD_ENB = 0;
}
}

/*==================MSDELAY=============================*/
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);
}
}
/*================================================*/


It will be very nice from you if you make a few comments on it.
Best Regards
Mehmet KURT

List of 13 messages in thread
TopicAuthorDate
C Code for LCD            01/01/70 00:00      
   code            01/01/70 00:00      
      Changes as comments            01/01/70 00:00      
         re: code            01/01/70 00:00      
   debugging?            01/01/70 00:00      
      Points to check            01/01/70 00:00      
         solution            01/01/70 00:00      
   lcd display problem            01/01/70 00:00      
      how to help when not knowing with what            01/01/70 00:00      
         lcd display problem            01/01/70 00:00      
      Contrast Problem.            01/01/70 00:00      
         CONTRAST pot ?            01/01/70 00:00      
            lcd display problem ....solved            01/01/70 00:00      

Back to Subject List