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.

C and Assembly

Status
Not open for further replies.
Ok, I'm not starting another war about "C vs Assembly" and stuff like that - I need your guys opinions about my small problem.

A few days ago, I got myself a Pic Kit II, and happily learning the tutorials provided. However, the tutorials are quite shallow, only some very rudimentary stuff are thrown inside, and I still have to refer to external sources like the Net to do with the Assembly programming. Needless to say, it's mind-numbingly difficult, and now I could barely do some simple routines, and some very simple LED blinking techniques.

So I used the MikroC Compiler in my college, and however, I am allowed to use C inside. And yet, I found it's much easier for me to make many fancy stuff inside the training board without cracking/knocking/bashing my head of all the ASM codes. :)

In the end, I'm pretty confused to myself : Must I continue learning Assembly, or must I go with the C since I have covered one semester of C programming in my college and I admit that I'm extremely comfortable with it.
 
If you want to use C, I would suggest you move to an 18F series device, the C18 compiler is a free download from MicroChip, and the 18F instruction set is optimised for C.

However, I would suggest first you do play with assembler to get the feel of how a PIC works, and the 16F887 demoboard (which I presume you have?) would let you do just that - my tutorials could be moved to it fairly easily.
 
Well, my training board is equipped with the PIC 16F690, and too bad, Microchip's free C18 compiler is only meant for 18 series. So I have to do that in my college which actually equipped with the MikroC, and they supported that apparently.

Hmm... yes, I played some assembler already. Lighting up LED, yes I could do it. Make it blink, I could do it. (I dunno how to make it blink faster though)

I checked the books about PIC in my library, most of them seldom get to explain how to teach newcomers on manipulating further the ports and complex loops.

In the meantime, I'll learn both together - since I known C already ok, I can use the C as my pseudo-code to assist in composing my ASM. :)
 
C Vs Assembly is a question that does not a have a simple answer. It really depends on ones starting experience and the type of applications one deals with. The plain truth is programming productivity is mostly based on one's access to a good library of pre-written functions. C normally comes with a large library of standard functions and often there are tons of specialty library functions also made easily available.

Assembly programming can also benefit tremendously by having a good selection of pre-written library functions but if may take longer to find and/or write them. Assembly can be frustrating at first because one tends to feel that they have to create everything from scratch, where in reality any assembly programmer with any time in grade makes use of library functions to help speed up his/her productivity.

So my advice to brand new programmers is to start with a high level language like C or Basic designed to support your microprocessor series but do try and pick up assembly language later. Many high languages let you mix in assembly instructions within the program so it's easy to start simple and gradually master assembly instructions and functions. The main advantage of leaning assembly is that you will gain a more true understanding of the underlining processor, how it works and how to get the most speed and use the less memory possible when that is required.

Lefty
 
Last edited:
The BoostC compiler supports the 16F690 and it's free. They also have a forum for if (when) you get stuck and if you search here for BoostC you will find example code.

Mike.
 
Ok, I've read thru Nigel's tutorials, they are also good. I'm now doing assembly and C language together, side by side. I guess both of them are important. Since I'm in semester break, I could take quite some sweet time for the Assembly language.

Not sure about the upcoming semester's stuff, since they covered 68HC11 and not PICs. Their ASMs are all totally different, and even their organizations as well. :)

Anyway, I wish I can move to the PIC18F series to expand some more of the capabilities. But, I don't have a training board for the PIC18F - is it suitable if I can 'fabricate' the programming board, wire up the PIC Kit II onto it and pop the PIC 18F chip inside? I can't seem to find schematics on these - what must I need? :)
 
Mike/Pommie's suggestion of using BoostC for the 16F family makes sense.

If you want to go with the 18F it is very easy to slap an 18F chip down on a breadboard. Connect the 5 ICSP wires to the programmer and you have enough connections to program it.

3v0
 
Ok, will do it. But must I need diodes to protect the inputs of the programmer and the chip also? Usually, which crystal do I need?

And, recommend me an PIC 18F. There seem to be a lot of it, but I don't know which one is perfect for starters. :)
 
You need a 20K or so resistor between MCLR/VPP and +5 to act as a pullup. Some people use a diode in series to keep VPP (+12) from feeding back into VDD(+5) but you can easily do without it.

You do not need a crystal to start with if you use a PIC with internal clock. I have not used any 18F's that do not have this ability. I suggest starting with the 18F1320 (8MHz internal, 1 BKPT) or the 18F1330 (32MHz internal via PLL and 3 BKPT) which is a motor control chip with fewer timer.

