Discussion in "Project Addition or Changes" started by    adambose1990    Oct 11, 2011.
Tue Oct 11 2011, 08:02 AM
#1
Hi guys, here is a simple project I have done in 89s52 IC of 8051 series. Making a Digital Clock.


Components required:
1 microcontroller 89C52(89S52 will also do)
2 ceramic capacitors-22pF
1 switch(button for reset purpose)
1 electrolytic capacitor-10uF,25V
1 crystal oscillator-11.0592MHz
16x2 LCD display
1 resistor-10k


Software you will need:
The programming of the microcontroller is done using keil compiler. Port 2 is output port, This LCD is in 8bit mode.
Details of LCD you can have here.

http://www.mikroe.com/eng/chapters/view/17/chapter-4-examples/

Circuit Diagram:



The detail explanation of the code is done below:


//main.c
#include <REG51.H>

#include "lcd.h"

void ms_delay(int time)
{
	unsigned int i,j;
	for(i=0;i<time; i++)
		for(j=0;j<=1275;j++);
}

void main(void)
{   
   	int hr=00,min=00,sec=00,flag=0;
	LCD_init();
   	LCD_putnum(hr,2);		   //|HH:MM:SS 	AM
   	LCD_sendstring(":");
	LCD_putnum(min,2);
	LCD_sendstring(":");
	LCD_putnum(sec,2);
	LCD_sendstring("  AM");
   while(1)
   {
	for (sec=0;sec<60;sec++)
    {				
		LCD_gotoxy(6,0);
		LCD_putnum(sec,2);
		ms_delay(142);
		if (sec==59)
	    { 
			min=min+1;
			if(min==60)
			{
		  		if(hr==11&&sec==59)
		    	{
					hr=0;
					min=0;
					sec=-1;
					flag=~flag;
					LCD_gotoxy(0,0);
					LCD_putnum(hr,2);
					LCD_gotoxy(3,0);
					LCD_putnum(min,2);
					LCD_gotoxy(10,0);
					if (flag==0)
						LCD_sendstring("AM");
					else
						LCD_sendstring("PM");
				}
		  		else
				{   
					hr=hr+1;
					min=0;
					LCD_gotoxy(0,0);
					LCD_putnum(hr,2);
					LCD_gotoxy(3,0);
					LCD_putnum(min,2);
				}
			}
			LCD_gotoxy(3,0);
			LCD_putnum(min,2);
	    }
	} 
   }		
}


But before that you have to make lcd.h file. Its codes are given also here. This Header is specially made for this program.
//lcd.h
#ifndef __LCD_H__
#define __LCD_H__

#define LCD_data P2


void _LCD_busy(void);
void _LCD_sdelay(void);
void _LCD_poweron(void);
void _LCD_command(unsigned char);
void _LCD_senddata(unsigned char);
void _LCD_sendstring(unsigned char *);
void _LCD_putnum(int, int);
void _LCD_init(void);
void _LCD_clear(void);

sbit LCD_rs=P1^0;
sbit LCD_rw=P1^1;
sbit LCD_en=P1^2;

void LCD_busy()
{
    unsigned char i,j;
        for(i=0;i<50;i++)
                for(j=0;j<255;j++);
}

void LCD_sdelay()
{
    unsigned char i;
        for(i=0;i<50;i++);
}

void LCD_poweron()
{
unsigned int i;
for (i=0;i<22500; i++);
}

void LCD_command(unsigned char var)
{
     LCD_data  = var;      //Function set: 2 Line, 8-bit, 5x8 dots
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in instruction register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
}

