#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 used one button to move the cursor, another to the increment counter. I have displayed RTC in LCD using:
at bottom of the code, I have mentioned.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
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?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.
#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
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 :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.
I can't see why posting snippet by snippet should be more easy than posting the whole code.At once, It will be quite difficult what you are expecting because I am in the learning phase.
SEC = _55_RTC_COUNTER_SEC;
MIN = _59_RTC_COUNTER_MIN;
Me, too.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.
Yes, be sure of this.no offense intended,
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!
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.
I think this group only provide help for experienced people, thanks all for the suggestion.
This exactly is not true. You simply don't read our posts.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?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?