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.

help,how to convart clock 12 hours formet ??

Status
Not open for further replies.

md.rokon

Junior Member level 1
Joined
Jan 12, 2011
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,387
help,how to convart clock 12 hours formet ??
 

Attachments

  • Digital Clock AT89c2051MODI.rar
    127.2 KB · Views: 106

plz help rtc 12 hours
 

what is the problem that you are facing ?
 

work is fine so..hours show 13:00:00, how to hours 1:00:00??
 

Two possible ways
1. substract 12 from hours value in BCD arithmetic
2. set the RTC to 12 hours mode (the dataseheet tells how)
 

you can set the 12 hrs mode by enabling the 6th bit of Hour register ( for DS 1307). then the 5th bit indicates the AM/PM( 1 for PM and 0 for AM)
 

how to change 12 hours ????any idea??
#include<reg52.h>
sbit DATA1 = P1^4;
sbit SCK1 = P1^5;
sbit LACH1 = P1^6;
sbit set=P1^3;
sbit up=P1^2;
sbit down=P1^1;
unsigned char hour, minute, second,c;
unsigned char ma[]={0x3F,0x6,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char kt=0,a=0,i,k,x=0;
bit set0=1,set1=1,up1=1,up0=1,down0=1,down1=1;
sbit SCL = P3^4;
sbit SDA = P3^5;
void delay(){
unsigned char i;
for (i = 0; i < 4; i++){};
}

//-----------------------------------------
void SCL_high(){
SCL = 1;
delay();
}

//------------------------------------------
void SCL_low(){
SCL = 0;
delay();
}

//-------------------------------------------
void I2C_Start(){
SDA = 1;
SCL = 1;
SDA = 0;
delay();
SCL = 0;
SDA = 1;
}

//--------------------------------------------
void I2C_Stop(){
SDA = 0;
SCL_high();
SDA = 1;
}

//----------------------------------------------
bit I2C_Write(unsigned char dat){
unsigned char i;
bit outbit;
for (i = 1; i <= 8; i++){
outbit=dat&0x80;
SDA = outbit;
dat = dat << 1;
SCL_high();
SCL_low();
}
SDA = 1;
SCL_high();
outbit = SDA;
SCL_low();
return(outbit);
}

//----------------------------------------------------
unsigned char I2C_Read(bit ack)
{
unsigned char i, dat;
bit inbit;
dat = 0;
for(i=1;i<=8;i++)
{
SCL_high();
inbit = SDA;
dat = dat << 1;
dat = dat | inbit;
SCL_low();
}
if (ack) SDA = 0;
else SDA = 1;
SCL_high();
SCL = 0;
SDA = 1;
delay();
return(dat);
}

//-------------------------------------------------------------
void rtc_write(unsigned char add, unsigned char dat){
I2C_Start();
I2C_Write(0xd0);
I2C_Write(add);
I2C_Write(((dat/10)<<4)|(dat%10));
I2C_Stop();
}

unsigned char rtc_read(unsigned char add){
unsigned char dat;
I2C_Start();
I2C_Write(0xd0);
I2C_Write(add);
I2C_Start();
I2C_Write(0xd1);
dat = I2C_Read(0);
I2C_Stop();
dat = (dat & 0x0F) + (dat>>4)*10;
return (dat);
}
void writeds(){
rtc_write(0x00, second);
rtc_write(0x01, minute);
rtc_write(0x02, hour);
}

void readds()
{
if(kt==0)
{
if(a==1)
{writeds();a=0;
}
second = rtc_read(0x00);
minute = rtc_read(0x01);
hour = rtc_read(0x02);
}
}

void hienthi(unsigned char x)
{
unsigned int i,temp;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA1=1;
else
DATA1=0;
x*=2;
SCK1=0;
SCK1=1;
}
}
void quetled()
{

if(kt==0)
{
hienthi(ma[second%10]);
hienthi(ma[second/10]);
hienthi(ma[minute%10]);
hienthi(ma[minute/10]);
hienthi(ma[hour%10]);
hienthi(ma[hour/10]);
LACH1=0;
LACH1=1;
}
if(kt==1)
{
hienthi(0x00);
hienthi(0x00);
hienthi(0x00);
hienthi(0x00);
hienthi(ma[hour%10]);
hienthi(ma[hour/10]);
LACH1=0;
LACH1=1;
}
if(kt==2)
{
hienthi(0x00);
hienthi(0x00);
hienthi(ma[minute%10]);
hienthi(ma[minute/10]);
hienthi(0x00);
hienthi(0x00);
LACH1=0;
LACH1=1;
}
if(kt==3)
{
hienthi(ma[second%10]);
hienthi(ma[second/10]);
hienthi(0x00);
hienthi(0x00);
hienthi(0x00);
hienthi(0x00);
LACH1=0;
LACH1=1;
}
}
void ktphim()
{
set0=set1;set1=set;
if((set0==1)&&(set1==0))
{
kt++;
if(kt>3)kt=0;
}
switch(kt)
{
case 0:break;
case 1:
{
up0=up1;up1=up; a=1;
if((up0==1)&&(up1==0))
{
hour++;
if(hour>20)hour=0;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
hour--;
if(hour==-1)
hour=23;
}
break;
}
case 2:
{
up0=up1;up1=up; a=1;
if((up0==1)&&(up1==0))
{
minute++;
if(minute>59)
minute=0;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
minute--;
if(minute==-1)
minute=59;
}
break;
}

case 3:
{
up0=up1;up1=up;a=1;
if((up0==1)&&(up1==0))
{
second++;
if(second>59)
second++;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
second=0;
}
break;
}
}
}

void main()
{
I2C_Start();
I2C_Write(0xD1);
I2C_Write(0x07);
I2C_Write(0x10);
I2C_Stop();
while(1)
{
ktphim();
readds();
quetled();

}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top