void LCD_putnum(int number,int width)// LCD_putnum: Implementing integer value from -99999 to 99999
{
   unsigned char digit;

   if (number < 0) 
   {
     LCD_senddata('-');
	 LCD_sdelay();
	 number = -1 * number;
   }

   switch (width)
   {
   		case 5:
			digit = '0';
			while(number >
= 10000)                // Keep Looping for larger than 10
   			{
     			digit++;                         // Increase ASCII character
     			number -= 10000;                    // Subtract number with 10
   			}
			LCD_senddata(digit);                // Put the Second digit
			LCD_sdelay();
	   case 4:
			digit = '0';
			while(number >
= 1000)                // Keep Looping for larger than 10
   			{
     			digit++;                         // Increase ASCII character
     			number -= 1000;                    // Subtract number with 10
   			}
			LCD_senddata(digit);                // Put the Second digit
			LCD_sdelay();
		case 3:
			digit = '0';
			while(number >
= 100)                // Keep Looping for larger than 10
   			{
     			digit++;                         // Increase ASCII character
     			number -= 100;                    // Subtract number with 10
   			}
			LCD_senddata(digit);                // Put the Second digit
			LCD_sdelay();
		case 2:
			digit = '0';
			while(number >
= 10)                // Keep Looping for larger than 10
   			{
     			digit++;                         // Increase ASCII character
     			number -= 10;                    // Subtract number with 10
   			}
			LCD_senddata(digit);                // Put the Second digit
			LCD_sdelay();
		case 1:
			LCD_senddata('0' + number);           // Put the First digit
			LCD_sdelay();
   }
}

void LCD_sendstring(unsigned char *var)
{
     while(*var)              //till string ends
       LCD_senddata(*var++);  //send characters one by one
}

void LCD_senddata(unsigned char var)
{
     P2  = var;      //Function set: 2 Line, 8-bit, 5x7 dots
     LCD_rs   = 1;        //Selected data register
     LCD_rw   = 0;        //We are writing
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     //LCD_busy();          //Wait for LCD to process the command
}

void LCD_init(void)
{
     LCD_data = 0x38;     //Function set: 2 Line, 8-bit, 5x8 dots
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data  = 0x0C;     //Display on, Curson blinking off command
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data  = 0x01;     //Clear LCD
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data  = 0x06;     //Entry mode, auto increment with no shift
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;        //Enable H->
L
     LCD_busy();
}

void LCD_clear(void)
{
	LCD_data  = 0x01;     //Clear LCD
    LCD_rs   = 0;        //Selected command register
    LCD_rw   = 0;        //We are writing in data register
    LCD_en   = 1;        //Enable H->
L
    LCD_en   = 0;
    LCD_busy();
}

     
void LCD_gotoxy(int x, int y)//x=0..16, y= 0..1 
{      
  int dr;
  if (y==0)
  	dr=x+0x80;      
  if (y==1)       
    dr=x+0xC0;            
  LCD_data  = dr;      //Function set: 2 Line, 8-bit, 5x8 dots
  LCD_rs   = 0;        //Selected command register
  LCD_rw   = 0;        //We are writing in instruction register
  LCD_en   = 1;        //Enable H->
L
  LCD_en   = 0;
  LCD_busy();        
}

#endif


Thanks a lot...
For any quarries you can contact adambose1990@gmail.com
Tue Oct 11 2011, 08:09 AM
#2
You can download the following attachents
.Hex file
.H file
.C file
.DSN file
They are all in rar file. Extract them all.
Attachment
Tue Oct 11 2011, 12:05 PM
#3
@ adambose1990
good efforts
use timer for clock that will be more accurate as compare to looping
Thu Oct 13 2011, 11:51 AM
#4
good work adambose

and i completely agree with Majoka, you must use timers for tick generation. I will be much more accurate
Fri Oct 14 2011, 12:31 PM
#5
@Ajay Bhargav yes surely, This project is not accurate only because of the tick generation, it lags a few second in an RTC hour, I surely will follow your advice, thanks........:)
Tue Nov 01 2011, 04:20 PM
#6
Additional advice for error free timers; use timer in free running mode so that you dont have to do load operation for timers. This way your timer will always overflow at perfect intervals, no matter how late your ISR is serviced

Also use 12Mhz for best results with above method.
Thu Nov 03 2011, 08:04 AM
#7
Thanks a lot Ajay sir...:)
Sun Nov 06 2011, 02:17 AM
#8
You're welcome good luck for your Final Year
Fri Feb 10 2012, 05:26 AM
#9
Its a good and lot of information on your site and good collection of information for digital 8051. thanks for sharing the information.
Fri Feb 10 2012, 06:15 AM
#10
Hi jamewhite86, To know more digital 8051, have a look into this site : www.rsatechbook.webs.com
There is a lot not only about 8051, but also about AVR and PIC unique projects...... Have a good day...
http://rsatechbook.webs.com/

