fibi
Newbie level 1
can anybody pls help me, with regards to the extracting of information from a DS1302 trickle-charge timekeeping chip. I will be needed to activate a programmable trickle charger. Also known as the backup battery.
In general, i need help in the extracting of informations from the DS1302 real time clock chip and also the enabling of the backup battery. EVERYTHING SHALL BE IN KEIL C PROGRAMMING. NOT ASSEMBLY CODE!!!
The following is my code, which is currently able to do the displaying and incrementing of the clock values. Pls help me as in where and how, i can add the additional coding to myn existing source code.
In general, i need help in the extracting of informations from the DS1302 real time clock chip and also the enabling of the backup battery. EVERYTHING SHALL BE IN KEIL C PROGRAMMING. NOT ASSEMBLY CODE!!!
The following is my code, which is currently able to do the displaying and incrementing of the clock values. Pls help me as in where and how, i can add the additional coding to myn existing source code.
Code:
#include <at89c51xd2.h>
#include <string.h>
#include <absacc.h>
#include <DS1302_Driver.h>
#define LCD_data P0
#define RS P1_0
#define RW P1_1
#define EN P1_2
unsigned char Lcd_Data[]= {'C','L','O','C','K',':'};
void Lcd_Initial(void);
void Lcd_Command(unsigned char Command);
void Lcd_Busy();
void delay(unsigned char time);
void Lcd_Write(unsigned char Data);
void T0Delay(void);
void Lcd_Clock_Display();
void LCD_Print();
void Timekeeper();
int i,d;
unsigned char ascii_sec1 = 0, ascii_sec2 = 0, ascii_min1 = 0, ascii_min2 = 0, ascii_hour1 = 0, ascii_hour2 = 0;
unsigned char sec = 0 , min = 0 , hour = 12 , count = 0;
void main (void)
{
Lcd_Initial();
Lcd_Command(0x01);
Lcd_Command(0x1c); //move right
Lcd_Command(0x1c); //move right
for(i=0;i<7;i++) //loop to display 12 characters
{
Lcd_Write(Lcd_Data[i]); //print data from unsigned char Lcd_Data
}
TMOD = 0x01;
TH0 = 0x97;
TL0 = 0xD6;
TF0 = 0;
TR0 = 1;
EA = 1;
ET0 = 1;
while(1)
{
Lcd_Clock_Display();
}
}
void Lcd_Initial(void)
{
Lcd_Command(0x38); // function set : 2-line display
Lcd_Command(0x0C); // display on , cursor off
Lcd_Command(0x01); // clear screen
}
void Lcd_Command(unsigned char Command)
{
Lcd_Busy();
EN = 0;
RS = 0;
RW = 0;
delay(5);
EN = 1;
LCD_data = Command;
delay(5);
EN = 0;
}
void Lcd_Busy()
{
unsigned char i,j;
for(i=0;i<40;i++) //A loop for delay
for(j=0;j<20;j++);
}
void delay(unsigned char time)
{
unsigned char x;
for(x=0;x<time;x++); //delay subroutine
}
void Lcd_Write(unsigned char Data)
{
Lcd_Busy();
EN = 0;
RS = 1;
RW = 0;
delay(5);
EN = 1;
LCD_data = Data;
delay(5);
EN = 0;
}
void Timekeeper() interrupt 2
{
TF0=0;
TH0 = 0x97;
TL0 = 0xD6;
count++;
if(count == 50)
{
count=0;
sec++;
if (sec == 60)
{
sec = 0;min++;
}
if (min == 60)
{
min = 0;hour++;
}
if (hour == 24)
{
sec = 0;
min = 0;
hour=0;
}
}
}
void Lcd_Clock_Display()
{
ascii_sec1 = (sec/10) | 0x30;
ascii_sec2 = (sec%10) | 0x30;
ascii_min1 = (min/10) | 0x30;
ascii_min2 = (min%10) | 0x30;
ascii_hour1 = (hour/10) | 0x30;
ascii_hour2 = (hour%10) | 0x30;
Lcd_Command(0xC0);
Lcd_Write(ascii_hour1);
Lcd_Write(ascii_hour2);
Lcd_Write(':');
Lcd_Write(ascii_min1);
Lcd_Write(ascii_min2);
Lcd_Write(':');
Lcd_Write(ascii_sec1);
Lcd_Write(ascii_sec2);
sec1 = (sec/10) | 0x30;
sec2 = (sec%10) | 0x30;
min1 = (min/10) | 0x30;
min2 = (min%10) | 0x30;
hour1 = (hour/10) | 0x30;
hour2 = (hour%10) | 0x30;
Lcd_Command(0xC0);
Lcd_Write(hour1);
Lcd_Write(hour2);
Lcd_Write(':');
Lcd_Write(min1);
Lcd_Write(min2);
Lcd_Write(':');
Lcd_Write(sec1);
Lcd_Write(sec2);
}