473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

year information not displayed properly

I have set my year value in the register on my RTC (DS1302) to be 2008
using this code:

// This function sets the year on the RTC
// Note: The year takes in only the last two digits of the year only
// and valid for only 2000 to 2099
void set_year(unsigned int year)
{
unsigned int year_temp;
unsigned char year_write = 0;
unsigned char year_tens;
unsigned char year_ones;

// Obtain the last two digits of the year
year_temp = year - 2000;

// Obtain the ones of the year and write it to year_write
year_ones = year_temp % 10;
year_write = year_write | year_ones;

// Obtain the tens of the year and write it to year_write
year_tens = year_temp / 10;
year_write = year_write | (year_tens << 4);

// Write the byte year_write to the register
writebyte(WRITEYEAR, year_write);
}

However, the chip can't store all four digits. So I subtract 2000 to
store the last two digits of the year, and add 2000 back to the value
retrieved from the real time clock register carrying the information
about the year.

The following function accesses the year information from the
register:

// This function accesses the register carrying the year and returns
// it to the main function in the format of "20xx", with the "xx"
determined
// by the contents of the register
unsigned int access_year(void)
{
unsigned char register_data;
unsigned int return_year = 0;
unsigned char temp;

// retrieve the byte in the register
register_data = readbyte(READYEAR);

// process the first digit of the year
temp = register_data & 0x0f;
return_year += temp;

// process the second digit of the year
temp = register_data & 0xf0;
return_year += (temp >4)*10;

// add 2000 to return_year to make it 20xx
return_year += 2000;

// return return_year to complete function call
return return_year;
}

However, I'm getting a value of 216 displayed on the LCD. readbyte()
and writebyte() functions have been tested to work properly. It would
be much appreciated to get some feedback, as I have made sure that I
have anded and or'ed the variables properly. Could there be a problem
with the conversion between unsigned int and unsigned char? For a
specific LCD writing function, it uses type int for the data rather
than unsigned int. Could that be a source of problem as well?
Jan 9 '08 #1
4 1604
However, I'm getting a value of 216 displayed on the LCD. readbyte()
and writebyte() functions have been tested to work properly. It would
be much appreciated to get some feedback, as I have made sure that I
have anded and or'ed the variables properly. Could there be a problem
with the conversion between unsigned int and unsigned char? For a
specific LCD writing function, it uses type int for the data rather
than unsigned int. Could that be a source of problem as well?
It must be your LCD function. 2008 as an integer has its least significant
byte of 0xD8 which is 216 in decimal, which is what you are seeing. Your
problem must be the LCD writing function is somewhere using char 8bit
datatypes and not multibyte integers.

And everyone else will bitch at you because you need to take this problem to
a group about programming for whatever cpu/mcu/lcd you are using.
Jan 9 '08 #2
On Jan 9, 1:15 am, "MisterE" <vo...@sometwher.worldwrote:
However, I'm getting a value of 216 displayed on the LCD. readbyte()
and writebyte() functions have been tested to work properly. It would
be much appreciated to get some feedback, as I have made sure that I
have anded and or'ed the variables properly. Could there be a problem
with the conversion between unsigned int and unsigned char? For a
specific LCD writing function, it uses type int for the data rather
than unsigned int. Could that be a source of problem as well?

It must be your LCD function. 2008 as an integer has its least significant
byte of 0xD8 which is 216 in decimal, which is what you are seeing. Your
problem must be the LCD writing function is somewhere using char 8bit
datatypes and not multibyte integers.

And everyone else will bitch at you because you need to take this problem to
a group about programming for whatever cpu/mcu/lcd you are using.
I personally found this to be a programming problem. Below shows my
LCD display code that deals with data:

void LCD4_OUT_data(int number, char position)
{
const int size = 10;
char text_array[size];
int n;

n = sprintf(text_array, "%u", number);
if (n < 0 || n >= size){
return;
}

LCD4_CMD(position);
LCD4_OUT(text_array);
LCD4_OUT(" ");

}

It doesn't appear that the integer got converted to unsigned char
anywhere. It got converted to string, that's for sure.
Jan 10 '08 #3
ssylee wrote:
....
void LCD4_OUT_data(int number, char position)
....
n = sprintf(text_array, "%u", number);
Why are you using %u rather than %d?
Jan 10 '08 #4
On 10 Jan., 08:12, ssylee <staniga...@gmail.comwrote:
On Jan 9, 1:15 am, "MisterE" <vo...@sometwher.worldwrote:
However, I'm getting a value of 216 displayed on the LCD...
It must be your LCD function. 2008 as an integer has its least significant
byte of 0xD8 which is 216 in decimal, which is what you are seeing. Your
problem must be the LCD writing function is somewhere using char 8bit
datatypes and not multibyte integers.
...

I personally found this to be a programming problem. Below shows my
LCD display code that deals with data:

...

It doesn't appear that the integer got converted to unsigned char
anywhere. It got converted to string, that's for sure.
Then the error must be after the return from access_year() and before
the call to LCD4_OUT_data().
Jan 11 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MT | last post by:
hi all, I have a view that has data from this year as well as previous years. the select statment looks something like this: create view as select year, costs_mon1, costs_mon2, costs_mon3...
0
by: Krzysztof Fink-Finowicki via .NET 247 | last post by:
I have problem with TEXTAREA HTML tags in my Web application (MSIE 6.0). User fills-in content of TEXTAREA on HTML dialog window. After accepting, content of TEXTAREA from dialog window is...
2
by: Claudia Fong | last post by:
Hi, I need to add one to the current year so the year would be 2006. I'm using the code below and I put this code before the InitializeComponent() next_year and current_year are declare as...
0
by: Panayotis Kouvarakis | last post by:
I have noticed that CompareValidator and RangeValidator don't work properly with 2-digit year dates when using client script validation. Specifically the problem lies in the way the string is...
11
by: Kevin | last post by:
I have a problem I'm trying to figure out how to resolve in Access. I have a volunteer database for a project which occurs each year. Currently I have to go in and wipe out the data each year to...
6
by: Burghew | last post by:
Hello, I generate invoices for my customers evry month. I want to keep a form which will allow the user to select the Month and Year through a combo and thus generate reports based on the month...
4
by: koonda | last post by:
Hi all, I am working on a project. Everything is working fine except the date formating. I have five listboxes and a dropdownlist box controls. The 5 listboxes I have populated from the underlying...
4
by: farhanm84 | last post by:
I have a requirement to display the link in colum format in IE browser. The link text is associated with an image (double arrow). Since the text of the link is large enough to set in one of the...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.