Thread: I program DS1302 & AT89C51 C code but LCD display 85 : 85 : 85,what is wrong???

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    21

    I program DS1302 & AT89C51 C code but LCD display 85 : 85 : 85,what is wrong???

    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]

  2. #2
    Registered User
    Join Date
    Apr 2011
    Location
    Las Vegas
    Posts
    66
    Hi. Since I don't have your configuration, I can't test anything.

    Can you print anything to the LCD? For example, can you send the characters in "Hello" and have it display properly?

    Second, you state that your time display is showing "85:85:85" which is 8 characters, but you are sending 9 characters to the display in LCD_TimerDisp(). What is the 9th character?

    Kevin
    Last edited by kmess; 04-25-2011 at 03:34 AM.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    The code you posted looks fine. There is certainly nothing in there that would cause this strange behavior. Do you have the code for TimeToStr? Perhaps the error is in there somewhere. Also, with embedded questions, it often helps if you post your schematic. What LCD are you using? Perhaps you aren't configuring it correctly.

    As kmess suggested, try printing a simple string and see if that works correctly. If it does, then you can be fairly sure the problem lies in TimeToStr, or the DS1302_SetTime or DS1302_GetTime functions, but those are less likely since they look like system libraries.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    From experience LCD_init needs a delay after it in some cases longer than the specs says to wait.
    Note: This does not seem to be your problem since your display displays something instead of the normal nothing that happened to me when I failed to wait long enough.
    I think I added 2mS to 4 mS delay in the init code.

    Note: I am guessing you have a 8-bit LCD_DATA (instead of the 4 bit) based on your init code; if not, you init code needs to be changed.

    Tim S.
    Last edited by stahta01; 04-25-2011 at 10:23 AM.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    21

    Thank for replying!!

    To : kmess
    Thank you for replying

    Well, the orignal code can show words on the lcd screen,some pics here.
    Cause after modify it i face the 85:85:85 error.
    I have change the for(alphabet=0; alphabet<9; alphabet++) to
    for(alphabet=0; alphabet<8; alphabet++) and it still display the same problem.


    To : anduril462
    Thank you for replying

    Well, i don't think i have the TimeToStr code. I not very sure about it. Sorry, my programming is very weak. Here pic of the schematic.
    The Lcd im using is call " PC0802A A POWERTIP". ((It have 7x2 pins))
    Hmm, what you mean by printing simple string??

    To : stahta01
    Thank you for replying

    Ohh,you mean i might have to add delay to my LCD_init??
    okay, i will go check whether it is a 8 bit or 4 bit LCD.
    Can you teach me how to change my init code??
    I need help,quite weak in programming, but i willing to keep trying.


    Thanks again
    Attached Images Attached Images I program  DS1302 &amp; AT89C51 C code but LCD display 85 : 85 : 85,what is wrong???-error-jpg I program  DS1302 &amp; AT89C51 C code but LCD display 85 : 85 : 85,what is wrong???-sch-jpg I program  DS1302 &amp; AT89C51 C code but LCD display 85 : 85 : 85,what is wrong???-ori-jpg 

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    21
    Well, i have remove the date from the code, so now i can from the LCD can only see " 85:85:85". Don't have the 85-85-85 for date anymore.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Your schematic is hard to read. What frequency is your processor running at? Your delay function is operating in clock cycles, not milliseconds. Depending on the frequency, delay(500) might be too short, as Tim suggested.

    You need to isolate the problem. See if it's TimeToStr converts it incorrectly, or if it's your LCD routines. Try wiring another port to a sequence of LEDs, so bits 0 to 7 of the output port represent bits 0 to 7 of each character in CurrentTime.TimeString. You should be able to do something like PORT3 = CurrentTime.TimeString[0] to output to the LEDs. This will give you the binary value of the character at index 0, 1, whatever. You can translate that into hex and look it up in an ASCII chart. If you see the ASCII characters '8' and '5' throughout, you can be pretty sure the problem is with TimeToStr. If the string data is good, you're not interfacing to the LCD correctly. It's crude, but effective.

    Also, you need to turn up compiler warnings and make sure your code compiles without any warnings. Based on the name, I would expect TimeToStr to take a char *, not a struct with a char * element. Perhaps you should be calling TimeToStr(CurrentTime.TimeString). Just a guess.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Actually, the delay function counts in an unknown multiple of clock cycles, in the best case. The compiler can recognize that it doesn't do anything, and just take it out, so your function always returns immediately.

    If you really want to do this, you should at least declare x as volatile, though you really should be using either inline assembly, library functions, or one of the timers for the delay.

    If you can write any character at all, your LCD schematics and routines are probably fine. Just check with an oscilloscope that all the timing specifications are met.

  9. #9
    Registered User
    Join Date
    Apr 2011
    Posts
    21

    Thank for replying!!

    To anduril462 :

    I have try to change the TimeToStr(&CurrentTime); to
    TimeToStr(CurrentTime.TimeString);
    The LCD shows display " ll ll ll ll ll ll ll ll "
    It have warning that say : pointer to different objects

    What you mean the the processor,you mean my microprocessor or??
    The datasheet say that High-speed Architecture
    – In Standard Mode:
    • 40 MHz (Vcc 2.7V to 5.5V, both Internal and external code execution)
    • 60 MHz (Vcc 4.5V to 5.5V and Internal Code execution only)
    – In X2 mode (6 Clocks/machine cycle)
    • 20 MHz (Vcc 2.7V to 5.5V, both Internal and external code execution)
    • 30 MHz (Vcc 4.5V to 5.5V and Internal Code execution only)
    So,how i determine which??

    Srry,i think i cant add extra wiring or components on the the board it, because the board is not mine.

    Is there any programming code that i can change or add on??

    Im also confuse about the what you mention about the timestring and those convertion.

    I can try posting a clearly verious of the schmetic.




    To cyberfish :

    Hmm,i do not understand what you mean be declare x as volatile??
    can you show me an example or teach me where i can change in my code?
    Last edited by w31q1an9; 04-26-2011 at 02:57 AM.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    void delay(unsigned int y)
    {
    	volatile unsigned int x;
    	for(x=0; x<y; x++);
    }
    Use an oscilloscope to make sure the delays are long enough.

  11. #11
    Registered User
    Join Date
    Apr 2011
    Posts
    21
    To cyberfish :

    I have add ''volatile" to the code,but the problem that show a constant 85:85:85 is still there,it remain the same.
    What you mean by make sure the delays are long enough??

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    How long do you think delay(500); will be?

  13. #13
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    The LCD datasheet will tell you long long the enable pulse has to be, how long the data has to be ready before enable goes high (setup time), and how long the data has to stay constant for after enable goes high (hold time). And also how long each instruction will take. Check that they are followed.

  14. #14
    Registered User
    Join Date
    Apr 2011
    Posts
    21
    For the delay(500) , you mean the delay(500) at the void main section or the void strobe??
    I have change and test by changing the value from 500 to 10000. The problem still exist,wad change is that the lcd display the 85:85:85 slower after i launch.
    Okay i will go look at the lcd datasheet for what you say.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe display in Code::Blocks
    By Jarobins in forum Game Programming
    Replies: 1
    Last Post: 03-04-2010, 03:15 AM
  2. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  3. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  4. Need a Code to display .jpg files
    By arvindkr in forum C++ Programming
    Replies: 4
    Last Post: 08-31-2002, 05:43 PM
  5. floating point numbers display something wrong i think
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-27-2002, 03:18 AM