16x2 LCD interfacing using 8051

Dear Engs,

Kindly help me out as i'm short on time and stuck with the code only...I'm trying to make digital clock using Atmel89c51 with 16x2LCD....the problem is my LAB engineer has made us use mikroC compiler. Its more like a software then a programming language. The command line is totally different for MikroC.

The code i posses is 'C' code. although I've tried to adjust it according the MikroC command line. But now i'm short on few commands. Tell me where can I compile the code best to obtain a HEX file.

I'm posting the code check it out and point out any mistakes.

[quote=", post:, topic:"]

// Program to make a digital clock using LCD

#include

#define cont_port P3

#define port P1

#define dataport P2 // Data port for LCD

#define m_sec 10

sbit rs = cont_port^0;

sbit rw = cont_port^1;

sbit en = cont_port^6;

sbit dig_hr1=port^0;

sbit dig_min1=port^1;

sbit start=port^2;

sbit am_pm=port^3;

int hr ,hr1=0;

int min,min1=0;

int sec,sec1=0,dig_am_pm=0;

void delay(unsigned int msec) // Time delay funtion

{

int i,j ;

for(i=0;i<msec;i++)

for(j=0;j<1275;j++);

}

void lcd_cmd(unsigned char item) // Function to send command on LCD

{

dataport = item;

rs= 0;

rw=0;

en=1;

delay(1);

en=0;

return;

}

void lcd_data(unsigned char item) // Function to send data on LCD

{

dataport = item;

rs= 1;

rw=0;

en=1;

delay(1);

en=0;

return;

}

void lcd_data_string(unsigned char *str) // Function to send string on LCD

{

int i=0;

while(str!='\0')

{

lcd_data(str);

i++;

delay(1);

}

return;

}

lcd_data_int(int time_val) // Function to send number on LCD

{

int int_amt;

int_amt=time_val/10;

lcd_data(int_amt+48);

int_amt=time_val%10;

lcd_data(int_amt+48);

}

void lcd(unsigned char str1[10]) // Function to initialize LCD

{

lcd_cmd(0x38); //2 LINE, 5X7 MATRIX

lcd_cmd(0x0e); //DISPLAY ON, CURSOR BLINKING

delay(m_sec);

lcd_data_string(str1);

}

void set_hr1() // Function to set hour

{

hr1++;

if(hr1>11)

hr1=0;

lcd_cmd(0xc3);

lcd_data_int(hr1);

lcd_data(':');

}

void set_min1() // Function to set minute

{

min1++;

if(min1>59)

min1=0;

lcd_cmd(0xc6);

lcd_data_int(min1);

}

void main()

{

int k;

start=1;

dig_hr1=1;

dig_min1=1;

lcd_cmd(0x01);

lcd_cmd(0x83);

lcd("SET TIMING");

lcd_cmd(0xc3);

lcd_data_int(hr1);

lcd_data(':');

lcd_data_int(min1);

while(start==0)

{

delay(10);

if(dig_hr1==0)

set_hr1();

if(dig_min1==0)

set_min1();

}

if(am_pm==0)

{

lcd_cmd(0xc8);

lcd_data_string("am");

dig_am_pm=0;

}

if(am_pm==1)

{

lcd_cmd(0xc8);

lcd_data_string("pm");

dig_am_pm=1;

}

delay(200);

lcd_cmd(0x01);

while(1)

{

for(k=0;k<2;k++)

{

for(hr=hr1;hr<12;hr++)

{

for(min=min1;min<60;min++)

{

for(sec=0;sec<60;sec++)

{

lcd_cmd(0x82);

delay(1);

lcd_data_int(hr);

lcd_data(':');

lcd_data_int(min);

lcd_data(':');

lcd_data_int(sec);

if(dig_am_pm==0)

{

lcd("am");

}

else

{

lcd("pm");

}

lcd_data_string(" ");

delay(100);

}

}

min1=0;

}

if(dig_am_pm==0)

dig_am_pm=1;

else

dig_am_pm=0;

hr1=0;

}

}

}

[/quote]

I am surprised people still use these basic good-for-nothing Atmel controllers.

Did you not develop the software in the MikroC for 8051 IDE?

http://www.mikroe.com/eng/products/view/232/mikroc-pro-for-8051/

I could help if it were assembly language :(

[quote=“Asad, post:2, topic:16146”]

I am surprised people still use these basic good-for-nothing Atmel controllers.

Did you not develop the software in the MikroC for 8051 IDE?

http://www.mikroe.co…c-pro-for-8051/

[/quote]

Actually its an Educational IC hence as a student i’ve to use it…Although AT-MEGA is there but still as a beginner have to use it.

The problem with mikroC is it has its own command line not like C. I’ve tried adjusting it according to MikroC command line but there is some restriction to the code.

its like re-developing the whole thing.

anyways if you could link me to a beginners compiler it would be of much help.

MikroC would have a manual with beginner projects. Try consulting that.

Wouldn't you be better off with Keil?

[quote=“Asad, post:5, topic:16146”]

MikroC would have a manual with beginner projects. Try consulting that.

Wouldn’t you be better off with Keil?

[/quote]

Yeah! Although I’ve downloaded it but still need to take its tutorials. Anyways a new problem just poped up.

Help on this one.

The programme was for 16x2…but the LCD i’ve got is 16x1. For the time being i’ve abandoned the digital clock and playing with simple output displays and moving strings.

I’ve modified the code for 1 row BUT…the LCD i’ve got “16166 R2” is only initializing the first 8 columns and not the rest 8

The HEX code is all fine i’ve simulated it in Proteus with a 16x1 LCD. But the LCD i’ve got is only showing the first 8 columns…and thats freaking me out.

LCD controllers vary in how they interpret information being provided by the controller. Your best bet is the standard Hitachi LCD controller so look for that. in your 16x2 LCD

I think he is still trying to compile the code only. Real life debugging is next stage.

Mazahyr, have you written this code yourself or got it from somewhere and just trying to compile it with your Micro compiler thing?

[quote=", post:8, topic:16146"]

I think he is still trying to compile the code only. Real life debugging is next stage.

Mazahyr, have you written this code yourself or got it from somewhere and just trying to compile it with your Micro compiler thing?

[/quote]

Sorry for the late reply.

to be clear, there are 2 problems.!

The one stated at beginning of this topic is a Digital clock

This problem has to deal with the code and language. And yes the code is not mine completely. I’ve modified it.

The other problem which I’m currently facing is writing simple code using MikroC and running it.

It works perfectly fine when simulated using Proteus. I’m using a 16x1 LCD HD44780a00(controller).

Now while implementing the physical circuit and making it, only the first 8bits get initialized and the remaining 8bits aren’t working.

Although the pixels are glowing. The code is perfectly fine aswell as the circuit. I’m not able to figure it out…!

Example:

The data is presented on the first 8bits only. Whereas, when it is scrolled on the same 8bits the complete msg is shown. That shows that the uC is outputting the right data BUT it is not able to recognize whether its an 8x1 or a 16x1 MUX.

Help on this one.

And yes I know the simple solution lies within the LCD. Don’t suggest getting a new one.