MPLAB IDE small question

Thread Starter

hazim

Joined Jan 3, 2008
435
Hello

This is my first day with MPLAB:). I read the tutorial provided with it and it seems everything is ok till now.. I'm working as the tutorial, step by step. But when I came to debugging, "Watch" doesn't show anything changing where there is changes according to the code.. You may ask me to post the code here. I want to ask you first, the green arrow is located to "goto $", this is after I click on "Step Into", is this okay? my code starts just the next line at "STATUS". According to the tutorial, the arrow starts at the begining of the main code and not before it (goto $ or else)
At times, a window says that I should disable WTD and I did

Regards;
Hazim
 

Attachments

Not sure what you're asking, but you should use the include file for your PIC (don't define TRIS, STATUS, PORT, etc...)

I don't see the need for the goto $ statement. Try removing it.
 

BMorse

Joined Sep 26, 2009
2,675
Hello

This is my first day with MPLAB:). I read the tutorial provided with it and it seems everything is ok till now.. I'm working as the tutorial, step by step. But when I came to debugging, "Watch" doesn't show anything changing where there is changes according to the code.. You may ask me to post the code here. I want to ask you first, the green arrow is located to "goto $", this is after I click on "Step Into", is this okay? my code starts just the next line at "STATUS". According to the tutorial, the arrow starts at the begining of the main code and not before it (goto $ or else)
At times, a window says that I should disable WTD and I did

Regards;
Hazim

You will definitely have to post your code on here, especially since I see you copied and pasted other code into a template file and you have it all wrong....

We can not tell for sure how you disabled the watch dog timer (WDT) if we can not see your Config statement...

Why are you declaring variables in your main program loop??
Why is the goto $ there??



as for the Watch window, if you want to see real time updates you have to enable it,

  • click on the debugger menu,
  • then click Settings,
  • when the simulator Settings window pops up,
  • click on the tab that says Animation/Realtime Updates
  • Check the box that says Enable Realtime watch updates
  • then you can change the speed it updates by changing the value in the box that says x100 msecs, or you can leave it the way it is at 1.
B. Morse
 

t06afre

Joined May 11, 2009
5,934
The $ is in MPASM defined as arithmetic operator meaning current program counter. The goto $ statement is a endless loop. It will be the same as
Rich (BB code):
Loop
GOTO Loop
I find the use of $ operator confusing but it can be useful then you want to do testing like this.
Rich (BB code):
BTFSC ADCON0,GO ;Is conversion done?
GOTO $-1 ;No, test again
MOVF ADRESH,W ;Read upper 2 bits
The GOTO $-1 is the same as saying goto current instruction-1. You can also use it like GOTO $+5
 
Last edited:

Thread Starter

hazim

Joined Jan 3, 2008
435
Then here is my problem. I tried to remove it, but the program didn't build successively. What to do with it??:confused:
 

Thread Starter

hazim

Joined Jan 3, 2008
435
Here is the code. Sorry for it being not well arranged. As I said before, the template code ends at goto $, and my code starts after it. I'm only learning programming a PIC and trying what I learn.
 

Attachments

BMorse

Joined Sep 26, 2009
2,675
Rich (BB code):
 #include <p16F84.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;***** VARIABLE DEFINITIONS

cblock    0x0c
w_temp EQU 0x0C ; variable used for context saving​
status_temp EQU 0x0D ; variable used for context saving​
STATUS equ 03h ;Address of the STATUS register TRISA equ 85h ;Address of the tristate register for port A PORTA equ 05h ;Address of Port A COUNT1 equ 08h ;First counter for our delay loops COUNT2 equ 09h ;Second counter for our delay loops​
endc
;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector​
goto start ; go to beginning of program
ISR CODE 0x0004 ; interrupt vector location​
Interrupt: movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; Place ISR Here movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt MAIN_PROGRAM CODE start: ; remaining code goes here bsf STATUS,5 ;Switch to Bank 1 movlw 00h ;Set the Port A pins movwf TRISA ;to output. bcf STATUS,5 ;Switch back to Bank 0 movlw 02h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then​
Loop1
decfsz COUNT1,1 ;Subtract 1 from 255​
goto Loop1 ;If COUNT is zero, carry on. decfsz COUNT2,1 ;Subtract 1 from 255 goto Loop1 ;Go back to the start of our loop. movlw 00h ;Turn the LED off by first putting movwf PORTA ;it into the w register and then on Loop2 decfsz COUNT1,1 ;This second loop keeps the goto Loop2 ;LED turned off long enough for decfsz COUNT2,1 ;us to see it turned off goto Loop2 ;
goto Start ;go back to Start and turn LED​
END ; directive 'end of program'
I had rearrange some of your code, try it now... I also turned off the watch dog timer you said you turned off already....

