While using the simulator, the values of i in the serial window are shifted by left 8 bits.
#include "stdlib.h" #include "stdio.h" #include "reg51.h" void main (void) { unsigned char i; SCON = 0x50; TMOD |= 0x20; TH1 = 221; TR1 = 1; TI = 1; for (i = 0; i < 8; i++) { printf("%x\n", i); } }
try this: printf("%bx\n", i);
To understand what's going on, see: http://www.keil.com/support/man/docs/c51/c51_printf.htm
Pay particular attention to the bullet-point Notes below the table of format specifiers...
So, to conclude:
1) You have hijacked a thread (actually at least two threads).
2) You like to SCREAM in threads.
3) You like to constantly repeat your questions.
4) You like to formulate your questions as requests.
5) You don't know what problem you want to solve - hence the incorrect query about printing BCD numbers.
6) This is a school assignment.
7) Your current bet is some rubbish code you have got from a friend.
8) You think uninitialized variables are the way to go, because the broken code looks like it produces sligthly better results then.
9) You refuces to sit down with a pen and paper and figure out what to do, and how to do it.
10) You think cheating in an acceptable way of passing school assignments.
Exactly what do you expect us to do about this mess? receive the full unabrigated school assignment and write a fully working and perfectly documented program to solve the task for you? Would that make you a better student - or just a student that have cheated?
Note, that by helping you cheat on school assignments, that makes us cheaters too. If I just knew exactly what the task is, I could probably code and test the code within 5 minutes. Hence, if you participated on the lessons, you should be able to solve the problem (without Google) within an hour.
How about picking up the school books and for cnce spend some time reading them. Yes, I know that this will take a _huge_ amount of time. It is quite obvious that you will have to open the books at an very early page. Variables are treated very early. Uninitialized variables are definitely discussed very thoroughly!
This is a _trivial_ assignment, so do spend some time solving it yourself, instead of almost killing yourself trying to find the best way to cheat.
By the way - you do know that some teachers actually keeps track of Internet forums, to see which students are busying themselves with cheating? They don't have to read all posts on all forums in this world: The advantage of Google, is that they can google for people cheating...
I HAVE NOW GOT BETTER CODE WITH INITIALOIZED DATA AND IT IS NOW WORKING BETTER
IT WORKS WITH MOST NUMBERS 0 TO 99 BUT IT DOES NOT WORK WITH NUMBERS 100 to 255
THIS MUST WORK 100% TODAY AND PRINT BCD NUMBERS
WHAT IS WRONG?
int printbcd(int value) { printf("%x",binerytobcd(value)); } int binerytobcd(int binary) { int bcd; /* answer */ bcd = 0; /* initilase variable */ while (binary > 10) /* while binary is more than 10 */ { bcd = bcd + 16; /* change bcd */ binary = binary - 10; /* change binary */ } while (binary > 0) /* while binary is greater than 1 */ { bcd = bcd + 1; /* chainge bcd */ binary = binary - 1; /* change binary */ } return bcd; /* result */ }
You are still SHOUTING!
Do not write in ALL CAPITALS!
"WHAT IS WRONG?"
1) The code is lousy!
2) You still haven't learned what BCD numbers are!
Try one more time to google for BCD numbers. How can you know when a solution works or not, if you don't even know what the expected output result is?
By the way: Please post your address, and you'll get a visitor that will rip the caps-lock key from your keyboard - and every keyboard within a 100m radius... Upper-case text represents shouting, as already told a number of times in this thread. Are you dense?
I LOOK ON GOOGLE FOR BCD AGAIN AND FOUND DATA ON PACKET BINARY CODED DECIMAL
I DO NOT UNDERSTAND HOW TO PACKET DATA INTO BYTE
ANYONE KNOW?
THE CODE CAM FROM A FREIND WHO SAYS IT WORKS BUT I TRY WITH (IE) 120 BUT IT DOES NOT PRINT 120
I NEED TO GET CODE WORKING
PLEASE WHAT IS WRONG?
Which part of "do not write in ALL-CAPITALS" do you not understand?
I mean, "do not write in ALL-UPPERCASE"
What would be the point in telling you? You clearly aren't listening to what you're being told!
How many times does "Don't Shout" have to be said to you before you will stop shouting??
I will give you some tips if you will stop shouting.
I HAVE NO TIME
IF YOU KNOW PLEASE TELL ME ANSWER
I wonder why the text "what is bcd" is such a good search term to google on. Might it be because it tells exactly what BCD numbers are, and how they are stored, and how to convert back from BCD to either a binary number or a decimal number?
Did you get your code from a friend in the same class?
Are you expecting to send in the same solution?
Do you think your teacher likes to see two identical solutions?
Is your friend spending his time on another forum?
Doesn't it feel good after having really spent some time solving a problem?
It takes no longer to type politely than to shout.
You want this for free - the least you can do is to ask nicely!
If you won't do that, I won't reply.
"Is your friend spending his time on another forum?"
They're a tag-team. The friend is the one doing the coding since it requires the ability to use lowercase.
I HAVE GOT 2 HOURS LEFT TO DO THIS
DOES ANYONE KNOW THE ANSWER?
I TRY GOOGLE AND MICROSOFT BUT CANNOT FIND ANY CODE THAT WORKS
He does not know what BCD is, he insist on shouting, he wants to get a diploma.
I hope anyone trying to 'help' him will end up sitting at the desk next to his when he 'get' his diploma and get hired.
I, am perfectly willing, as we all should be, to help anyone trying to get through school, but 'helping' someone get thought school without having even an inkling of understanding of the subject is very counterproductive.
I, once, was given (by a HR that did not believe in engineers interviewing candidates) an assistant that as the first thing he did put up his freshly minted PhD diploma on his office wall. I gave him a piece of code to look at (saying this is the style we use here) and his first question (1/2 hour later) was "does db mean 'double byte'". The 'ad' for the job specified, among other things, "fluent in '51 assembler" and HR assured me that he was (they read what his diploma supposedly ment).
Erik
Erik,
I know this is nothing to do with the screamers problem but as I read your text it reminded me of a situation that used to exist at our place.
To be a member of development, you had to hold a degree - The subject of that degree didn't matter - Just that you had a degree.
So ... We ended up with one guy who had a degree in journalism writing 8051 assembler.
The text in the files may have been succinct and well formed - But the code was not!
I SEARCH FOR PACKED BCD BUT GOT NO WORKING CODE
HELP NOW PLEASE?
"HELP NOW PLEASE?"
Sorry - No can do!
You are not expected to find working code!
You are expected to find some very good explanations of what packed BCD is.
After spending 10-20 minutes reading about packed BCD (the explanations really are good, and I have already mentioned a good search string for Google), it should then be trivial to write your own code to do the exercise.
I know that the above suggestion isn't popular. It has the very bad side effect that you may actually learn something. I clearly understand that this can be traumatic for you.
Stop reading and repsonding to the joker-poster already. Some of you say how busy you are, yet have no problem posting something to make you *feel* smart about yourself.
Is this a forum about Keil, or your own personal circle jerk forum?
Close and lock the thread.
"the joker-poster" just might understand that to get a diploma you need to do some work and his friend may learn that to get a diploma your code needs to work.
While the likelyhood of sucn an event may be small, it is still worth the effort.
Is this a forum about Keil yes it is and part of what it requires to use Keil (study, work) has been discussed in detail above.
jerk forum? absolutely not, however, if someone seeking advice consider "you must do some work" as coming from a jerk, that is not the "jerk"s problem.
erik
Go look up circle jerk...
Check in other threads.
Reasonable questions are always answered with reasonable answers.
However, people comming with unreasonable requests - or as in this case ordering us to supply turn-key solutions to school work - will have to settle for answers about methodology.
No, I do not *feel* smart about myself, talking about encoding or decoding BCD numbers just as I'm not *feeling* smart about being able tie my shoe laces either.
I know that the net is full of trolls and intentionally irritating people. However, I have no good means to separate trolls from people actually wanting help. As long as a thread doesn't diverge into a constant series of invectives, I always try to suggest a suitable next step for solving a problem. If it's a troll, then the step isn't needed. If it's a fool, the step may be ignored. Now and then, the suggesition may be picked up and acted upton.
In the end, I don't care too much if a suggestion is acted upon or not. People who want advice will get it. People who want to ignore advice are free to ignore them. That is life.
The Circle Jerks are a hardcore punk band formed circa 1979 in Hermosa Beach, California.
I can not even imagine that you refer to the other definition.
Now, for something even more interesting, please provide a link to anywhere YOU have actually provided help to anyone in this forum. If you see no reason to provide help, you have no right to criticize the help given whether you like it or not. That you decide to hide behind the name of a clothing company i.e. make jerking anonymous really show how much a man you are.
Author Per Westermark
I like this guy.
then why do you call him a moron? to feel related to him?
Do you mean like how your mom and dad are related...?
related as in similar.Your question proves you are a moron. Get your head out of the gutter .... naah keep it there and stop throwing your trash here.
If you think this it the last time I reply to your insane babbles you are right.
PS To Per: I hope my post that this moron misunderstood, was clear enough that you, who have sense, could see that nothing was directed towards you.
View all questions in Keil forum