Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Digital clock program using AT892051

Status
Not open for further replies.

rohanmartin08

Newbie level 2
Joined
Jul 28, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
mumbai
Activity points
1,311
I have written a code for digital clock. Is the following code correct?



#include <AT892051.H>
#include <stdio.h>
#include <intrins.h>



sbit DigitShiftregisterSerialPin=P1^0; /* Character to be transfered through thisbit in parallel*/
sbit DigitShiftregisterClockPin=P1^1; /* Clock*/
sbit DigitShiftregisterLatchPin=P1^2; /* Latch*/
sbit DriveMinutes=P1^3; /* 1st 7-segment Display*/
sbit DriveTensMinutes=P1^4; /* 2nd 7-segment Display*/
sbit DriveHours=P1^5; /* 3rd 7-segment Display*/
sbit DriveTensHours=P1^6; /* 4th 7-segment Display*/


unsigned char SevenSegmentData;
unsigned char _crol_(unsigned char Temp,unsigned char SevenSegmentData);
char Display_Buffer[4];
int Dispcount;
int mscount;


int Hours=0;
int Minutes=0;
int Seconds=0;

char Temp;

code unsigned char DecimalToSevenSegment[11]=
{
0xEE,0x28,0xCD,0x6C,0x2B,0x67,0xE7,0x2C,0xEF,0x2F
};


void main()
{

TMOD=0x01;
TH0=0xF8; /* Initializing timer0 for 1ms*/
TL0=0x30;
IE=0x82;
TR0=1;



do
{

sprintf(Display_Buffer,"%02d%02d",Minutes,Hours); /* converting integer into character*/

}while(1);

}



void Timer0(void) interrupt 1 /* ISR begins*/
{
TF0=0;
TR0=0;
TH0=0xF8;
TL0=0x30;
TR0=1;

{
/* To transfer bits into byte from port pin onto the shift register*/
Dispcount++; /* Dispcount is used to refresh the Hours and Minutes on the LED*/
mscount++; /* Generate 1ms Delay*/
if(mscount>=1000)
{
mscount=0;
Seconds++;



if(Seconds>=60)
{
Seconds=0;
Minutes++;



if(Minutes>=60)
{
Minutes=0;
Hours++;



if(Hours>=13)
{
Hours=1;

}
}
}
}

// For LED's

{
int i,j=1;
if(Dispcount==29) /* This code is for refresh rate */
{
DriveMinutes=0;
DriveTensMinutes=0;
DriveHours=0;
DriveTensHours=0;


}
if(Dispcount==30)
{
if(j<=4)
{
SevenSegmentData=DecimalToSevenSegment[Display_Buffer[j]-'0'];
{
if (Dispcount==32)
{
Temp=SevenSegmentData;
}

{
DigitShiftregisterClockPin=1; /* clock is set high*/
/*}*/


if(8>i) /* For a byte to be read by the port pin*/
{


if (Dispcount==34)
{

/*if (Dispcount==36)
{*/
DigitShiftregisterSerialPin=Temp^7; /* Taking MSB one at a time, the loop continous till all 8-bits are sent to the portpin
}
if (Dispcount==38 )
{ */
DigitShiftregisterClockPin=0; /*clock is made low*/
}
if (Dispcount==40)
{
SevenSegmentData=_crol_(Temp,1); /* bits are rotated left*/
}
}
DigitShiftregisterLatchPin=0; /* Data is Latched*/
}


if(Display_Buffer[1])
{
DriveTensHours=1;

}
if(Display_Buffer[2])
{
DriveHours=1;

}
if(Display_Buffer[3])
{
DriveTensMinutes=1;

}
if(Display_Buffer[4])
{
DriveMinutes=1;

}
}

}
}
}
}
}
 

the first three rules of good programming are "comment, comment and comment".
 

Is the code for time atleast correct?

mscount++; /* Generate 1ms Delay*/
if(mscount>=1000)
{
mscount=0;
Seconds++;



if(Seconds>=60)
{
Seconds=0;
Minutes++;



if(Minutes>=60)
{
Minutes=0;
Hours++;



if(Hours>=13)
{
Hours=1;

}
}
}
}
Code:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top