Onward to PIC's;-
PIC's are stupid and need to be told the base of the numbers and this is refer to as the 'Radix' and is told to the computer by a Radix statement defining the base you are working with. e.g;- Radix = hexadecimal. or by adding a base indicator to the number so a hex number is recorded as 20H or a binary as 1100B or 08D for decimal etc.
Binary is sometime written as b'00001100' and hex as 0x20 but basically the thing is the assembler will tell you if a mistake is made.
A source program tells the PIC what to do and is a sequential series of steps and is man readable – it has rules for how information is presented and is a series of text words or mnemonics that an assembler can recognise and use to convert to binary – the text is man readable and the hex file used by the computer is computer readable – it will appear as a set of two hex numbers representing the 8 bit binary code used by the computer. The PIC we will use is 8 bit.
An Assembler is a special program which converts the text from a source program to hex which is converted by the computer to binary – OK - you write a program as a series of instructions in a human readable form of text and then convert it with an assembler to hex for the computer to read.
Then load it into the PIC with a programmer.
A source code is simple a human readable set of instructions.
A hex file is a computer readable set of instructions.
An assembler is a program which converts a source file to a hex file which can be read be the computer.
Download the datasheet for the 10f200 from :-
http://www.microchip.com/wwwproducts/De ... e=en019863
A basic PIC
The PIC word for the device we will use is 8 bits wide (called a byte)
OK think of pigeon holes or 8 boxes tied together
so the memory is a group of 8 bit bytes (meaning that the 8 bits relate to each other to form a byte)
The memory can consist of 1024 bytes of 8 bits wide (total 8182 bits )
The memory is either RAM ( = random access memory) or ROM (= read only memory )
Ram is as special registers (pigeon hole store!) and Rom as the main stored memory
The architecture will have a working register called the ' W ' Register and a set of PORT's which connect to the pins and a ALU or arithmetic logic unit and a timer – the PORT's can be configured as input or as output.
Some pins have special dedication and may be only input or output.
Special pins may have special function such as power pins
Some pins have a configurable dedicated purpose
all processors have a timer or several timers
Key words;-
RAM (can be written to or read from )
ROM (the main memory and is only written to when the device is programmed it is normally read from)
register ( can be written to or read from and is used as temp store )
PORT ( connected to the pins – can be configured as input or output and can be changed on the fly )
A basic PIC has 35 instructions
These can be divide into three groups;-
General instructions
Bit instructions
Control instructions
It is suggested that you obtain a pickit 2 debug express development module. The pack contains all you will need including a Mplab IDE, assembler and starter software. The tutorial is based upon this set.
Forget the dev board supplied with the kit – instead we will use a humble 10f200 which incorporates all of the basic features without any complication.
The 10f200 has only eight pins but two are not used leaving only 6 working pins and two of them are supply leaving only four active pins.
Of these four, one pin is dedicated as an input so you have only three to worry about for the start of the project.
The pins are called a General Purpose Interface or GPIO instead of a PORT.
The chip has a built-in RC osc so you don't have to worry about an oscillator either.
It only has 256 bytes of memory but more than enough for our purpose.
First we need to build the computer so you will need a 10f200 chip in a DIP package, a eight pin holder, an LED and a resistor, a header and a piece of vero to build it on. – a total of only six components – Wow - a complete computer with only 6 components or five if you are very sure you won't blow the chip and can do without the holder.
The computer is programmed directly from the PicKit 2 and it can even be run using the PicKit as the power supply. If you make a mistake or just want to try a new programme – no problem – it will also erase and re-programme the part again and again.
The chip also uses five of the pins during programming via the six pin header ( one pin not used )
You need to decide the layout but you have to connect the various chip pins to the header -
Header
1 Programming voltage – to chip pin 8
2 VDD supply – to pin 2
3 VSS ground – to pin 3
4 data to - to pin 5
5 clock to- to pin 4
6 not used
Also connect the resistor to pin 3 ( GP2/T0CK1) and then to the LED anode ( remember an LED is a diode ) and then the other side of the LED to ground – so apart from the programming pins you only have a diode connected to the computer via a resistor,
Now open the wizard in the projects drop-down from the running Mplab – select 10f200 as the processor from the list offered – click on next and then next again (selecting the choices offered) – it now asks for a name so dream up a name but remember to include the full string of the working directory where it is kept – click next and it invites you to enter the file you require – select the p10f200.asm first and then the 10f200.inc – finish.
You will have two files appear in the Mplab and if you click open the .asm file it will open to reveal a template already prepared for you.