Pic chip programming help

Discussion in 'General Off-Topic Chat' started by nicky041192, Mar 24, 2010.

Mar 24, 2010
  1. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    In electronics, we have to create a program for a pic chip.
    I am thinking of doing a system for a vending machine.
    I just don't understand all of the codes...
    What's the best place for. beginners to learn this stuff? The asm program tutorials are soo confusing ....

    Thanks a lot.
    -nicky

    EDIT: spelling mistakes, i posted this via my ipod touch XD
     
  2. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,712
    Country:
    United Kingdom
    ASM is awesome but they really should not be teaching it "raw" to beginners and I would probably side with those who say ASM is for making ultra tight loops and the like.

    You want an IDE (at worst it will sort some of the less fun parts of assembly out and at best you will be using C of some form), I am somewhat out of the PIC world these days (actually most programmable chips for that matter) but I did like http://www.microchip.com/stellent/idcplg?I...p;part=SW007002 . Not sure what series/chip you have opted for but there are loads of various IDE solutions for PIC so you can try a bunch if you like and that one does not support your chosen device.

    As for vending machine I hope it is a good one- your basic can vending machine could probably be done with a bunch of gates or an off the shelf IC.
     
  3. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    Thanks for the reply. We can't use logic gates. It's coursework and we have to design a program
    for pic chips. We was learning about silicon and zenner diodes and jumped straight into programming where I have no experience with it before.
     
  4. UltraMagnus

    Member UltraMagnus hic sunt dracones

    Joined:
    Aug 2, 2007
    Messages:
    1,967
    Location:
    Portsmouth
    Country:
    United Kingdom
    oh, wow, PIC asm.

    I never had to learn asm for PICs, however when I was learning 8051 asm I found it easier to just look at the instruction set rather than tutorials. Definitely use MPLAB it makes things a lot easier. A vending machine should be a rather simple assignment.
     
  5. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    well everyone is different.
    ive been trying to do this since monday. nothing has gone into my head XD
    i think the examiners has told us to use ASM4PICS program to build our program.
     
  6. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,712
    Country:
    United Kingdom
    If they launched you right into ASM from basic components I question the course but back on topic if you really must use ASM (those IDEs are there to make life easier by allowing you to use C type languages a lot of the time then again I question the course) then learn another form of ASM with more documentation first. X86 is the obvious choice with many guides.

    A handful from my collection of links:
    http://homepage.mac.com/randyhyde/webster.....edu/index.html
    http://burks.brighton.ac.uk/burks/language...asmtut/asm1.htm
    Also poke around http://www.romhacking.net/ as it does detail older chips which will resemble PICs far more than complex general purpose processors like those with X86 instruction set.
     
  7. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    i dont know what type of asm this is but we had to start withe:

    GOTO INIT
    INIT CLRF PORTA
    CLRF PORTB
    BSF STATUS,5
    MOVLW 1F
    MOVWF PORTA
    MOVLW 00
    MOVWF PORTB
    BCF STATUS,5
    START CLRF PORTA
    CLEF PORTB
     
  8. Magoo222

    Member Magoo222 GBAtemp Regular

    Joined:
    Mar 22, 2009
    Messages:
    111
    Country:
    United Kingdom
    Are you actually loading it into a PIC, and if so which model/type?
     
  9. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    it not about loading onto a PIC. just to create the code. then when all of the coursework is done and dusted, we might be loading it onto a PIC. but its not our priority
    its a 16F84 i believe
     
  10. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,712
    Country:
    United Kingdom
    That looks like you already have some of the basics there for you in some libraries of something with a handful of functions although most of that is setting everything up. No comments and nothing else does not set a good tone for this sort of thing.

    Without a specific model number it is possible to do some things but not many. I am using http://www.hobbyprojects.com/pic_tutorials/tutorial2.html , http://www.cs.uml.edu/ecg/projects/basm/ref.html , http://www.best-microcontroller-projects.c...ml#16F84_pinout and http://everything2.com/title/PIC+opcodes (a mish mash of PIC types I know) and probably not of great use to you if you are stuck with that app; assemblers vary slightly in instruction ordering (instruction, source/data, destination -> mov F, R1 or instruction destination source/data -> mov R1, F, control characters (what makes a comment and the like, what indicates a hex number or a decimal number) and even what opcodes/mnemonics they support/word them as (in your example GOTO is used where others would use bra (branch).

    At this stage I would write out what you want/have to do and try and work from there. It is still fairly simple so ASM should not be that bad (I stand by my comments calling for you to use a higher level language though).

    The I in PIC stands for interrupt which is very good as the last thing you need to be doing is running code check for things every few (milli)seconds- I can not speak for your course but if someone handed me such a program for a PIC (or any programming language that allows interrupts) I would not be inclined to pass them.

    You have not mentioned a spec so I guess it is being left for you to write one (again a bad state of affairs), there are three main sections I am guessing (assuming you do not have to do temperature or "empty" sensing- should not be too difficult to work in anyhow. I also do not know what level of security you want to work to- obviously "free drinks" is not acceptable but do you want input line encryption, output line encryption.

    You need

    Money checking- I assume this is from an manual source of sorts (mass test or something) that emits a binary signal (or something you can abuse as one) when given conditions are fulfilled (I doubt you will have a programmed value here at the sensor level) and I do not know if you will need to account for multiple coins, multiple prices, change dispensing, coin return* and so on. This is where my thoughts ran to logic gates although I guess that counts are input level programming.

    *this would carry over into your program.

    Selection action- I do not know if you have a "e7" sort of keypad entry or a 10 buttons next to pictures sort of thing. I would hope it is at some level digitised (maybe externally to the chip) as having to run a bunch of lines to your limited input pins is not ideal or all that extensible (I would get kicked for this in various circles but consider another PIC to run the input controller).

    Dispensing action- presumably a solenoid or motor or of some form- something electromechanical (note that you will need to add a transistor and a flyback diode and running kit like this from a chip (if the chip even kicks out enough current) is a bad idea without one (fry the chip bad) unless it is a simple project and you only need a "dispense can" signal and do not have to think about this. If digital and you have been given free reign then make a truth table/lookup table and submit it with your code.

    In C (not something I know all that well) you would presumably call some form of standard library
    define you function names.

    Define your function names (all three of them)

    If you have not kicked the functions to another file or files you can write them internally (bad practice mind)

    You then call your functions into the main "program" and work it from there

    It will probably be something like
    onevent coin entry call function:coinentry
    You would then sum the coins to make sure they have sufficient funds.
    After this it would be an IF, ELSE loop (IF funds=sufficient call selection ELSE return)

    Selection-# if you want to kick something to a screen or LED now would be a good time.
    onevent button press call selectiondrink
    Another IF, ELSE loop (probably IF "1", ELSE IF "2", ELSE IF "3" ELSE "4")
    I am assuming 4 drinks known by numbers.

    Now you send a dispense signal based on the selection before.

    In ASM you will have to do all of that as well as define variables at the bit level (00001 means a 5p has been put in 00010 means a 10p and however else you like),
    manage registers (you do not have many at all on the PIC so you would have to know what is what register and move it in or out of them as required* and ideally you do not want to be reading input pins to compare against so you want to stash the values in a register/memory, set outputs according to the mnemonics or register/pin names and the like), initialise the chip (it may not start functioning until something is done. It is not that difficult when you know how but I can completely understand someone new to this game not getting it right away and similarly this is why high level languages like C are used instead of ASM most of the time.

    *cutting down on this sort of thing is why ASM is used normally.

    Were it to be me I would seriously consider having strong words with the person in charge (or higher up) as this is not good.
     
  11. nicky041192
    OP

    Member nicky041192 GBAtemp Maniac

    Joined:
    Mar 9, 2008
    Messages:
    1,433
    Location:
    UK
    Country:
    United Kingdom
    I had to create a flow chart. This shows me what I want my system to do.
    Here is my flow chart (Microsoft Word): http://www.megaupload.com/?d=IVH5OWIT

    Its just all of the codes thats been confusing me. Ive been getting help from my teacher and all I understood was BSF and CLRF.

    What we should really know is just these codes:
    Mnemonic Operands Description
    bcf f, b Clear bit b of file f
    bsf f, b Set bit b of file f
    btfss f, b Test bit b of file f, skip the next instruction if the bit is set.
    call k Call subroutine k
    clrf f Clear file f
    goto k Branch to label k
    movf f, d Move file f (to itself if d = 1, or to working register if d = 0)
    movlw k Move the literal k to the working register
    movwf f Move working register to file f
    retfie Return from the interrupt service routine and set the global interrupt enable bit GIE.

    Im trying to get high marks on this piece of work. I am considering dropping the subject though. But I personally dont want to drop it.

    after looking at the table, i have a few questions...:
    1. What is a subroutine?
    2. What exactly does the movf f,d and movwf do?
    3. What does it mean by working register?


    Im slowly beginning to understand this. I guess it takes time for me to understand this stuff. I always found programming interesting ever since I was introduced to homebrew on the DS.
     
  12. UltraMagnus

    Member UltraMagnus hic sunt dracones

    Joined:
    Aug 2, 2007
    Messages:
    1,967
    Location:
    Portsmouth
    Country:
    United Kingdom
    1: a smaller part of code, so if you want to do something multiple times you don't have to copy and paste. so once you have written the subroutines you can just write:
    call a
    call b
    call a
    call c
    call a
    etc

    instead of copying and pasting the code into that sequence, it makes things much neater.

    2: moves a file to and from the working register
    3: a register is just a convenient, faster location in memory, also some commands will only work on something put into the working register.
     

Share This Page