Microcontroller Programming With C

This is a discussion on Microcontroller Programming With C within the A Brief History of Cprogramming.com forums, part of the Community Boards category; (I realize that this might not be the right board, but I also posted in the C board. I figured ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Microcontroller Programming With C

    (I realize that this might not be the right board, but I also posted in the C board. I figured that this thread might bring in useful comments from the GD board)

    I'm getting interested in building and programming robotics. I'm going to do this with C...microcontroller programming with C. Is this much different? What would I need (I assume an emulator and/or something to burn the chip)?

    If anybody has any links to a microcontroller programming (preferably in C) with forums, etc., that would be very helpful.

    --Garfield the Programmer

    P.S. If you program microcontrollers in C, can you post some code so I can see the difference? Thanks.
    1978 Silver Anniversary Corvette

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Hmm, I'm not familiar with microcontrollers that allow you to program in C... I've used a number of microcontrollers that require you to use some form of assembly language, or some which use a modified form of BASIC.

    I know people can, and do, use C to program microcontrollers -- the hard part is getting compilers. To buy the software packages for many of these microprocessors is a couple thousand dollars in investment -- so when I do it, I either use university facilities to do the programming, or use home-built hardware and software. As I never made a C compiler, I haven't really done programming in C. I've written assemblers, using C, to aid in programming, if that's what you mean.

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    how exactly do you write an assembler?

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    You basically write a text parser, which reads one line at a time, tokenizes it, and uses lookup tables to convert the assembly code into the proper machine instructions.

    Writing something with as many features as MASM, for example, would take time; I only implemented a watered-down version of x86 assembly language, which compiles to the machine language of whatever controller I'm using.

    In the past, I've implemented commands like this:
    Code:
    const char * commands[] = {"ADD","SUB"};
    #define NUM_COMMANDS 2 
    .
    .
    .
    for (i = 0; i < NUM_COMMANDS; i++){
       if (strcmp(commands[i],commandString)==0){
          operation = i;
          break;
       }
    }
    Once I've gotten the operation decided (if it didn't fail the operation matching), I could use a switch statement to go to the appropriate code, but I prefer to use an array of function pointers. Then I have one function for each command, which checks the parameters for that command, and returns success or failure (failure == bad command parameters).

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Programming a microcontroller in C is not particulaly different to programming anything else in C these days. Todays chips come with an PC IDE and compiler, (at least, I can't think of any that don't), which takes pretty standard C source code, compiles/links it to some executable image, and provides a tool for downloading this image into the chip. There is usually some kind of API that you can use to access hardware specific bits and pieces.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Do you know where I'd get these tools?
    1978 Silver Anniversary Corvette

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Generally, you buy them from the same company as the chips. In our case, mostly Motorola and NEC.

    It tends also to depend on what you call a microcontroller. I have seen Z80's, 68xx's, 8080's and 8008's all called microcontrollers. These are general purpose microprocessors, and it is quite possible to build general purpose computers with them, indeed, I have used such things for years. These can have their own OS's and compilers.

    As an example, look here...

    http://www.geocities.com/SiliconVall...8/z80_home.htm

    ... for some stuff on Z80's, including circuit diagrams to build your own simple machines - much fascinating stuff here, (bias - I loved the Z80).

    Another thing to consider when talking about embedded systems is the OS. Several company's supply specialised OS's for use in embedded systems. In house here we use Phar-Lap, (Windows like), PSOS, (Unix like), and Windows CE. The OS vendors provide compilers and support tools. Windows CE is quite mainstream now, if you browse MS web site, (for example), looking for "Platform Builder" and "Embedded Visual C++" you'll find loads of stuff.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    So you program microcontrollers, adrianxw? How is it? I have this newly found interest in making and programming a robot.

    --Garfield
    1978 Silver Anniversary Corvette

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    BACK TO THE SUBJECT:

    >> "Embedded Visual C++" <<

    adrianxw, what exactly do you mean by "Embedded"? I've heard that terminology, but I never knew what it meant.

    Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  10. #10
    Registered User goran's Avatar
    Join Date
    Sep 2001
    Posts
    68
    hey garfield, no offence but you seem to be really obsessed with the idea of a robot. read some fiction, of late ?

    cheers,
    I don't wait for the future; it comes soon enough.

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> no offence but you seem to be really obsessed with the idea of a robot <<

    None taken. No, I haven't read fiction, but I just want to go down the line of languages/products. I first started out with BASIC, and that is the highest-level, no memory management, language every written. Then, I went on to C. C is a pretty low-level language right next to the hardware. And I'm never going to stop programming with C (especially Windows programming). But, there is one more language that is the lowest-level, the most core language and you can't go any lower. And that is assembler.

    I find robots quite interesting. I love writing software a lot and I do it pretty well, if I might add. But the idea to make something physical that has one soul purpose, it interests me. Not more than software, but it is interesting. Since I already know C, I'll just look into programming microcontrollers with C.

    --Garfield
    1978 Silver Anniversary Corvette

  12. #12
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Z8 chip

    Okay, I think that I'll let you guys on to a little bit of information. Provided that it will help my learning process.

    My father programs in assembler with the zilog Z8 chip. I just told him about my interest in assembler and he told me to go for it. Of course, he told me about the brain racking, hard concepts of it. He also explained that an electronical understanding is almost necessary to learn it too (and I'm only 15). So, he said he'd help me out with the "electrical" understanding.

    He already has the emulator (which, apparently, is the simulator and burner), the compiler, and then I'll have to buy my own chip.

    Funny how some things just work out.

    --Garfield
    1978 Silver Anniversary Corvette

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> mean by "Embedded"?

    When you program, (for example), you are directly using a computer. When you put your clothes in the washing machine and tell it to clean them, you are not directly using the computer inside the machine, it is "embedded" i.e. it is a component of a larger system.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    adrianxw, I'm not sure of what you mean. Do you mean that if you indirectly access and work with a processor, that's "embedded"? It is not really making sense to me.

    --Garfield
    1978 Silver Anniversary Corvette

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> if you indirectly access and work with a processor,

    If you like. I'm afraid the term does not really have a universally accepted definition.

    One of our range of products is an Intel based board with various specialist peripherals hung on it. We use this same board in various platform ticket machines used by railways, ticket issuers used by car parking companies, and fare computers fitted in buses and operated by the bus driver. All of the users are "talking" to a simple interface which seems purpose built for their own application, but in fact, they are talking to a very sophisticated embedded computer which does all the actual work. Even our simplest boxes are shipped with over half million lines of compiled Pascal in them.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 02-18-2009, 05:10 AM
  2. Replies: 27
    Last Post: 10-25-2007, 10:47 AM
  3. Programming a PIC 16F84 microcontroller in C
    By Iahim in forum C Programming
    Replies: 1
    Last Post: 05-13-2004, 02:23 PM
  4. C for microcontroller
    By phernyt in forum C Programming
    Replies: 2
    Last Post: 12-08-2001, 12:01 PM
  5. Microcontroller Programming With C
    By Garfield in forum C Programming
    Replies: 20
    Last Post: 11-17-2001, 04:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21