Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Increment the counter of RTC in the LCD

Status
Not open for further replies.

jack1998

Junior Member level 2
Junior Member level 2
Joined
Oct 17, 2021
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
136
I have used an 8085 microcontroller connected with 16*2 LCD to display the Real-time clock. Till now the time and date are displayed correctly on the LCD and now I want to customize that time and store it in that register using buttons. I have used one button to move the cursor, another to the increment counter. I have displayed RTC in LCD using:
Code:
#include <stdint.h>
unsigned char   button1 = 0;    //increment_button
unsigned char   button2 = 0;    //cursor_button
int first = 1;                                          
int second = 7;
void rtc_display_current_time(void);
static void convert_BCD_to_2chars(uint8_t bcd, uint8_t * const str);
void switich_increment(void);
int set_cursor_position (uint_fast8_t row, uint_fast8_t col);
void LCD_send_string(uint8_t * const str, lcm_position_t pos);

typedef enum {
    LCM_POSITION_TOP    = 0x00U,     /* The left at the top line */
    LCM_POSITION_BOTTOM = 0x40U,     /* The left at the bottom line */
} lcd_position_t;

typedef struct
{
    uint8_t sec;
    uint8_t min;
    uint8_t hour;
    uint8_t day;
    uint8_t week;
    uint8_t month;
    uint8_t year;
} st_rtc_counter_value_t;

void main(void) {
  
    /* Hardware Initiate */ 
    hdwinit();     
    /* Panel Initiate */
    panel_init0();    
    /*LCD Initiate */
    lcd_init();
    rtc_init_current_time():

    while (1U)
      {
        rtc_display_current_time();
        switich_increment();
        cursor_move();
      }
}

void rtc_init_current_time(void) {     
    {
        SUBCUD = 0x00;    
        SEC   = R_RTC_INIT_SEC;
        MIN   = R_RTC_INIT_MIN;
        HOUR  = R_RTC_INIT_HOUR;
        WEEK  = R_RTC_INIT_WEEK;
        DAY   = R_RTC_INIT_DAY;
        MONTH = R_RTC_INIT_MONTH;
        YEAR  = R_RTC_INIT_YEAR;
    }
}

void rtc_display_current_time(void) {
      uint8_t string_time[13+1];               /* A string area for the time to display. */
      st_rtc_counter_value_t read_val;         /* Counter values read from RTC registers */
  
        /* Show "YY/MM/DD(DOW)" on the top of LCD. */
    convert_BCD_to_2chars(read_val.year, &string_time[0]);
    string_time[2] = '/';
    convert_BCD_to_2chars(read_val.month, &string_time[3]);
    string_time[5] = '/';
    convert_BCD_to_2chars(read_val.day, &string_time[6]);
    string_time[8] = '(';
    convert_week_to_3chars(read_val.week, &string_time[9]);
    string_time[12] = ')';
    string_time[13] = '\0';
    LCD_send_string(string_time, LCD_POSITION_TOP);

    /* Show "hh:mm:ss" on the bottom of LCD. */
    convert_BCD_to_2chars(read_val.hour, &string_time[0]);
    string_time[2] = ':';
    convert_BCD_to_2chars(read_val.min, &string_time[3]);
    string_time[5] = ':';
    convert_BCD_to_2chars(read_val.sec, &string_time[6]);
    string_time[8] = '\0';
    LCD_send_string(string_time, LCD_POSITION_BOTTOM);
    
    set_cursor_position (first,second);                       
}

void LCD_send_string(uint8_t * const str, lcd_position_t pos) {
    int i;
    uint8_t *p;           
    for (i = 0, p = str; *p != '\0'; i++, p++)
    {     
       lcd_dout(*p);
    }
}

static void convert_BCD_to_2chars(uint8_t bcd, uint8_t * const str) {
    if (NULL == str)
    {
        return;
    }  
    *(str+0) = '0' + ((bcd>>4)&0xFU);
    *(str+1) = '0' + (bcd & 0xFU);
}

void switich_increment(void) {    
     if (button == 1 ) {               
        if (second == 2) {                     //setting cursor on the LCD to 2th position of 2nd line
            string_time[0]++;                  //incrementing the value of hour
            if(string_time[0] > 12) string_time[0] = 1;
        }
        if (second == 5) {            
            string_time[3]++;                     //incrementing the value of minute
            if(string_time[3] > 31) string_time[3] = 1 ;
        }
     set_cursor_position (1, second);              
     button = 0;
 }
}

