Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PIC programming in ASM

  • 07-01-2008 11:21am
    #1
    Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭


    Hi guys,

    I've just picked up my old 'machine code' notes from college and I'm starting to program PIC's (working on the 16F84a presently).
    I'm writing in assembly, which is fine at the moment, but I just want to know if there are many others out there programming these chips and if so, what higher level language are you using?
    I have never programmed in C, but was quite good in BBC Basic (ha ha!) and Pascal back in the day! Also did some ASP 2.0 more recently. :)

    Any pointers for me in terms of the next step? Is C easier to program ASM in?


Comments

  • Closed Accounts Posts: 1,444 ✭✭✭Cantab.


    10-10-20 wrote: »
    Hi guys,

    I've just picked up my old 'machine code' notes from college and I'm starting to program PIC's (working on the 16F84a presently).
    I'm writing in assembly, which is fine at the moment, but I just want to know if there are many others out there programming these chips and if so, what higher level language are you using?
    I have never programmed in C, but was quite good in BBC Basic (ha ha!) and Pascal back in the day! Also did some ASP 2.0 more recently. :)

    Any pointers for me in terms of the next step? Is C easier to program ASM in?

    SDCC is quite good for small projects. I used it for 8051 chips before. 8051 not really designed to be coded in C and so you can only go so far in complexity. You can definitely compile for PIC16 in SDCC -- I imagine it's the same situation though.

    I'd stay away from PICs to be honest. I know they've got a good following of amateur hobbyists out there, but the architecture is outdated at this stage.

    Atmel AVRs are a good place to start I think -- you can program in assembly, the C compiler is optimised for the chip's architecture, there are free GUI tools from Atmel that get you up-and-running very quickly and you can extent your knowledge to the 16-bit and 32-bit AVR architectures very easily. Plus, AVRs are very cheap, Atmel produce a whole range of lovely chips with extended functionality and there are a load of boards available.

    In summary, PICs are great for hacking around on. AVRs have all the features of PICs but will be a much more pleasant experience with powerful, professionally designed free tools available and low-cost chips.


  • Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭10-10-20


    OK, great, thanks. I'll have a look at the AVR's. I did see mention of these around alright.
    I just find whole idea of a computer on a chip great in terms of the fact that I do some electronics work and a single PIC gives me endless control.

    Do you have any starter websites for AVR coding and construction etc?


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    I know they've got a good following of amateur hobbyists out there, but the architecture is outdated at this stage.

    Well personally I'd have to disagree with most of that, there is nothing wrong with the architecture of the pic?? It is perfectly suited to the size and cost of what the PIC in intended to do. Its as modern as anything for what it is However, maybe you choice of PIC is outdated (as far as I'm aware) there are much more powerful PIC's out there now(and cheaper!)
    Try the 16f627a/16f628, about €4 in maplin if I remember.
    8051 not really designed to be coded in C and so you can only go so far in complexity

    The only problem with using the SDCC with the pic, is a problem with SDCC not the PIC's. For a compiler to support a processor, it needs many support files written and tested. The primary focus of SDCC simply lies outside the PIC world, and more in the 8051 and similar world

    8051 are perfectly designed for writing in C. It's an Intel design processor, using Intel Assembly, something which again, C is perfect for using!
    No difference to using C or C++ for any Intel (or other!) processor, whether its 8 bit, 16bit, ....!


    Well how complex do you want? I used an 8051 to build an embedded DVD player, read mp3 data from DVD discs. I basically wrote a whole IDE/ATAPI driver in C using SDCC to control the 8051. Was able to send this data anywhere on my board (my mp3 decoding chip). Implemented a push button menu system using a LCD display, displayed ID3 tags on the display also.
    IMO thats all pretty complex

    A great compiler for using with pic's is called HI-TIDE from HI-tech software. It's free, has excellent PIC support, and great debugging. It uses the eclipse IDE so you'll need that installed first.

    PIC's are used in MANY low cost/low volumes products, because they are cheap, easy to program, and you can get a prototype up and running very quickly. you can also buy them in bulk with a pre-burned die!

    The other great thing about a pic is that pretty much the C you would use, will apply to programming any embedded processor/controller. It's very easy to program as it has on board flash memory, where as the 8051 would need an additional chip for your rom and a programmer

    And lastly, from the point of view of cost, the PIC are much much cheaper than an 8051 and arm set up. If you fry a pic (you will) it will cost you €4 to replace, fry your 8051, anywhere from €50+. You also need a more advanced set up to use the 8051.

    Sorry if this is all dis-jointed, started it before lunch....


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    to your question on languages,

    if you want to use basic with the pic, you should look at the STAMP microcontrollers. They use pics with additional memory and I/O. You can also use BASIC to program them.

    I'm sure there are other BASIC compilers for the PIC you could search for.....

    C would be the ideal language to learn for the processors, as it will pretty much always be the same, even if the architecture changes. Every different architecture and model however would have its own set of instructions, so you probably just couldnt start programming a new type of chip straight away, where as knowing C would allow you do this. Once have the right compiler, it will take care of all of the relevant assembly. It is very worthwhile understanding what the assembly is doing though


  • Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭10-10-20


    ianhobo wrote: »
    Well personally I'd have to disagree with most of that, there is nothing wrong with the architecture of the pic?? It is perfectly suited to the size and cost of what the PIC in intended to do. Its as modern as anything for what it is However, maybe you choice of PIC is outdated (as far as I'm aware) there are much more powerful PIC's out there now(and cheaper!)
    Try the 16f627a/16f628, about €4 in maplin if I remember.
    You're correct about the 84a, it's dated but I just want to start some where simple! I have a few 628's in the drawer at home also.
    The only problem with using the SDCC with the pic, is a problem with SDCC not the PIC's. For a compiler to support a processor, it needs many support files written and tested. The primary focus of SDCC simply lies outside the PIC world, and more in the 8051 and similar world

    8051 are perfectly designed for writing in C. It's an Intel design processor, using Intel Assembly, something which again, C is perfect for using!
    No difference to using C or C++ for any Intel (or other!) processor, whether its 8 bit, 16bit, ....!


    Well how complex do you want? I used an 8051 to build an embedded DVD player, read mp3 data from DVD discs. I basically wrote a whole IDE/ATAPI driver in C using SDCC to control the 8051. Was able to send this data anywhere on my board (my mp3 decoding chip). Implemented a push button menu system using a LCD display, displayed ID3 tags on the display also.
    IMO thats all pretty complex

    A great compiler for using with pic's is called HI-TIDE from HI-tech software. It's free, has excellent PIC support, and great debugging. It uses the eclipse IDE so you'll need that installed first.

    PIC's are used in MANY low cost/low volumes products, because they are cheap, easy to program, and you can get a prototype up and running very quickly. you can also buy them in bulk with a pre-burned die!

    The other great thing about a pic is that pretty much the C you would use, will apply to programming any embedded processor/controller. It's very easy to program as it has on board flash memory, where as the 8051 would need an additional chip for your rom and a programmer

    And lastly, from the point of view of cost, the PIC are much much cheaper than an 8051 and arm set up. If you fry a pic (you will) it will cost you €4 to replace, fry your 8051, anywhere from €50+. You also need a more advanced set up to use the 8051.

    Sorry if this is all dis-jointed, started it before lunch....

    8051 is the heart of the BBC Micro! That was the first chip I learned to do ASM on!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭10-10-20


    ianhobo wrote: »
    to your question on languages,

    if you want to use basic with the pic, you should look at the STAMP microcontrollers. They use pics with additional memory and I/O. You can also use BASIC to program them.

    I'm sure there are other BASIC compilers for the PIC you could search for.....
    No, sorry Basic was just a reference I made jokingly. I'm well past BASIC. :)
    C would be the ideal language to learn for the processors, as it will pretty much always be the same, even if the architecture changes. Every different architecture and model however would have its own set of instructions, so you probably just couldnt start programming a new type of chip straight away, where as knowing C would allow you do this. Once have the right compiler, it will take care of all of the relevant assembly. It is very worthwhile understanding what the assembly is doing though

    Good point, I understand that C is high level enough to allow me to program independently of the architecture, but doesn't that leave the developer somewhat out in the cold when things go wrong? i.e. if you don't know the architecture then you have a poor chance of fixing low-level code issues?

    I'm trying to learn PIC from the ground upwards, understand the registers and memory locations etc... have fun while doing so, and then implement a PIC in a small project and see where it leads from there...


  • Registered Users, Registered Users 2 Posts: 413 ✭✭ianhobo


    Good point, I understand that C is high level enough to allow me to program independently of the architecture, but doesn't that leave the developer somewhat out in the cold when things go wrong? i.e. if you don't know the architecture then you have a poor chance of fixing low-level code issues?

    I'm not too sure what you mean? What sort of issues do you mean?

    Regardless of whatever language you decide on, be it ASM, C, BASIC, you will still have to have a very good understanding of the architecture, that won't change, and it won't be independent of the architecture, its more that your style will be more consistent across the various architectures than it would be with assembly.It can just be easier an quicker to manipulate, and to control the hardware using a higher level language like C as opposed to assembly. Each architecture will have its own assembly language, where as your C will still pretty much be C, regardless of your chosen architecture, whether it's a pic, an ARM, an 8051. (And I mean the way you write C and the syntax as opposed to any language portability issues....)

    I also said its worthwhile learning assembly language in general, I suppose this would help you solve any specific issues that came up? Most C compiler will have an assembly directive/macro which will allow you write inline assembly inside your C. Something along the lines of....
    void myFunction(void)
    {
       int variable1 = 0;
       
       __asm
      {
           mov regA, variable1;
       }
    }
    
    the exact way will depend on the compiler though

    Another good thing about working with controllers is that as your programs and projects get bigger, you have to be very efficient in your coding and data handling to make the best use of the limited resources, an invaluable skill when you work with more powerful processors and more memory.

    Personally I think the PIC is the ideal way to start, they are cheap, easy to program, and they are featured loaded having on board timers, internal clocking abilities, onboard comparators, lots of I/O, and they operate at relatively high speeds :) Some google searches will yeild a mountain of free resources, ideas, software, particularly for that model your using

    BTW heres where you can get that compiler, I think its very good. You need to sign up first thought if I remember


  • Closed Accounts Posts: 1,927 ✭✭✭paddyp


    I've done huge amounts of pic code in assembler, now I use a compiler and would never go back. I still have to write blocks of assembler for time sensitive code but the large bulk of things can be done in C. If you have to look at the code in 6 months time assembler is a disaster. Also every PIC has it's own idiosyncrasies which in assembler land you get to know intimately, everytime you change chip you have to really read the small print and check the developer forums. The compilers take care of 99% of this.

    MPLAB comes with free ccs pcb compiler these days which is good for small projects.

    Another option I like is the HC08 family - there is a free codewarrior IDE for these - codewarrior is a proper ide unlike clunkity mplab

    Nice cheap programmer
    http://ie.farnell.com/jsp/Semiconductors/Development+Tools+&+Programming/FREESCALE+SEMICONDUCTOR/USBSPYDER08/displayProduct.jsp?sku=1324337&_requestid=39542

    For the pic the pickit2 is a good cheap development kit .. you can modify the old pickit to work as debug express pickit.


  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    For a small micro controller like that C is very good... the only reason to use asm would be if space was a serious issue, eg 12F 1K parts....

    The more projects you do the more code you will build up. If its written in C you'll find its very easy to re-use code you've written before.

    As one of the other posters said above, if you come back 6 months later and look at a complex assembly project it will be a real pain. Also the PIC 16F assembly language is quite limited, eg you have to swap memory banks, no divide instructions ect...

    Its good to know the odd bit of assembly, as the very odd time you might need to insert it into C-code, eg to clear the watch dog timer...

    Another reason for using C is that there's standards set down for writting it and checking it, eg MISRA-C / LINT, this is a must for automotive projects, but is also really good practice.

    My first PIC projects were in assembler, 11 years ago i wrote the code for a power factor meter in asm which was a real pain. The last 8 years or so i've been using C and never looked back.


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    Hi All:

    I've come to this post a little late, sorry.

    I'm just getting back into this sort of thing myself - am finding that the PICC-lite C compiler that's included free with the MPLAB software (you don't have to sign up for it, ianhobo, it's wrapped up in the MPLAB download) from Microchip is fine. However, if you're doing anything that needs precision timing (I'm thinking things like bit-banging routines in particular) you may need to go the ASM route, and I'm led to believe that the implementation on PICs is a bit ugly (thankfully, I'm not right now). However, there's a lot to be said for being able to nip round to Maplin to pick up more for very little cash, especially for small projects that don't require huge computational horsepower or facilities that an 8-bit micro can't offer (I'm thinking things like the aforementioned PIC 16's here). The fact that the 16F627 I'm messing with has an internal oscillator makes the circuitry simpler too.

    I remember that the Tekzilla people (one of the Revision3 podcasts) recommend AVR's as a starting point - simpler to program in assembler, amongst other things - and that there's a very good resource for Atmel development - www.avrfreaks.com I think?

    8051 assembler should be pretty similar to 8080/8088 assembler - I believe they're similar in the hardware department - and as such are a useful thing to examine if you're planning to write assembly language routines for a PC in the future (unlikely these days unless maybe you're Jeff Minter, but all the same...)

    Wasn't it a 6502 that powered the BBC Micro (and the C64, and the Apple ][?)

    Anyway...
    Gadget


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭10-10-20


    Hi Guys,
    I'm really enjoying the challenge of writing in ASM at the moment, PIC's have opened up a new world to projects and the like. I've written a PWM controller from scratch for LED lighting. I could have used the PWM control in one of the other chips, but I wasted the challenge. I'll interface with a simple 2-line LCD next. Radionics stock them for ~€16.

    I would look at C later on, but I never got training in it, so I will be in the deep end.
    I do find that the support for ASM is quite poor from Microchip, and the third-party websites do make up for it, but there is a steep initial learning curve in terms of bank-switching and the like. I may start documenting some of my issues in a blog at some stage.


  • Registered Users, Registered Users 2 Posts: 8,074 ✭✭✭10-10-20


    Hi All:

    ......

    Wasn't it a 6502 that powered the BBC Micro (and the C64, and the Apple ][?)

    Anyway...
    Gadget

    Errr... well spotted.

    We used to have the second processor purchased from Watford Electronics on the BBC also...
    http://en.wikipedia.org/wiki/BBC_Cheese_Wedge


Advertisement