The C18 code for setting up the 18F1320 is
Code:
#pragma	 config OSC = INTIO2, WDT = OFF, LVP = OFF
#include <p18f1320.h>
...
void main(void)
{
  // speed up the clock to 8MHz, 18F1320
  OSCCONbits.IRCF0=1;
  OSCCONbits.IRCF1=1;
  OSCCONbits.IRCF2=1;

  ...
}

Since you already know C you may enjoy the Cooperative Multitasking article on my site. It was written for the Junebug but you can wire up the LEDs and other hardware to make it work. Check the Junebug assembly manual for schematics. The links in my signature point the way to this stuff.

My take is that every embedded programmer should learn a few assembly languages. This provides a reasonable understanding of general microprocessor archeticture.

3v0




Ok, will do it. But must I need diodes to protect the inputs of the programmer and the chip also? Usually, which crystal do I need?

And, recommend me an PIC 18F. There seem to be a lot of it, but I don't know which one is perfect for starters. :)
 
Last edited:
The BoostC compiler supports the 16F690 and it's free. They also have a forum for if (when) you get stuck and if you search here for BoostC you will find example code.

Do they have references on the commands a syntax anywhere? im having trouble finding them. Am I correct in assuming that most pic c compilers are different from eachother in the exact command names and syntax they use?
 
You need to scan SourceBoost for virus I down load C:\Program Files\SourceBoost\boostlink.pic.exe
[DETECTION] The file contains an executable program that is disguised by a harmless file extension (HIDDENEXT/Crypted)
[NOTE] The file was moved to '4a0f629b.qua'!
Begin scan in 'E:\'
 
You need to scan SourceBoost for virus I down load C:\Program Files\SourceBoost\boostlink.pic.exe
[DETECTION] The file contains an executable program that is disguised by a harmless file extension (HIDDENEXT/Crypted)
[NOTE] The file was moved to '4a0f629b.qua'!
Begin scan in 'E:\'


BoostC from their site is fine. It does contain executables, the IDE, the compiler, the linker.....
 
I hate to say your wrong I just re downloaded it from there site and it has a virus
Begin scan in 'C:\Program Files\SourceBoost'
C:\Program Files\SourceBoost\boostlink.pic.exe
[DETECTION] The file contains an executable program that is disguised by a harmless file extension (HIDDENEXT/Crypted)
[NOTE] The file was moved to '4a16ee6a.qua'!
that was at 5.47pm 2/27/09
 
A hidden exe message is not a virus warning, it's only flagged as suspicious behavior.
 
Last edited:
It's ok I just removed it and it stop my ant virus program from poping up ever 5 sec. saying that was trying to connect to net. SourceBoost works find with out it.
 
boostlink.pic.exe is a linker

Code:
C:\Program Files\SourceBoost>boostlink.pic.exe
BoostLink Optimizing Linker Version 6.91
http://www.sourceboost.com
Copyright(C) 2004-2008 Pavel Baranov
Copyright(C) 2004-2008 David Hobday



Usage: linker.exe [options] files
Options:
 -t name        target processor
 -On            optimization level 0-1 (default n=1)
                n=0 - no optimization
                n=1 - pattern matching and bank switching optimization on
 -v             verbose mode
 -d path        directory for project output
 -p name        project (output) name for multiple .obj file linking
 -ld path       directory for library search
 -rb address    ROM base (start) address to use
 -rt address    ROM top (end) address to use
 -swcs s1 s2 s3 Use software call stack. Hardware stack is allocated by
                specifying stack depths s1,s2,s3 - these are optional
                s1 = main and task routines hardware stack allocation
                s2 = ISR hardware stack allocation
                s3 = PIC18 low priority ISR hardware stack allocation
 -isrnoshadow   ISR No use of Shadow registers
 -isrnocontext  ISR No context Save/restore is added to ISR(PIC18 only)
 -icd2          Add NOP at first ROM address for correct ICD2 operation
 -hexela        Always add extended linear address record to .hex file
 -beep          Issue sound at the end of link (default off)

Switches for making libraries:
 -lib        make library file from supplied .obj and .lib files
 -p name     project (library output file) name



failure

C:\Program Files\SourceBoost>
I have it and zoneAlarm on my system. If the linker used the internet zoneAlarm would inform me.
 
It drives my antvir crazy and i have removed it and SourceBoost works find
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top