jack1998
Junior Member level 2
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:
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?
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?