Get Social

Information

Powered by e107 Forum System
Forum Activity
pravin_35 Avatar
Posted By pravin_35
Sat Jul 26 2014, 01:34 AM
its reading 0x00 device ID, which means either dev...
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Jul 25 2014, 05:37 PM
its reading 0x00 device ID, which means either dev...
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Jul 25 2014, 05:32 PM
I get it now.. Did not read that part, sorry for m...
PavanKh Avatar
Posted By PavanKh
Fri Jul 25 2014, 01:09 AM
hello everyone ! I'm using SIM900A GSM module to s...
pravin_35 Avatar
Posted By pravin_35
Thu Jul 24 2014, 01:28 PM
Please post a diagram of the board the PIC is moun...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 24 2014, 12:52 PM
Please post a diagram of the board the PIC is moun...
pravin_35 Avatar
Posted By pravin_35
Thu Jul 24 2014, 12:08 PM
screen shot
pravin_35 Avatar
Posted By pravin_35
Thu Jul 24 2014, 08:19 AM
What kind of sample code are you looking for? any ...
nisargpatel Avatar
Posted By nisargpatel
Thu Jul 24 2014, 06:35 AM
yes ds1307 keeps time on same crystal 32.76.. but ...
pravin_35 Avatar
Posted By pravin_35
Thu Jul 24 2014, 04:35 AM
Does the DS1307 keep time ?That is, if you set it ...

Conversation

ajay_bhargav
Thu Jul 24 2014, 01:06 AM
@R.ABHISHEK where? I dont see it. is it in forum?
Wed Jul 23 2014, 05:49 AM
R.ABHISHEK
sir,pls message on microcontroller 8051 assambly language new program
Wed Jul 23 2014, 05:47 AM
R.ABHISHEK
sir,pls message on 8051 microcontroller assambly language program new quastions
ajay_bhargav
Tue Jul 22 2014, 09:18 AM
@Pragya Android application is taken from google play. Only Author has its source with him. Application is only used in this project.
Tue Jul 22 2014, 04:58 AM
Pragya
plz send me 8051 code and android code for android based device controller via Bluetooth .Here in this project I am using Hc-06 Bluetooth module
Thu Jul 10 2014, 09:57 AM
Caleb
plz someone mail me the source code for that project
Thu Jul 10 2014, 09:57 AM
Caleb
http://www.8051projects.net/download-d188-control-your-pc-tv-remote.html
ExperimenterUK
Tue Jul 08 2014, 03:25 PM
Post questions in the forum.. this area is for chat
Tue Jul 08 2014, 08:15 AM
P.Panchanyam
Sir i want some new ideas for my final year projects ,which would help for our soceity in future
Tue Jul 08 2014, 01:39 AM
jasvinder
Dear Sir Ref. to the discussion held with under sign, the detail is as under--- We are in weighing scale field since 1986. We are assembling the scales by purchasing the material from out source ( From India and other countries). Now we decide to make our own Card in our decided shape. So we want to develop a universal card , which we can make all types of scales of up 100000 counts with 7 segment LED Display . Also with other features like Printing, Counting, RS232 Etc. And Three Pass words at different levels. And we can edit the Softwear. What else you can provide in this field, also mention. We will pay you the development , softwear and testing charges. And up-gradation charges at time to time. Our web site is modern-scales.com Kindly revert.

Downloads

Comments

Imran.pk
Fri Jul 25 2014, 07:50 PM
PavanKh
Fri Jul 25 2014, 12:56 AM
vinosentinal
Mon Jul 21 2014, 08:28 PM
niks_here
Sun Jul 20 2014, 05:38 PM
athiramsankar
Sun Jul 20 2014, 12:00 PM
salemalqahtani
Sun Jul 20 2014, 12:55 AM
nagarajan.electro
Sat Jul 19 2014, 12:49 AM
praru
Sat Jul 12 2014, 07:51 AM

Online

Guests: 35, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 01:37 AM

Members: 37481
Newest member: Imran.pk