int set_cursor_position (uint_fast8_t row, uint_fast8_t col) {                                                 
    if (row) {
        col |= 0xC0;                          
    }
    col |= 0x80;
    lcd_cout (col);   
    return 0;
}

I have read the RTC register value and stored it in the array and when I try to increment using array index it is not incrementing. Though, I have tried displaying numbers and tried incrementing it is working but when I display the RTC value reading the RTC register it doesn't get incremented. How can I increment?
 

Hello!

I have used one button to move the cursor, another to the increment counter. I have displayed RTC in LCD using:

Great! And?
I mean: if you don't say what goes wrong, nobody can reply. Or you just wanted to report that it works?
In this case, it might be good to say it.

Dora
 

Hello!



Great! And?
I mean: if you don't say what goes wrong, nobody can reply. Or you just wanted to report that it works?
In this case, it might be good to say it.

Dora
at bottom of the code, I have mentioned.
 

Hello!

There are still myriads of problems in your code, it looks like you ignore what has been said earlier.
First of all, you don't display the full code. Anyway I don't work on 8085, so I will not try to load the code
but if somebody wants to give it a try, it's not possible.
But for instance, when you write SEC = R_RTC_INIT_SEC; the variable SEC and the variable or constant
R_RTC_INIT_SEC are not defined and neither declared.

Beside this, at one place you increment something, but you display something else (the structure),
so it will definitely not work. If you want to write a message to somebody, the best is to transmit him
the sheet on which you have written, not another one. Other than the fact that incrementing the
characters of a string is odd, that will never work.

Dora.
 

Hello!

There are still myriads of problems in your code, it looks like you ignore what has been said earlier.
First of all, you don't display the full code. Anyway I don't work on 8085, so I will not try to load the code
but if somebody wants to give it a try, it's not possible.
But for instance, when you write SEC = R_RTC_INIT_SEC; the variable SEC and the variable or constant
R_RTC_INIT_SEC are not defined and neither declared.

Beside this, at one place you increment something, but you display something else (the structure),
so it will definitely not work. If you want to write a message to somebody, the best is to transmit him
the sheet on which you have written, not another one. Other than the fact that incrementing the
characters of a string is odd, that will never work.

Dora.
all those variables are declared in the header file so I do not mention them here. I don't get this line" one place you increment something, but you display something else (the structure),". How can I make it incremental, any suggestion?
 

Hi,

what about doing first things first?
Drawing a flow chart?

It´s not only for us, it´s mainly for yourself.
In my eyes it´s more important for unexperienced programmers.

Klaus
 

I think the suggestion is that working with real numbers then converting them to displayable characters is far easier than doing math in ASCII characters. We really need to see the header contents to be sure.

Brian.
 

header file as:
Code:
#ifndef _RTC_H
#define _RTC_H
#define _55_RTC_COUNTER_SEC                  (0x55U)
#define _59_RTC_COUNTER_MIN                  (0x59U)
#define _15_RTC_COUNTER_HOUR                 (0x15U)
#define _05_RTC_COUNTER_WEEK                 (0x05U)
#define _01_RTC_COUNTER_DAY                  (0x01U)
#define _01_RTC_COUNTER_MONTH                (0x01U)
#define _21_RTC_COUNTER_YEAR                 (0x21U)

typedef struct
{
    uint8_t sec;
    uint8_t min;
    uint8_t hour;
    uint8_t day;
    uint8_t week;
    uint8_t month;
    uint8_t year;
} st_rtc_counter_value_t;
#endif
 
Last edited:

Hello!

It looks like you will never learn!!!
Or at least you will never reply to what we ask you to do. It's really a pain to have to ask
repeatedly for information. I have asked what SEC is, you don't reply. As I told you a few
times already, if somebody wants to spend time debugging what you wrote, why not giving
him the WHOLE code, all the .c, .h files involved in your code? That kind of code is
probably not defense classified, is it?

SEC = R_RTC_INIT_SEC;

Your h file does not declare the variable SEC, and neither R_RTC_INIT_SEC.
Am I supposed to conclude that R_RTC_INIT_SEC is the same as _55_RTC_COUNTER_SEC?
Some consistency wouldn't hurt.

Beside this, you declare a structure twice (once in the .h, once in the .c), but you never initialize it.
The time structure does not appear in the initialization function.
And in your display current time, you declare a time string, you fill it with the structure which
contains basically at best the original values, and at worst garbage or zeroes because it's not
initialized anywhere.

