Hi, I have seen that some of the example programs availbale in this site define/declare variables as unsigned. For eg: unsigned voltage; //A-to-D example program What type would voltage in the above case assume? If it just holds a numeric value between 0 and 255 can I directly say float f = voltage/4.5; or do I need to do any casting on this statement. Thanks in advance
Ramya, Get yourself a good book on C because you have to always either know this stuff cold or realize you don't know it cold and look it up (do this every time and you will know it cold). Good Luck Andy
Andy, I have a book titled "C and the 8051" by Tom Schultz. The data type table in this text do not contain a type 'unsigned'. It has 'unsigned int', 'unsigned char' and 'unsigned long'. And as far as I have referred this book I never found any example that just says "unsigned varibalename". That is the reason I wanted to post it on the forum expecting someone to know the answer. I have experimented using such variable. it works without any errors when I assign the value of some register to it. But it shows up an error (ERROR L210) when I try to divide that variable with a float value. unsigned voltage; unsigned step; step=0x199; voltage = (unsigned)(step/4.5);
As a relic from the original K&R days, you can often omit the keyword "int" from declarations. "int" is assumed where the specification is incomplete. For instance: MyFunction (); returns int, because there's no declared return type. unsigned i; means i is an unsigned int. IMO, leaving the keyword out is poor style. It's usually not a good idea to leave specifications implicit and assume that "everyone knows what it means". Most embedded programmers I've known do not use the raw C types, but instead typedef a series of names that specify the exact width of the type, e.g. typedef unsigned char U8; typedef unsigned int U16; typedef unsigned long U32; This way, you can change the typedefs as you change compilers and processors and keep the code portable and consistent. C99 defines an "official" series of types to the same purpose in inttypes.h. I don't think C51 supports this feature yet.
Davis, Thank you so much for your response. Now I understand why it was working fine when it was assigned a numeric value. Is there a way to convert the result of a division operation on unsigned int variable to float. I tried doing this: unsigned step; float f = (float)(step/4.5); This shows *** FATAL ERROR L210: I/O ERROR ON INPUT FILE: EXCEPTION 0021H: PATH OR FILE NOT FOUND FILE: C:\KEIL\C51\LIB\C51FPS.LIB I have looked in the Keil installation folder for this file. I did see C51BFPS LIB file but not C51FPS file. Any idea what this file is and why is this necessary for the above code snippet. Thank you
are you using the eval? floating point is not included in the eval call keil sales Erik
Hi Eric, Do you mean evaluation version by 'eval'? Yes I am using evaluation version. I have the CD that has full version but doesn't work somehow. Techincal support people told me to install 'Dongle' on the paralle port of CPU which I have no idea where to find. Thank you
Do you mean evaluation version by 'eval'? Yes Techincal support people told me to install 'Dongle' on the paralle port of CPU which I have no idea where to find If you paid for the CD, you have one, if not contact Keil sales. The CD is the same for "full" and "eval" the dongle is what opens up what ypu have to pay for. Erik
Erik, I work in a lab where this software is installed. I did not install it myself. I will have to contact network admin to find about dongle then. Thankyou for your response. Ramya
"I have a book titled 'C and the 8051' by Tom Schultz" As Erik often notes, such books are usually aimed at 'C' programmers who want to apply that skill to the 8051. Therefore, in addition to that book, you also need a book on the 'C' language itself. K&R is, of course, the standard work! http://www.amazon.co.uk/exec/obidos/ASIN/0131103628/qid=1149618505/sr=1-1/ref=sr_1_3_1/026-0034114-8808423
"The CD is the same for 'full' and 'eval' the dongle is what opens up what you have to pay for." In fact, you need both a dongle and a Serial Number - and these are supplied, with instructions, when you pay for the product: The Serial Number is needed once to install the the prouct; The Dongle is requires every time you use the installed product. You also need a valid Serial Number for support; your serial number (and its expiry date) is shown in the uVision Help/About.
K&R is, of course, the standard work! but, in my opinion not good for a novice. For a starter, I much prefer Kochan "programming in ANSI C". With that book you can teach yourself C Erik
"in my opinion [K&R is] not good for a novice" I wouldn't disagree with that. But, for a concise reference, no 'C' programmer should be without one!
K&R is widely regarded as being a tutorial. H&S is widely regarded as being the reference.
I have checked the PK51 development tools package available in the lab and found some manuals and the CD. The CD has the serial number as said by Andy. But I didn't find anything called dongle. Is that a hardware piece or software available in the CD itself?
"... dongle. Is that a hardware piece or software ..." A dongle is a hardware "key" that plugs into the parallel, serial, or USB port. License-checking software reads the "key" to ensure that you are entitled to use the software.