B. Morse
 

t06afre

Joined May 11, 2009
5,934
Here is the code. Sorry for it being not well arranged. As I said before, the template code ends at goto $, and my code starts after it. I'm only learning programming a PIC and trying what I learn.
Here is the a modified code You did some small mistakes but it should be fixed now. Be very carefull then using almost identical labels like Start and start:eek: It makes it hard to read the code
Rich (BB code):
;**********************************************************************
;                                                                     *
;   This file is a basic code template for assembly code generation   *
;   on the PIC16F84. This file contains the basic code                *
;   building blocks to build upon.                                    *
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PIC data sheet for additional             *
;   information on the instruction set.                               *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:        xxx.asm                                         *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required: P16F84.INC                                       *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
 
    list      p=16F84             ; list directive to define processor
    #include <p16F84.inc>         ; processor specific variable definitions
    __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp        EQU     0x0C        ; variable used for context saving 
status_temp   EQU     0x0D        ; variable used for context saving
; variable used for counters
COUNT1        equ       0x0E                 ;First counter for our delay loops
COUNT2        equ       0x0F                ;Second counter for our delay loops 
;**********************************************************************
RESET_VECTOR      CODE    0x0000  ; processor reset vector
        goto    start             ; go to beginning of program
ISR               CODE    0x0004  ; interrupt vector location
Interrupt:
        movwf  w_temp             ; save off current W register contents
        movf   STATUS,w           ; move status register into W register
        movwf  status_temp        ; save off contents of STATUS register
;  Place ISR Here
        movf   status_temp,w      ; retrieve copy of STATUS register
        movwf  STATUS             ; restore pre-isr STATUS register contents
        swapf  w_temp,f
        swapf  w_temp,w           ; restore pre-isr W register contents
        retfie                    ; return from interrupt
MAIN_PROGRAM    CODE
start:
;STATUS         equ       03h                 ;Address of the STATUS register
;TRISA             equ       85h                 ;Address of the tristate register for port A
;PORTA           equ       05h                 ;Address of Port A
;Do not need this as it defined in inc file
                        bsf                   STATUS,5       ;Switch to Bank 1
                        movlw              00h                    ;Set the Port A pins
                        movwf              TRISA              ;to output.
                        bcf                   STATUS,5       ;Switch back to Bank 0 
Start_loop                movlw                02h                   ;Turn the LED on by first putting
                       movwf               PORTA            ;it into the w register and then
Loop1          decfsz               COUNT1,1       ;Subtract 1 from 255
                     goto                  Loop1              ;If COUNT is zero, carry on.
                     decfsz             COUNT2,1        ;Subtract 1 from 255
                     goto                 Loop1                ;Go back to the start of our loop.
                    movlw              00h                     ;Turn the LED off by first putting
                    movwf              PORTA              ;it into the w register and then on 
Loop2        decfsz             COUNT1,1           ;This second loop keeps the
                   goto                 Loop2                   ;LED turned off long enough for
                   decfsz             COUNT2,1           ;us to see it turned off
                   goto                 Loop2                   ; 
 goto                 Start_loop                       ;go back to Start and turn LED
        END                       ; directive 'end of program'
