Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have never been to any technical site that shows concern just to anybody with problems...I look forward to also share in the future..."

Geography

Where in the world do Tek-Tips members come from?
Tico1 (Programmer)
10 Aug 06 13:00
Hi all, I am traying to write my first program using assembly. I have trouble understanding many things. Looking at the samples that I have, assembly samples for PIC16F87 I can see used EQU or equ or res as part of declatation or seems to be a declaration, and I am not sure I understand 100% what that means.

I forgat to say that I am a C# programmer as well as C/C++.
One more question: what kind of label do I have to use for an ISR routine. With other words how do I indicate to assembler that the following code has to be executed on interrupt. There is a good book that could have those answers or there is somone that could halp me with that??? your answer will be greatly appreciated....thanks a lot.  
zeitghost (Programmer)
11 Aug 06 4:44
"equ" is an assembler directive that assigns values to labels.

For instance

CODE

fred equ 0x33  

will give the label "fred" the value 0x33 (51 decimal).

There's a vast amount of data on the microchip site related to programming PICs (odd that).

I've used a couple of books.

The one I have to hand is "PIC Your personal Introductory Course" by John Morton.

The interrupt service routine is located at address 004h.

The pic jumps to address 4 when it receives an interrupt. It doesn't really need a label, but you can give it a label if you like.

If you look in the MPLAB code templates for the PIC you are using, there are get you started examples.

Hope that helps a  little.
Tico1 (Programmer)
11 Aug 06 8:50
Thanks a lot...your answer actually triggered more questions, like: a label is a PC address??? and there is any difference between EQU or equ. I would ask dirrectly how I declare a variable and how I declare a constant??? is "res" used to declare a variable???? that's my conclusion just playing with MPLAB simulator.

Your answer will greatly appreciated....
zeitghost (Programmer)
14 Aug 06 4:26
There's no difference between "equ" and "EQU".

MPLAB somewhere in its setup has a tick box that turns on case sensitivity if it's a problem. It normally runs without.

In the code segment, a label like "FRED" is the address of an instruction.

CODE

     goto FRED

some other stuff in here

FRED  addlw 1    ;a comment comes after the ";"

"Variables" are declared in the data segment.

The PIC is a bit weird as ram is referred to as registers in the documentation.

The data segment contains "Special Purpose Registers" that include the working register W and peripheral control registers and "General Purpose Registers" which are essentially just ram. The addresses of these are given in the data sheet.

CODE


   list    p=16F84 ;select processor type
   radix   hex     ;define radix as hexadecimal

;----------------------------------------------------------
;    cpu equates (memory map)
; Special Function Register Addresses

INDF    equ 0x00     ;indirect addressing register
PCL    equ 0x02     ;lower program counter byte
FSR    equ 0x04     ;indirect memory address data pointer
portA    equ 0x05     ;port A address
portB    equ 0x06     ;port B address
trisb    equ 0x06     ;trisB address in register bank 1

status    equ 0x03     ;status register
RP0     equ 5        ;bit 5 of status register
RP1     equ 6        ;bit 6 of status register

w       equ 0        ;w register


; General Purpose Register Addresses

Count1  equ 0x0d     ;pause routine inner loop counter
Count2    equ 0x0e     ;pause routine outer loop counter

;---------------------------------------------------------

; this is the program segment

   org 0x000 ;this sets the start address to 0x000

start        ;this label has the value 0x000
   movlw 10  ; put the value 0x10 into W

get_cnt      ;this label has the value 0x001

    addlw 1  ; add the literal value 1 to W

    goto get_cnt  ; repeat forever
 
Most of this sort of stuff is available on the web if you look for it.
Tico1 (Programmer)
15 Aug 06 13:38
Ok, all addvice so far is very much appreciated. I made progress actually, I have a source code done by somebody else and I am trying to understand. One of the questions is:

When an external interrupt occurs the PC is set to 0x04 for PIC16F87 and the execution starts there where normally all status is pushed in the stack the interapt is executed and before exiting the previous status is poped from stack. My confution starts from the fact that the ISR routine is called from the main and the debugger mode I can see the ISR routine being visited continuously and the INTF flag being checked. I expected that ISR is entered only when my PORTB0 goes low or hight depends how is set.

One other question is related to INTF which is used looks like it contains the bit number of TMR0IF in INTCON register. I tried to find a declaration of it and I did not find it in any asm or inc file. I found a lst file containg a declaration of INTF. The question is who did that? and what is the real meaning of it....


Your answer will be greatly appreciated....


Thank a lot
zeitghost (Programmer)
16 Aug 06 3:32
TMR0IF is found in the p16f87.inc file on my MPLAB 6.3 installation. (That's in the MCHIP_Tools folder).

It's in the section of the file marked "INTCON Bits".

If it wasn't defined somewhere it would generate an error.

If you are seeing interrupts "continuously", then I'd guess that the timer is generating regular interrupts, but that's only a guess...

Since the PIC16f87 has just the one interrupt vector, it can get a little busy in there.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close