I have program a (RTC) DS1302 & (8051) At89c51 C code using keil and compile a hex file, den i load the hex file using flip.
Everything was fine,just that the lCD show 85 : 85 : 85 for the time and the time did not run at all. What can be the problem??
Correct me if there is something that im wrong or i need to change or add on to. Thx!
Below is the code--------------------------------------------------------------
[tag]
Code:
#include <at89c51xd2.h>
#include <string.h>
#include <ds1302.h>
/*******************************************/
/* define the button name and the lcd pin */
/*******************************************/
#define E P1_2 //LCD E
#define RW P1_1 //LCD RW
#define RS P1_0 //LCD RS
#define LCD_DATA P2 //LCD Data port
SYSTEMTIME CurrentTime;
/************************************/
/* Function that going to use */
/************************************/
void delay(unsigned int); //software delay
void strobe(void); //write in data
void LCD_init(void); //LCD initialisation
void LCD_print(unsigned char); //print on LCD
void LCD_command(unsigned char); //to set instruction to cursor
void LCD_TimerDisp(); //Show time
/*****************/
/* Main function */
/*****************/
void main(void)
{
unsigned char i;
for(i=0; i<20; i++)
delay(500);
LCD_init();
DS1302_SetTime(DS1302_SECOND, 45);
DS1302_SetTime(DS1302_MINUTE, 59);
DS1302_SetTime(DS1302_HOUR, 23);
LCD_TimerDisp();
}
/************/
/* Function */
/************/
void delay(unsigned int y)
{
unsigned int x;
for(x=0; x<y; x++);
}
void strobe() //write in data
{
E = 1;
delay(500);
E = 0;
delay(500);
}
void LCD_init() //LCD initialisation
{
RS = 0;
RW = 0;
LCD_DATA = 0x38;
strobe();
LCD_DATA = 0x0c;
strobe();
LCD_DATA = 0x01;
strobe();
LCD_DATA = 0x06;
strobe();
}
void LCD_print(unsigned char alpha) //print on LCD
{
RS = 1; //data type
RW = 0; //write enable
LCD_DATA = alpha; //LCD D0 to D7
strobe();
}
void LCD_command(unsigned char beta) //to set instruction to cursor
{
RS = 0; //data type
RW = 0; //write enable
LCD_DATA = beta;
strobe();
}
void LCD_TimerDisp()
{
unsigned char alphabet;
do
{
DS1302_GetTime(&CurrentTime);
TimeToStr(&CurrentTime);
LCD_command(0x06);
LCD_command(0xc0);
for(alphabet=0; alphabet<9; alphabet++)
{
LCD_print(CurrentTime.TimeString[alphabet]);
}
delay(300);
}while(1);
}
[/tag]