473,663 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(unsign ed 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(WRITE YEAR, 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(voi d)
{
unsigned char register_data;
unsigned int return_year = 0;
unsigned char temp;

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

// 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 1623
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...@sometwhe r.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(i nt number, char position)
{
const int size = 10;
char text_array[size];
int n;

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

LCD4_CMD(positi on);
LCD4_OUT(text_a rray);
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(i nt number, char position)
....
n = sprintf(text_ar ray, "%u", number);
Why are you using %u rather than %d?
Jan 10 '08 #4
On 10 Jan., 08:12, ssylee <staniga...@gma il.comwrote:
On Jan 9, 1:15 am, "MisterE" <vo...@sometwhe r.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
3062
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 costs_mon4,
0
2350
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 copiedto TEXTAREA on main HTML window: wndTxtArea.value = dlgTxtArea.value; Then user may take the text for editing in HTML dialog windowonce more. The problem arises when text to be copied is multiline. Firsttime it is displayed properly after...
2
18618
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 int. current_year = DateTime.Now.Year;
0
1213
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 converted into a date before being compared to the preset value(s). Normally (when using the default values: CutOffYear=2029 and Century=2000) a 2-digit year, YY, should be converted to 20YY if YY<=29 and 19YY if YY>29. This is what happens if the...
11
1555
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 start new. I want to somehow be able to incorporate the year's info into the database. For instance, keep 2005's information, and add 2006's. So next year I can pull up 2005 and say "oh yeah, so-and-so participated that year". Any ideas? ...
6
4835
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 selected. Also, please let me know how I can keep a copy of invoices which I generate for future reference. Awaiting eagerly for your replies -- 'With Thanks'
4
1217
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 database view and dropdownlist box is populated by the date in the same view. When I select any values from the listboxes the information is displayed in the Repeater Control. I also want to select the date including the 5 listboxes to display the...
4
3385
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 column width the text and the image are messed up. When I tried removing half of the link text then it is properly displayed. For example, from the link text "Give as much detail as possible" if I remove "as possible" the link text will become "Give...
27
2765
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: ================ module.h ================ #ifndef __MODULE_HDR_INCLUDED__
0
8436
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8858
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8771
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.