In summary, your program does what you tell it to do: nothing.

Dora.
 

Hello!

It looks like you will never learn!!!
Or at least you will never reply to what we ask you to do. It's really a pain to have to ask
repeatedly for information. I have asked what SEC is, you don't reply. As I told you a few
times already, if somebody wants to spend time debugging what you wrote, why not giving
him the WHOLE code, all the .c, .h files involved in your code? That kind of code is
probably not defense classified, is it?

SEC = R_RTC_INIT_SEC;

Your h file does not declare the variable SEC, and neither R_RTC_INIT_SEC.
Am I supposed to conclude that R_RTC_INIT_SEC is the same as _55_RTC_COUNTER_SEC?
Some consistency wouldn't hurt.

Beside this, you declare a structure twice (once in the .h, once in the .c), but you never initialize it.
The time structure does not appear in the initialization function.
And in your display current time, you declare a time string, you fill it with the structure which
contains basically at best the original values, and at worst garbage or zeroes because it's not
initialized anywhere.

In summary, your program does what you tell it to do: nothing.

Dora.
At once, It will be quite difficult what you are expecting because I am in the learning phase. As I have already mentioned I have displayed that on the LCD which means I have declared it another c file. I have more than 60 c and h.files how can I post here? I only want to know as I have displayed using void rtc_display_current_time(void) function how can that displayed value be incremented? this is the initialization :

SEC = _55_RTC_COUNTER_SEC;
MIN = _59_RTC_COUNTER_MIN;
HOUR = _15_RTC_COUNTER_HOUR;
WEEK = _05_RTC_COUNTER_WEEK;
DAY = _01_RTC_COUNTER_DAY;
MONTH = _01_RTC_COUNTER_MONTH;
YEAR = _21_RTC_COUNTER_YEAR;
 

Hi
At once, It will be quite difficult what you are expecting because I am in the learning phase.
I can't see why posting snippet by snippet should be more easy than posting the whole code.
Half of our post in all your threads are asking for complete informations.
We really try to help, it's only you, who makes it difficult, lengthy and demotivating.

Do you think we professionals have all our knowledge from birth?
No. We all were at the same stage as you are now.
We all had to learn it. Step by step. We all had to draw sketches ... and still do!
We all still have to draw schematics, read datasheets, read books, do internet search.

For sure we don't draw the all the sketches for the simple tasks.
We focus on this what is difficult for us. We draw the difficult things.
When we recommend you to draw a sketch, then this is because we'd do the same when we were on your place.
It's nothing special, not for keeping you busy.... it's to help you now and in the future.

For sure you are free to go your own way. But don't be surprised when one by one refuses to go your way, your difficult way.

Klaus
 

Hello!

Fully agree with what Klaus said. Beside this, we are all busy on real work
(at least I suppose other here are busy) and we don't necessarily remember
what you wrote last time. Maybe your LCD works, maybe not.

SEC = _55_RTC_COUNTER_SEC;
MIN = _59_RTC_COUNTER_MIN;

Typical situation reflecting how difficult it is to help you: how do you want us
to guess that _55_RTC_COUNTER_SEC is the same as what you named with another
label last time? Did you change the naming, or does the other constant still
exist somewhere in your 60 C files?
Beside this, you don't fully reply to the question: WHERE IS "SEC" DECLARED?
Is it a char? uint8? Something else? I would guess it's an uint8 but I don't see
it in the code.

You have 60 C files? Judging by what you are asking, that might be part of your
problem. If you can't handle a plain RTC read program, no offense intended, but
it might be too early to handle a program of that complexity.
You can eat one cow, but one steak at a time. In the present case, you might
consider writing a separate program (I mean a full and independent program) that
handles the RTC in standalone, but does only that. It looks like that's what you are
doing anyway because your main() does only RTC init, read and display. It does it
wrongly, but that's the only thing it seems to do. So before coming here and asking
us to do your job (or homework), write a full program. You don't even need a .h file
for that complexity. I would say you can do it with 200 ~ 300 lines, all included,
possibly with alarm. Compile it at your place and don't send it before it works.
At least before the LCD works, and then you will ask why it doesn't increment.
By the way, there is a very good tool called a debugger, which is likely to answer
most of your questions.

That will be my last reply on this case, because I'm fed up having to pull any
bit of information and you don't look very proactive. If you manage to put a small
program in the proper shape, I might consider having a look at it.