Here is the P16f84.inc file
Rich (BB code):
LIST
; P16F84.INC Standard Header File, Version 2.00 Microchip Technology, Inc.
NOLIST
; This header file defines configurations, registers, and other useful bits of
; information for the PIC16F84 microcontroller. These names are taken to match 
; the data sheets as closely as possible. 
; Note that the processor must be selected before this file is 
; included. The processor may be selected the following ways:
; 1. Command line switch:
; C:\ MPASM MYFILE.ASM /PIC16F84
; 2. LIST directive in the source file
; LIST P=PIC16F84
; 3. Processor Type entry in the MPASM full-screen interface
;==========================================================================
;
; Revision History
;
;==========================================================================
;Rev: Date: Reason:
;2.00 07/24/96 Renamed to reflect the name change to PIC16F84.
;1.01 05/17/96 Corrected BADRAM map
;1.00 10/31/95 Initial Release
;==========================================================================
;
; Verify Processor
;
;==========================================================================
IFNDEF __16F84
MESSG "Processor-header file mismatch. Verify selected processor."
ENDIF
;==========================================================================
;
; Register Definitions
;
;==========================================================================
W EQU H'0000'
F EQU H'0001'
;----- Register Files------------------------------------------------------
INDF EQU H'0000'
TMR0 EQU H'0001'
PCL EQU H'0002'
STATUS EQU H'0003'
FSR EQU H'0004'
PORTA EQU H'0005'
PORTB EQU H'0006'
EEDATA EQU H'0008'
EEADR EQU H'0009'
PCLATH EQU H'000A'
INTCON EQU H'000B'
OPTION_REG EQU H'0081'
TRISA EQU H'0085'
TRISB EQU H'0086'
EECON1 EQU H'0088'
EECON2 EQU H'0089'
;----- STATUS Bits --------------------------------------------------------
IRP EQU H'0007'
RP1 EQU H'0006'
RP0 EQU H'0005'
NOT_TO EQU H'0004'
NOT_PD EQU H'0003'
Z EQU H'0002'
DC EQU H'0001'
C EQU H'0000'
;----- INTCON Bits --------------------------------------------------------
GIE EQU H'0007'
EEIE EQU H'0006'
T0IE EQU H'0005'
INTE EQU H'0004'
RBIE EQU H'0003'
T0IF EQU H'0002'
INTF EQU H'0001'
RBIF EQU H'0000'
;----- OPTION Bits --------------------------------------------------------
NOT_RBPU EQU H'0007'
INTEDG EQU H'0006'
T0CS EQU H'0005'
T0SE EQU H'0004'
PSA EQU H'0003'
PS2 EQU H'0002'
PS1 EQU H'0001'
PS0 EQU H'0000'
;----- EECON1 Bits --------------------------------------------------------
EEIF EQU H'0004'
WRERR EQU H'0003'
WREN EQU H'0002'
WR EQU H'0001'
RD EQU H'0000'
;==========================================================================
;
; RAM Definition
;
;==========================================================================
__MAXRAM H'CF'
__BADRAM H'07', H'50'-H'7F', H'87'
;==========================================================================
;
; Configuration Bits
;
;==========================================================================
_CP_ON EQU H'000F'
_CP_OFF EQU H'3FFF'
_PWRTE_ON EQU H'3FF7'
_PWRTE_OFF EQU H'3FFF'
_WDT_ON EQU H'3FFF'
_WDT_OFF EQU H'3FFB'
_LP_OSC EQU H'3FFC'
_XT_OSC EQU H'3FFD'
_HS_OSC EQU H'3FFE'
_RC_OSC EQU H'3FFF'
LIST
 

Thread Starter

hazim

Joined Jan 3, 2008
435
The code from BMorse worked well, there was only a small mistake, "Start" at the end should be "start". The main code is the same as mine, the declarations I have at the beginning BMorse put in the template code, someone talked about this before, also BMorse made some changes in the template code.
My question now is about these changes in the template code, why the original template code of the PIC didn't work? and why it have the goto $ instruction?

Thanks for you all
Best Regards;
Hazim
 

BMorse

Joined Sep 26, 2009
2,675
The code from BMorse worked well, there was only a small mistake, "Start" at the end should be "start". The main code is the same as mine, the declarations I have at the beginning BMorse put in the template code, someone talked about this before, also BMorse made some changes in the template code.
My question now is about these changes in the template code, why the original template code of the PIC didn't work? and why it have the goto $ instruction?

Thanks for you all
Best Regards;
Hazim

All I did to the template file you used was make it more like the template I use for the f84.... I don't know where you got your template file from (mine was named f84temp.asm)

Here is what the one I use looks like:
Rich (BB code):
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PICmicro PIC16F84. This file contains the basic code       *
;   building blocks to build upon.                                    *  
;                                                                     *
;   If interrupts are not used all code presented between the ORG     *
;   0x004 directive and the label main can be removed. In addition    *
;   the variable assignments for 'w_temp' and 'status_temp' can       *
;   be removed.                                                       *                        
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PICmicro data sheet for additional        *
;   information on the instruction set.                               *
;                                                                     *
;   Template file assembled with MPLAB V3.99.18 and MPASM V2.15.06.   *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:        xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:                                                  *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


    list      p=16F84             ; list directive to define processor
    #include <p16F84.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
