Pic chip programming help

  • Thread starter Deleted-119707
  • Start date
  • Views 1,305
  • Replies 11

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
33,892
Trophies
2
Website
trastindustries.com
XP
22,642
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.
 

UltraMagnus

hic sunt dracones
Member
Joined
Aug 2, 2007
Messages
1,964
Trophies
0
Age
32
Location
Portsmouth
Website
Visit site
XP
190
Country
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.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
33,892
Trophies
2
Website
trastindustries.com
XP
22,642
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.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
33,892
Trophies
2
Website
trastindustries.com
XP
22,642
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.
 

UltraMagnus

hic sunt dracones
Member
Joined
Aug 2, 2007
Messages
1,964
Trophies
0
Age
32
Location
Portsmouth
Website
Visit site
XP
190
Country
nicky041192 said:
1. What is a subroutine?
2. What exactly does the movf f,d and movwf do?
3. What does it mean by working register?

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.
 
General chit-chat
Help Users
    kenenthk @ kenenthk: Aw shit Mahomes just went down