-1
\$\begingroup\$

Below are the codes I using to display dates and times and basically I used the function "write(hr1,hr0,min1,min0,sec1,sec0);" to display the time and "day_compute(day);" to display what the day for the input date. For simplicity, I just show the input send to LCD between these 2 functions. I want the time to display on the 1st line of the screen and day to display on the 2nd line of the screen, what command line should I add in between this 2 so it will separate the day to the 2nd line?Refered to the datasheet but still not able to understand how to do that.

enter image description here

     void LCD_set();

     void main()
    {                   
           TRISA=0x00;
           TRISD=0x00
        
     while(1)
    {                       
                initialize();               
                write(hr1,hr0,min1,min0,sec1,sec0);
                day_compute(day);           
    }

        
     void initialize()
    {        
          PORTD=0x00;
          LCD_set();
          PORTD=0x0C;
          LCD_set();
          PORTD=0x06;
          LCD_set();
          PORTD=0x80;
          LCD_set();   
    }
     
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can you reduce this to a minimal example of what you have tried? Show us code that attempts to write "A" on the first line and "B" on the second line, without all of the code that handles the date. \$\endgroup\$ Commented Jul 4, 2021 at 11:20
  • \$\begingroup\$ For the love of readability please fix your indention and formatting. Expecting others to read this messy code is plain rude. \$\endgroup\$
    – Lundin
    Commented Jul 6, 2021 at 10:02

2 Answers 2

2
\$\begingroup\$

Using these commands sets the configuration and positions the cursor.

 Rs    Cmd  Executes
 18     38  2 lines and 5×7 matrix
 16     80  Force cursor to beginning ( 1st line)
 17     C0  Force cursor to beginning ( 2nd line)
\$\endgroup\$
0
\$\begingroup\$

Based on the explanation given by Tony, I understood the command line and found my mistake already. My mistake is in the void initialize() command

originally I using void initialize()

 {

  PORTD=0x00;
  LCD_set();
  PORTD=0x0C;
  LCD_set();
  PORTD=0x06;
  LCD_set();
  PORTD=0x80;
  LCD_set();

  }

where 0x00 and 0x06 is not needed and after added in PORTD=0x38 to declare it as 2 lines and 5x7 matrix as the code below,

 void initialize()
{


PORTD=0x0C;
LCD_set();
PORTD=0x38;
LCD_set();
PORTD=0x80;
LCD_set();

}

and write PORTD=0xC0 in between the print time and date function i obtained my desired result.

        write(hr1,hr0,min1,min0,sec1,sec0);
        PORTD=0xC0;
        LCD_set();
        write1(date02,date01,month02,month01,year3,year2,year1,year0);

as below picture enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.