cblock 0x0c ;This is where you declare your vars
endc
#define Index PORTA,0 ;phototransistor #define time_set PORTA,3 ;Hall-effect #define mode_switch PORTA,2 ;Hall-effect #define Sec_Bit flags,6 ;bit 6 of flags is the seconds increment flag ;***** VARIABLE DEFINITIONS w_temp EQU 0x0C ; variable used for context saving status_temp EQU 0x0D ; variable used for context saving ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt main ; remaining code goes here END ; directive 'end of program'
the code in blue is also important, this is where you can declare variables used in your application..

the code in purple is an example of where you would define other variables used in your application...

The rest of your applications should be between the label main and END.
B. Morse
 

t06afre

Joined May 11, 2009
5,934
The template files can be found in the \Microchip\MPASM Suite\Template folder. It is one sub folder for absolute code development templates. And one sub folder for relocatable code development templates.
Also then I try to compile the code from BMorse I got a lot of errors. But if it works for you everything is OK
 

BMorse

Joined Sep 26, 2009
2,675
Also then I try to compile the code from BMorse I got a lot of errors. But if it works for you everything is OK

I never said it would compile, I just rearranged his code to match the template more, I figured it would be good practice for him to figure out what some of those errors are since they are minor.... but if you want a compilable code here it is....

Rich (BB code):
 #include <p16F84.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

;***** VARIABLE DEFINITIONS

        cblock    0x0c
            w_temp
            status_temp
            COUNT1
            COUNT2

        endc 
  ;**********************************************************************
        ORG     0x000             ; processor reset vector
          goto    main              ; go to beginning of program


        ORG     0x004             ; interrupt vector location
        movwf   w_temp            ; save off current W register contents
        movf    STATUS,w          ; move status register into W register
        movwf    status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


        movf    status_temp,w     ; retrieve copy of STATUS register
        movwf    STATUS            ; restore pre-isr STATUS register contents
        swapf   w_temp,f
        swapf   w_temp,w          ; restore pre-isr W register contents
        retfie                    ; return from interrupt



main

        bsf     STATUS,5        ;Switch to Bank 1
        movlw   00h             ;Set the Port A pins
        movwf   TRISA           ;to output.
        bcf     STATUS,5        ;Switch back to Bank 0 
        movlw   02h             ;Turn the LED on by first putting

           movwf     PORTA ;it into the w register and then
start:

; remaining code goes here
 

Loop1 

        decfsz     COUNT1,1 ;Subtract 1 from 255 

        goto    Loop1           ;If COUNT is zero, carry on.
        decfsz  COUNT2,1        ;Subtract 1 from 255
        goto    Loop1           ;Go back to the start of our loop.

        movlw   00h             ;Turn the LED off by first putting
        movwf   PORTA           ;it into the w register and then on 

Loop2
        decfsz  COUNT1,1        ;This second loop keeps the
        goto    Loop2           ;LED turned off long enough for
        decfsz  COUNT2,1        ;us to see it turned off
        goto    Loop2           ; 

        goto start ;go back to Start and turn LED 

        END                       ; directive 'end of program'
B. Morse
 

t06afre

Joined May 11, 2009
5,934
I never said it would compile, I just rearranged his code to match the template more, I figured it would be good practice for him to figure out what some of those errors are since they are minor.... but if you want a compilable code here it is....
B. Morse
Hey mon do not be upset. In fact I am used to the fact that your answer always are very accurate and spot on the problem. So I was somewhat puzzled by the errors. Not that I compile all code in this forum either. This is the first time actually. I felt something was wrong so I checked. Just that
 

BMorse

Joined Sep 26, 2009
2,675
Hey mon do not be upset. In fact I am used to the fact that your answer always are very accurate and spot on the problem. So I was somewhat puzzled by the errors. Not that I compile all code in this forum either. This is the first time actually. I felt something was wrong so I checked. Just that

Nope, I am not upset at all, I do not take offense that easy..... some of those errors were minor so I figured I just left them in so the op can practice some more, since it was his first time with it.... just wanted to make sure all aspects of the question was covered that is why I re posted compilable code....... so don't think I took offense to anything, we are all here to help each other.....

B. Morse
 
Top