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); } }
You are still SHOUTING!
Do not write in ALL CAPITALS!
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 */ }
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 TRY TO INITILISE BCD BUT NOW I NEVER GET THE GOOD ANSWER SO I THINK THAT IS NOT THE PROBLEM"
OK then. Use uninitialized wherever the mood strikes you. The rest of us don't do that because it yields incorrect results, so we are in no position to be able to help you. I think you should be asking for help elsewhere; a place where using uninitialized variables is acceptable and gives correct results. That place is not here.
YOU WANT ME TO FAIL?
Yes, yes and yes again IF
.... the only way you can not fail is by someone providing you with answers to a thing as simple as this. Should someone be stupid enough to 'help' you get a diploma under false pretenses, I pity the poor employer that hires you based on a diploma you have receieved without even having a gist of the knowledge the diploma specifies that you have.
Erik
"WHAT ELSE CAN BE WRONG?"
The code in its entirety! Move on to the next candidate code.
By the way, you originally said you wanted to print a BCD value. To us, that means that the value is already in (packed) BCD and you want to print it as ASCII digits. Why do you even care about binary to BCD conversion?
100% BAD
I TRY TO INITILISE BCD BUT NOW I NEVER GET THE GOOD ANSWER SO I THINK THAT IS NOT THE PROBLEM
I GO BACK TO FIRST CODE AND SOMETIMES GET GOOD ANSWER WHICH IS BETTER
WHAT ELSE CAN BE WRONG?
"YOU SEE THE PROBLEM IN MY CODE?"
For starters, when (binery<2) is true, what is the purpose of incrementing uninitialized bcd?
The code is a ripe steaming pile of fecal matter. You should have recognized it as such, not asked about it here, and moved on to the next candidate routine for consideration.
PLEASE
YOU SEE THE PROBLEM IN MY CODE?
IT SOMETIMES GIVES A GOOD ANSWER SO I THINK THERE IS ONLY A LITTLE PROBLEM
WE NEED THE ANSWER 100% CORRECT AND QUIKCLY
"... WORKS BUT NOT CORRECTLEY"
How can something WORK and not be CORRECT?
"CHECK CODE AND SAY WHAT IS WRONG"
First, why do you and your friend think it is not correct? What have you observed?
THIS IS CODE MY FRIEND GAVE ME
HE SAID HE GOT IT FROM GOOGLE AND IT WORKS BUT NOT CORRECTLEY
int printbcd(int value) { printf("%x",binerytobcd(value)); } int binerytobcd(int binery) { int frpol; /* framing p?? */ int bcd; /* working sum */ for( frpol = 0 ; frpol < 7 ; frpol = frpol + 1) { if (binery<2) /* is binery a binery number*/ bcd = bcd + 1; /* change bcd to add it */ binery = binery - 2; /* do next number */ } return ( bcd % 255 ); /* get rid of last bit */ }
I TRY AND I DO NOT SEE CORRECT ANSWER
CHECK CODE AND SAY WHAT IS WRONG
What search strings did you try?
"WANT ANSER BCD PRINTING PLEASE NOW"
I jusr read the thraad (it is Monday morning here) and I see one word in all your posts which is "NOW"
so, In your opininion, everybody that has a paid job and occsionally visit this forum, should immediately drop what they are doing to earn their pay and for free take care of the fact that you have no idea of even the most basic concepts.
Ok, here is a suggestion
post whithout using capitals a short synopsis of what the BCD format is and how YOU propose to code the conversion so we know that you have, at least, done some work yourself and maybe, just maybe someone will forget the way you have behaved so far in this thread.
CANNOT FIND INFORMATON ON GOOGLE!
GIVE URL OF INFOMATION NOW
View all questions in Keil forum