Dora.
 

Hello!

Fully agree with what Klaus said. Beside this, we are all busy on real work
(at least I suppose other here are busy) and we don't necessarily remember
what you wrote last time. Maybe your LCD works, maybe not.



Typical situation reflecting how difficult it is to help you: how do you want us
to guess that _55_RTC_COUNTER_SEC is the same as what you named with another
label last time? Did you change the naming, or does the other constant still
exist somewhere in your 60 C files?
Beside this, you don't fully reply to the question: WHERE IS "SEC" DECLARED?
Is it a char? uint8? Something else? I would guess it's an uint8 but I don't see
it in the code.

You have 60 C files? Judging by what you are asking, that might be part of your
problem. If you can't handle a plain RTC read program, no offense intended, but
it might be too early to handle a program of that complexity.
You can eat one cow, but one steak at a time. In the present case, you might
consider writing a separate program (I mean a full and independent program) that
handles the RTC in standalone, but does only that. It looks like that's what you are
doing anyway because your main() does only RTC init, read and display. It does it
wrongly, but that's the only thing it seems to do. So before coming here and asking
us to do your job (or homework), write a full program. You don't even need a .h file
for that complexity. I would say you can do it with 200 ~ 300 lines, all included,
possibly with alarm. Compile it at your place and don't send it before it works.
At least before the LCD works, and then you will ask why it doesn't increment.
By the way, there is a very good tool called a debugger, which is likely to answer
most of your questions.

That will be my last reply on this case, because I'm fed up having to pull any
bit of information and you don't look very proactive. If you manage to put a small
program in the proper shape, I might consider having a look at it.

Dora.
you all expect the question as the experienced person asking the question. why do not you be at the side of beginner and think like that? and I am not telling you to write all program and by the way, it's not the homework it is the self project I am working with...and I think this group only provide help for experienced people, thanks all for the suggestion.
 

Hello!

What I keep telling you is that if you want help, you should _at_least_ put what you have made in a
self-contained shape. In this case I would expect a 1-file code that fully compiles at your place,
so that it would also compile if somebody has time to try.
From there, the people who are used to 8085 can load it and compile it at once without having to first
debug the obviously erroneous parts I mentioned.

You change your variable names, sometimes you don't even declare them, it's really hard to help,
and please remember that most of us are busy and don't _have_ to help you. It's always easier to put the
responsibility to somebody else. What I'm asking you is simple and shouldn't take you a day to do it:
write a 1-page program that replicates the problem.

By the way, here is a hint: it also happens to me to have something tricky that doesn't work. In this case,
I try to isolate what doesn't work, because I know that other people do not want to dig is dozens of files.
And it happens frequently that by trying to explain the problem as clearly as I can, I happen to find the solution
myself. So, you know what you have to do, the ball is in your court!

I think this group only provide help for experienced people, thanks all for the suggestion.

I think we are helping quite adequately, especially people who make the effort of providing
further info.

At #4, I have asked you where the variable SEC is declared and what is it. Did you reply?
-> No!
I also told you that you are defining a structure, but you don't use it. Did you
take my remark into account, modify the code and post the modifications?
-> No!
Klaus asked you to draw a chart. Well, all users heres have their own methods, I usually
don't draw charts, but what about trying to draw one? Did you do it?
-> No!
At #9, I asked you what SEC = R_RTC_INIT_SEC; is, you replied with something else
without declaring SEC and telling mw if R_RTC_INIT_SEC and _55_RTC_COUNTER_SEC or if
it was just a constant renaming. Did you cooperate a little bit?
-> No!
At #12, I already asked you to isolate the "bug" by writing a one-file program.
Did you do it?
-> No!

So this time I guess it will be my last reply on this subject, but I would like to make you aware that
although you try to put the responsibility on us, you have quite a good share of it.

Dora
 

Hi
you all expect the question as the experienced person asking the question. why do not you be at the side of beginner and think like that?
This exactly is not true. You simply don't read our posts.
In post#11 - for example - I wrote, that we all know how you feel, because we all once were at your place.
We all have been through this. We all made the same mistakes.

Again, you show that you don't respect this ... that you don't want to cooperate.

It's useless for me to go on. It's a waste of time. You don't want to learn. You want to keep your mistakes.

I'm not angry, I'm not upset. I'm sorry that I was not able to help you ... not with technical informations, not with well meant words

Klaus
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top