Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

cant get uart to display port values :(

Status
Not open for further replies.
Regardless of where you find sprintf its function remains the same. I expect it is stored in stdio.h because we most often use it to format strings which we then send to an output device. I do not see where the confusion is.
 
It wasn't a question, more of a ponder as to why they have moved it around, the confusion would be if you included STDIO only to find it was in IOSTREAM, I was talking about possible confusion when coming to use the function.
 
Wilksey...3V0... We're not helping LG.... Suffice to say sprintf() IS in "stdio" in both C18 and Hi-Tech... Stream and string are one and the same..... The IOSTREAM library is mainly C++... and is defined in "CONIO.H".

But we are talking about embedded C...
 
personaly i think Logan would be better off with Hitech C, my reasons are as follows... there are some very good books for the hitech C compiler while as far as i have been able to find C18 has none. the help files are less than helpful in many cases for C18. i had a look at the pdf 3v0 linked to and its a good case in point. it seems to be aimed at engineers there are very very few examples and for beginners and non engineers a few short lines of an example make all the difference for example compare the following formats picked at random.

C18's explanation of isalnum
Code:
isalnum
Function: Determine if a character is alphanumeric.
Include: ctype.h
Prototype: unsigned char isalnum( unsigned char ch );
Arguments: ch
Character to be checked.
Remarks: A character is considered to be alphanumeric if it is in the range of ‘A’ to
‘Z’, ‘a’ to ‘z’ or ‘0’ to ‘9’.
Return Value: Non-zero if the character is alphanumeric
Zero otherwise
File Name: isalnum.c

Hitech C explanation

Code:
Description
These macros, defined in ctype.h, test the supplied character for membership in one of several over-
lapping groups of characters. Note that all except isascii() are defined for c, if isascii(c) is true or if
c = EOF.
isalnum(c) c is in 0-9 or a-z or A-Z
isalpha(c) c is in A-Z or a-z
isascii(c) c is a 7 bit ascii character
iscntrl(c) c is a control character
isdigit(c) c is a decimal digit
islower(c) c is in a-z
isprint(c) c is a printing char
isgraph(c) c is a non-space printable character
ispunct(c) c is not alphanumeric
isspace(c) c is a space, tab or newline
isupper(c) c is in A-Z
isxdigit(c) c is in 0-9 or a-f or A-F
255
Example
#include <ctype.h>
#include <stdio.h>
void
main (void)
{
char buf[80];
int i;
gets(buf);
i = 0;
while(isalnum(buf[i]))
i++;
buf[i] = 0;
printf("’%s’ is the word\n", buf);
}
See Also
toupper(), tolower(), toascii()

both examples are pretty representitive of the documentation for each. from my view point Logan is very keen on electronics and pic's but he has very very limited access to information he can understand and process he learns by taking others code and adapting it and that has taken him so far but now he wants to get books and sit down work through examples and adapt them to his needs, he is 11 so pure therory dosnt hold his attention for long while loading a pic with a working program seeing how it works and then adapting and altering the code seem to work better for him,
a good example of this is the rs232 thing he is doing he wasnt getting far untill he got an example from ian with that he understood a few more things and has managed to develop it. also it has helped him understand the syntax for othr things and he is writeing code that seems to work well although i doubt its very effecient! but at this point i dont think that matters.
he cant get support for pics at school as they only use flow code and even then it isnt meant to be used by students under 15! the internet and this site are a great resource but books seem to hold his attention better some times as he realy likes to read a physical book not just on pics but all kinds of things and spends alot of time reading.
its very hard to know just what to do for the best for him i want to encourage his enthusiasm as i think given the chance he will take electronics all the way wich considering the limited job oprtunities around here would be good for him.
anyway this is my view point but ultimately i leave upto logan to decide what to use wich at the moment is C18 but he feels alot of frustration with the lack of realy good docs and no books!
 
its easier said than done when his main option is to teach himself, there dosnt seem to be much in the way of learning aids for c18. I am also disapointed with his school only offering flow code and even then its designed for older students, so like i say he has to make do with learning what he can anyway he can, i wish i had the time and knowledge to help him but i dont. we dont live near anybody let alone someone that could teach him! i know you offered to teach him but the time difference makes it very hard to have him online for a reasonsable lengh of time reguarly.
 
Ghostman.... I learnt C with TurboC 2.0.... then TurboC++ 3.1 from Borland... LG can download Borland C++ 4.5 for free... When using the console, you can do virtually any thing that can be done on a micro (unless it's device dependent).... This is all I have done to learn C..

I hardly read the C18 OR the Hi-tech manuals.. The only thing I use is the peripheral docs and the src files and the headers...

There was a book I purchased... It was "Interfacing the PC"... It was primarily aimed at Visual Basic 3 and Borland Pascal 5... Interfacing to virtually any device.... I still use it today, as the pacsal code is quite easy to port to C.... This book taught me absolutely loads....

3V0.... I meant that a stream and a string are both character array's.... physically the same.
 
thanks ian i like the idea of the book but C++ might be too much on top of C# but that will be down to LG.
 
your probally right. his end goal is to write a pc program to talk to the pic so he has chosen C# for that and has been going through tutorials for it. so i think throwing C++ into it is too much but thats upto him.
 
hi i will stick with C18 for now and C# at least till i get my bot all done its nearly ready for the comp after that i am going to work on a better one for next years comp as i will have more time what i would like to know is how to display the contents of a memory location for example FF2 is the memory location of the INTCON reg how would i display the contents of it bit by bit or any single bit by using its address rather than the bit name?
 
ok i think i got how to display the values of the address but i get 12 digits and i was exspecting 8? can anyone explain why that is?

DOH DOH actualy what i get displayed is FF2 in binary instead of the address contents so i dont have the answer :( but will keep trying
 
Last edited:
delving a bit deeper it looks like i need a pointer and because its a physical address am i right with needing a CONST CHAR pointer for the address then do a loop counting the 8 bits and each time round the loop print out the bits? the idea would be to get th user to input the address via serial port. once i get everything i want working i have an idea for a debug tool :D
 
If you want to see the value stored in a SRF use the name of the SFR.
For everything else you should be using variables.

Given your current level of understanding forget pointers and use arrays.

Have you forgotten how to use the debugger ?

Do the best you can on this year robot without burning time on new tools. You can work on tools for next year.

EDIT: My years of experience both in programming and teaching the same tell me you really need to narrow you focus. I would forget about anything but C on the robot for now. You can use hyperterm or similar to command the robot without going into programming on the PC.
 
Last edited:
If you want to learn C# then don't learn C++, C++ is C with classes essentially (OK, bit more involved, but I wont go into explaining the differences here).
C# was designed by one of the architects that developed Delphi for Borland, which is why I think the later Borland suite (before they sold out) included a .NET compiler.

The best piece of advice I can give for learning C# is to learn C first, use CodeBlocks and play around with code, the most similar language to C# is Java believe it or not, you can also get the .NET Micro Framework to create code for Arduino type boards using C#, they tend to be Arduino shield compatible also. (FEZ Domino, FEZ Panda, etc).

Once you have mastered the basics of C it's just a case of figuring out which header files and which structures to use (if necessary), you will also be able to code without any manuals and books, just reference for a particular function etc, I prefer to use unions rather than bitmasking by code for example, something I was unsure if C18 supported, but it does, in fact the MCHIP C compilers are quite good at complying with ANSI C.
 
Yes they do, I did however realise it was supported before looking at the header files, that was a glorious time!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top