Microcontroller › 8051 › I have program a DS1302 & AT89C51 C code but the LCD just display 85 : 85 : 85 for the time & it do not run, wad went wrong???
- This topic has 0 replies, 1 voice, and was last updated 13 years, 11 months ago by
Ang wei qiang.
-
AuthorPosts
-
April 6, 2011 at 8:43 am #851
Ang wei qiang
ParticipantI have program a DS1302 & 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. Thx!Below is the 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();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);
}
-
AuthorPosts
- You must be logged in to reply to this topic.