please dont rip this site
previous | start | next


Introducing the PIC’84

Architecture

A microcontroller such as the ’84 is- by its nature- a complete computer on a chip. It has 1: a processor and 2: registers, as well as 3: program and 4: data memory. This makes it different from ‘mere’ CPUs which have only the processor and registers.

In addition, the device includes 5: four types of interrupt and 6: 13 I/O pins.

Instruction Set

There are 35 instructions in the PIC84 instruction set; all are 14 bits long, and consist of an opcode and operand/s. Basically, the opcode specifies what to do and the operand/s specify how or where. These instructions are split into 3 groups: byte-oriented, bit-oriented and literal & control. Later on we will use each and every one of these operations, firstly individually (usually trivially) and secondly with others in more meaningful scenarios.

For now, let’s look at one of the instructions. Concentrate more on the format thereof, rather than the function which we’ll see closely later. I’ve chosen the instruction ADDWF- see [PIC table 4.2]. In this tutorial, I have adopted the Courier font below for all coding examples. The syntax of this instruction is:

and you’ll see this sort of look in many other instructions.

This is an appropriate time to introduce the working register: this is a special register (over and above those already mentioned) known as the W register, and it is where the arithmetic and logic unit (ALU) does the maths. Any instruction with the ‘W’ in the name acts on the working register. Generally, some other register is known as ‘F’ in these commands. So- almost intuitively- we can understand that the command ADDWF adds the working register to register F. But where is register F?

Have a look at [PIC fig 4-2]: each register (other than W, that is, which isn’t in the figure since it is a special one) is given a hexadecimal address. For instance, PORTA is 05h, TRISA is 85h and we could use one of the 36 GP registers between 0Ch and 2Fh like 3Ch. The ‘f’ in the command is a place holder for the actual address of the register F; remember there is no register F as such- it is a generic name for some register or other. So, we would code the instruction as:

Well, not quite- what’s the ‘d’ for? It is the destination of the result, and you’ll see this in many operations. Depending on our needs at the time, we need to choose to put the result either back into the working register or register F itself. [PIC page 51] explains that ‘d’ may be 1 or 0: a 0 causes the result to go to W, and a 1 puts it in F. Finally, therefore, this command could be either of the following, depending on our needs:

Let’s get on with actually writing a simple program . . . .

A simple PIC’84 program

This sample program serves a number of purposes. Apart from showing how to use a few instructions, it also introduces a couple of the assembler concepts and will also show some simple simulator techniques. The program, simple.asm is presented below; I’ll walk you through it line by line.

Let’s examine this sample program. You should verify the following by finding each directive or instruction in the appropriate Microchip book:

In the part called ‘program’, we meet a number of ’84 instructions. Check the full descriptions in [PIC] if you like; we’ll be looking at them later, anyway.

Let’s assemble and run this program . . .
 
 

Using MPLAB to debug the program

This is a three step process: edit the source code, assemble it, and then run the simulator to see what happens. If you worked through the MPLAB tutorial, you will already know about the editing and assembling. I’ll assume you have and do, and so we can move to the simulation.

With sample .asm successfully assembled, and the editor being the only window open in MPLAB, single-step through the program (the footstep icon). Not too helpful- you see each line of the program being highlighted as it is activated, but that’s it.

So, let’s start to use a few of the simulator’s other facilities. I suggest you open the following other windows in MPLAB. They all serve similar purposes- namely to see what’s happening in the registers- but all implement differently. I found it useful to have them all open at once, to compare the implementations:

With these three windows, step through your program: you’ve now got some insight into what’s going on. Satisfy yourself that all is working to plan.

Pause to reflect

Where shall we go from here? Well, where are we now? We’ve looked at the architecture and instruction set briefly; we’ve created a simple program and examined the code to get the feel of it; we’ve edited & assembled this program; and we’ve seen some of the simulator’s facilities.

I think we should move on to look more fully at the instruction set. I know that [PIC] covers all the registers, flags, interrupts, timers and stuff before going on to the instructions, but I found this the better way.



previous | start | next

Comments:

Questions:


file: /techref/microchip/intro/slide4.htm, 15KB, , updated: 2006/4/10 10:16, local time: 2008/5/17 12:57, owner: size111-hotmail-,
TOP NEW HELP FIND: 
38.103.63.16:LOG IN
©2008 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it!
<A HREF="http://www.piclist.com/techref/microchip/intro/slide4.htm"> begin</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be reviewed) Just type in the box and press the Post button. (HTML welcomed!): A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Did you find what you needed?

  cover THE book for getting started with the PIC uC! 5 stars at Amazon.com Now available from piclist.com for $34.95 ($7.50 S&H)
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .