Cytron PIC code assemble and got error in MPLAB

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Cytron PIC code assemble and got error in MPLAB

Postby mohdismiaswaly » Tue Mar 05, 2013 12:30 am

Hello,

Please look at the code below. Help me to fix the problem. This code is taken from your website. I just use my MPLAB IDE v8.3, I use MPASM Assembler toolsuite and once after I 'Build All' to assemble the code I got this error:

----------------------------------------------------------------------
Debug build of project `C:\Users\ISMI\Desktop\EC501\LAB3.mcp' started.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Tue Mar 05 00:23:48 2013
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\ISMI\Desktop\EC501\P1_1.o".
Clean: Deleted file "C:\Users\ISMI\Desktop\EC501\P1_1.err".
Clean: Deleted file "C:\Users\ISMI\Desktop\EC501\P1_1.lst".
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F4550 "C:\Users\ISMI\Downloads\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.asm" /l"P1_1.lst" /e"P1_1.err" /o"P1_1.o" /d__DEBUG=1
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 76 : Found label after column 1. (D1)
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 77 : Found label after column 1. (D2)
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 78 : Found label after column 1. (D3)
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\mplink.exe" /p18F4550 "P1_1.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"LAB3.cof" /M"LAB3.map" /W
MPLINK 4.30.01, Linker
Copyright (c) 2009 Microchip Technology Inc.
Error - file './P1_1.o', section '.org_0', Symbol '_.org_0_0056' is not word-aligned.
It can not be used as the target of a call or goto instruction.
Errors : 1

Link step failed.

----------------------------------------------------------------------
Debug build of project `C:\Users\ISMI\Desktop\EC501\LAB3.mcp' failed.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Preprocessor symbol `__DEBUG' is defined.
Tue Mar 05 00:23:49 2013
----------------------------------------------------------------------
BUILD FAILED

CODE: SELECT_ALL_CODE
;==========================================================================================
;
;   Author               : Cytron Technologies
;   Project               : DIY Project
;   Project Descrription   : PR1 (LED Blinking)
;   Date               : 25 May 2009
;
;===========================================================================================


;===========================================================================================
;   Project Description
;===========================================================================================
;   This file is a basic code template for assembly code generation on the PICmicro PIC16F84A.
;   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.                               
;                                                                                                                                       
;=============================================================================================
;
;                                                                     
;    Files required:                                                 
;                                                                   
;                                                                                                                             
;==============================================================================================
;                                                                     
;    Notes:                                                           
;     1. For beginner, the parts that you need to edit are: BANK, TRIS, PORT, DELAY                                                                 
;     2. All the general I/O pin only can use as input or output with the prior setting at TRIS.                                                                 
;     3. Let say in this case, we use pin 1,2 and 3 (RA2, RA3, RA4) as input and pin 10,11,12 (RB4, RB5, RB6) as output. So, we must
;        set TRISA,2 TRISA,3 TRISA,4 to '1' and TRISB,4 TRISB,5 TRISB,6 to '0'(in assembly, set '1' we use BSF, set '0' we use BCF
;        which we can write in this way:
;                                 BSF    TRISA,2                                                     
;                                        BSF   TRISA,3
;                                BSF   TRISA,4 
;
;                                BCF   TRISB,4
;                               BCF   TRISB,5
;                               BCF    TRISB,6
;     4. But, pls remember that before you can change TRISA, you need to switch from BANK0 to BANK1, then switch back to BANK0 after
;        setting the TRISA.BANK0 is used to control the actual operation of the PIC.For example to tell the PIC which bits of Port
;        are input and which are output.BANK1 is used to manipulated the data.
;     5. Bare in mind that in programming, we read the input; and write the output.
;     6. In assembly, to read we use BTFSC or BTFSS; while to write we use MOVLW, MOVWF, CLF, BSF or BCF. (and other type of
;        insrtuction that you can refer to PIC datasheet)   
;     7. DELAY is a kind of method that we used to use it to delay our PIC for some operation.
;     8. We already prepare the DELAY subroutine, you just CALL DELAY when you need it.
;     9. You also can change the delay time by changing the value in DELAY subroutine. (the maximum value is 255)   
;     
;=================================================================================================


   list      p=18F4550            ; list directive to define processor
   #include <p18F4550.inc>        ; processor specific variable definitions

;   __CONFIG   0X3FF2

; '__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 DEFINITION
;==================================================================================

   D1         EQU      0X20   ;REGISTER FOR DELAY
   D2         EQU      0X21   ;REGISTER FOR DELAY
   D3         EQU      0X22   ;REGISTER FOR DELAY

;====================================================================================



;=====================================================================================
; WRITE YOUR PROGRAM HERE
;=====================================================================================

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

main

; initialize of your PIC, setting the general I/O in TRIS
   
      BSF      STATUS,5            ;SWITCH TO BANK1; BIT 5 OF STATUS REGISTER IS SET TO 1
      CLRF   TRISB               ;SET PORTB AS OUTPUT ;PORTB = B'00000000'
      BSF      TRISA,2               ;SET RA2 AS INPUT ;RA2=1
      BSF      TRISA,3               ;SET RA3 AS INPUT ;RA3=1
      BSF      TRISA,4               ;SET RA4 AS INPUT ;RA4=1
      BCF      STATUS,5            ;SWITCH TO BANK0; BIT 5 OF STATUS REGISTER IS SET TO 0

      MOVLW   B'11111111'            
      MOVWF   PORTB               ;SET ALL 8 PIN IN PORTB TO HIGH(1)


; The main program begin here

START
      BTFSS      PORTA,2            ;check signal at pushbutton1, if press then goto following line, else skip the following line
      CALL      RED               ;button1 pressed, program execute the operation in subroutine RED   
      BTFSS      PORTA,3            ;check signal at pushbutton2, if press then goto following line, else skip the following line
      CALL      GREEN            ;button2 pressed, program execute the operation in subroutine GREEN
      BTFSS      PORTA,4            ;check signal at pushbutton3, if press then goto following line, else skip the following line
      CALL      YELLOW            ;button3 pressed, program execute the operation in subroutine YELLOW
      GOTO      START            ;no any button being pressed, program keep looping to check the pushbuttons' signal

RED   
      BSF          PORTB,4            ;ON YELLOW LED
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,6            ;OFF RED LED
      RETURN

GREEN
      BSF         PORTB,4            ;ON YELLOW LED
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,5            ;OFF GREEN LED
      RETURN

YELLOW
      BSF         PORTB,4            ;ON YELLOW LED         
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,4            ;OFF YELLOW LED
      RETURN


;========================================================================================
; DELAY SUBROUTINE
;========================================================================================

DELAY      MOVLW   D'200'         ;PAUSE FOR ABOUT 500mS (u can change the 200, 3, 1 value to obtain different delay timing)
         MOVWF   D3                     
         MOVLW   D'3'         
         MOVWF   D2         
         MOVLW   D'1'         
         MOVWF   D1         
         DECFSZ   D1            ;DECREASE THE VALUE OF D1 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-1            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 1 LINE ABOVE
         DECFSZ   D2            ;DECREASE THE VALUE OF D2 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-5            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE
         DECFSZ   D3            ;DECREASE THE VALUE OF D3 AND SKIP THE NEST LINE WHEN IT REACH ZERO
         GOTO   $-9            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 9 LINE ABOVE
         RETURN               ;RETURN FROM SUBROUTINE


          END                     ; directive 'end of program'
mohdismiaswaly
Apprentice
 
Posts: 39
Joined: Mon Nov 05, 2012 2:51 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby ober » Tue Mar 05, 2013 4:06 pm

Hi, for assembly code, it is not necessary to create project to build it.

Please follow the steps in Detailed Description, page 5, Getting Started to build it.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby mohdismiaswaly » Tue Mar 05, 2013 10:31 pm

Hello Ober,

OK now I managed to quickbuild the program without fail BUT that was because I disable the code in red color below, the sample code originally got it there __CONFIG 0x3FF2, but if I just let it there, compilation give error, it says that:

----------------------------------------------------------------------
Release build of project `C:\Users\ISMI\Downloads\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.disposable_mcp' started.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Tue Mar 05 22:27:51 2013
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F4550 "P1_1.asm" /l"P1_1.lst" /e"P1_1.err"
Warning[230] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 64 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Error[126] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 64 : Argument out of range (not a valid config register address)
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 76 : Found label after column 1. (D1)
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 77 : Found label after column 1. (D2)
Warning[207] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 78 : Found label after column 1. (D3)
Warning[226] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 150 : Destination address must be word aligned
Warning[226] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 152 : Destination address must be word aligned
Warning[226] C:\USERS\ISMI\DOWNLOADS\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.ASM 154 : Destination address must be word aligned
Halting build on first failure as requested.
----------------------------------------------------------------------
Release build of project `C:\Users\ISMI\Downloads\PR1 MPLABX\PR1 MPLABX\PR1_1 MPLABX\P1_1.disposable_mcp' failed.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v4.30.01
Tue Mar 05 22:27:51 2013
----------------------------------------------------------------------
BUILD FAILED

HERE IS THE SAMPLE PROGRAM CODE
CODE: SELECT_ALL_CODE
;==========================================================================================
;
;   Author               : Cytron Technologies
;   Project               : DIY Project
;   Project Descrription   : PR1 (LED Blinking)
;   Date               : 25 May 2009
;
;===========================================================================================


;===========================================================================================
;   Project Description
;===========================================================================================
;   This file is a basic code template for assembly code generation on the PICmicro PIC16F84A.
;   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.                               
;                                                                                                                                       
;=============================================================================================
;
;                                                                     
;    Files required:                                                 
;                                                                   
;                                                                                                                             
;==============================================================================================
;                                                                     
;    Notes:                                                           
;     1. For beginner, the parts that you need to edit are: BANK, TRIS, PORT, DELAY                                                                 
;     2. All the general I/O pin only can use as input or output with the prior setting at TRIS.                                                                 
;     3. Let say in this case, we use pin 1,2 and 3 (RA2, RA3, RA4) as input and pin 10,11,12 (RB4, RB5, RB6) as output. So, we must
;        set TRISA,2 TRISA,3 TRISA,4 to '1' and TRISB,4 TRISB,5 TRISB,6 to '0'(in assembly, set '1' we use BSF, set '0' we use BCF
;        which we can write in this way:
;                                 BSF    TRISA,2                                                     
;                                        BSF   TRISA,3
;                                BSF   TRISA,4 
;
;                                BCF   TRISB,4
;                               BCF   TRISB,5
;                               BCF    TRISB,6
;     4. But, pls remember that before you can change TRISA, you need to switch from BANK0 to BANK1, then switch back to BANK0 after
;        setting the TRISA.BANK0 is used to control the actual operation of the PIC.For example to tell the PIC which bits of Port
;        are input and which are output.BANK1 is used to manipulated the data.
;     5. Bare in mind that in programming, we read the input; and write the output.
;     6. In assembly, to read we use BTFSC or BTFSS; while to write we use MOVLW, MOVWF, CLF, BSF or BCF. (and other type of
;        insrtuction that you can refer to PIC datasheet)   
;     7. DELAY is a kind of method that we used to use it to delay our PIC for some operation.
;     8. We already prepare the DELAY subroutine, you just CALL DELAY when you need it.
;     9. You also can change the delay time by changing the value in DELAY subroutine. (the maximum value is 255)   
;     
;=================================================================================================


   list      p=18F4550            ; list directive to define processor
   #include <p18F4550.inc>        ; processor specific variable definitions
   
[color=#FF0000]   __CONFIG   0X3FF2[/color]

; '__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 DEFINITION
;==================================================================================

   D1         EQU      0X20   ;REGISTER FOR DELAY
   D2         EQU      0X21   ;REGISTER FOR DELAY
   D3         EQU      0X22   ;REGISTER FOR DELAY

;====================================================================================



;=====================================================================================
; WRITE YOUR PROGRAM HERE
;=====================================================================================

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

main

; initialize of your PIC, setting the general I/O in TRIS
   
      BSF      STATUS,5            ;SWITCH TO BANK1; BIT 5 OF STATUS REGISTER IS SET TO 1
      CLRF   TRISB               ;SET PORTB AS OUTPUT ;PORTB = B'00000000'
      BSF      TRISA,2               ;SET RA2 AS INPUT ;RA2=1
      BSF      TRISA,3               ;SET RA3 AS INPUT ;RA3=1
      BSF      TRISA,4               ;SET RA4 AS INPUT ;RA4=1
      BCF      STATUS,5            ;SWITCH TO BANK0; BIT 5 OF STATUS REGISTER IS SET TO 0

      MOVLW   B'11111111'            
      MOVWF   PORTB               ;SET ALL 8 PIN IN PORTB TO HIGH(1)


; The main program begin here

START
      BTFSS      PORTA,2            ;check signal at pushbutton1, if press then goto following line, else skip the following line
      CALL      RED               ;button1 pressed, program execute the operation in subroutine RED   
      BTFSS      PORTA,3            ;check signal at pushbutton2, if press then goto following line, else skip the following line
      CALL      GREEN            ;button2 pressed, program execute the operation in subroutine GREEN
      BTFSS      PORTA,4            ;check signal at pushbutton3, if press then goto following line, else skip the following line
      CALL      YELLOW            ;button3 pressed, program execute the operation in subroutine YELLOW
      GOTO      START            ;no any button being pressed, program keep looping to check the pushbuttons' signal

RED   
      BSF          PORTB,4            ;ON YELLOW LED
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,6            ;OFF RED LED
      RETURN

GREEN
      BSF         PORTB,4            ;ON YELLOW LED
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,5            ;OFF GREEN LED
      RETURN

YELLOW
      BSF         PORTB,4            ;ON YELLOW LED         
      BSF         PORTB,5            ;ON GREEN LED
      BSF         PORTB,6            ;ON RED LED
      BCF         PORTB,4            ;OFF YELLOW LED
      RETURN


;========================================================================================
; DELAY SUBROUTINE
;========================================================================================

DELAY      MOVLW   D'200'         ;PAUSE FOR ABOUT 500mS (u can change the 200, 3, 1 value to obtain different delay timing)
         MOVWF   D3                     
         MOVLW   D'3'         
         MOVWF   D2         
         MOVLW   D'1'         
         MOVWF   D1         
         DECFSZ   D1            ;DECREASE THE VALUE OF D1 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-1            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 1 LINE ABOVE
         DECFSZ   D2            ;DECREASE THE VALUE OF D2 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-5            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE
         DECFSZ   D3            ;DECREASE THE VALUE OF D3 AND SKIP THE NEST LINE WHEN IT REACH ZERO
         GOTO   $-9            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 9 LINE ABOVE
         RETURN               ;RETURN FROM SUBROUTINE


          END                     ; directive 'end of program'
mohdismiaswaly
Apprentice
 
Posts: 39
Joined: Mon Nov 05, 2012 2:51 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby ober » Wed Mar 06, 2013 7:38 am

Just notice you are using code written for PIC16F and hoping it to be assembler for PIC18F.

I think I have highlighted that PIC16F have different configurations bits compared to PIC18F. PR1 code is written for PIC16F84A, not PIC18F4550, it will generate error.

You have to find out what to put under the configuration bits setting for PIC18F4550, we do not write assembly for PIC18F.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby mohdismiaswaly » Fri Mar 08, 2013 10:36 am

HELLO OBER or Anyone,

I have check the configuration bit for PIC18F4550, and I have change and QuickBuild using MPLAB, no error now. But now I have different problem occur. I have edited the main program to suit my application; use push button switch at pin RB0 (logic high 5V is when the button released) and want to light up the LED at pin RB6 (when the button released, LED will ON and vice versa.

In short:

push the button = LED will OFF
release the button = LED will ON

Please check my code below, why after I run the PIC, when button is released yes the LED ON but it then turn OFF for a while and start to ON again, and this thing keep on repeating (button still released).

PLEASE CHECK, I HAVE CHECK FOR 2 DAYS ALREADY :x


CODE: SELECT_ALL_CODE
;==========================================================================================
;
;   Author               : Cytron Technologies [Edited by me  :)]
;       Project               : DIY Project
;   Project Description                   : PR1 (LED Blinking)
;   Date                       : 25 May 2009
;
;===========================================================================================                                   
                                                                   
;    Files required:                                                 


   list      p=18F4550            ; list directive to define processor
   #include <p18F4550.inc>        ; processor specific variable definitions
   [color=#BF0040]CONFIG FOSC = HS[/color]


; '__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 DEFINITION
;==================================================================================

   D1         EQU      0X20   ;REGISTER FOR DELAY
   D2         EQU      0X21   ;REGISTER FOR DELAY
   D3         EQU      0X22   ;REGISTER FOR DELAY

;====================================================================================



;=====================================================================================
; WRITE YOUR PROGRAM HERE
;=====================================================================================

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

main

; initialize of your PIC, setting the general I/O in TRIS
   
      BSF      STATUS,5            ;SWITCH TO BANK1; BIT 5 OF STATUS REGISTER IS SET TO 1
      BCF      TRISB,6
      BSF      TRISB,0               
      BCF      STATUS,5            ;SWITCH TO BANK0; BIT 5 OF STATUS REGISTER IS SET TO 0

; The main program begin here

UP      BTFSC   PORTB,0
      CALL   RELEASE
      CALL   PUSH
      GOTO    UP


PUSH     BCF      PORTB,6
      CALL   DELAY
      RETURN

RELEASE   BSF      PORTB,6
      CALL    DELAY
      RETURN   


;========================================================================================
; DELAY SUBROUTINE
;========================================================================================

DELAY      MOVLW   D'5'         
         MOVWF   D3                     
         MOVLW   D'3'         
         MOVWF   D2         
         MOVLW   D'1'         
         MOVWF   D1         
         DECFSZ   D1            ;DECREASE THE VALUE OF D1 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-1            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 1 LINE ABOVE
         DECFSZ   D2            ;DECREASE THE VALUE OF D2 AND SKIP THE NEXT LINE WHEN IT REACH ZERO
         GOTO   $-5            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 5 LINE ABOVE
         DECFSZ   D3            ;DECREASE THE VALUE OF D3 AND SKIP THE NEST LINE WHEN IT REACH ZERO
         GOTO   $-9            ;IF NOT ZERO, IT WILL LEAD THE PROGRAM TO 9 LINE ABOVE
         RETURN               ;RETURN FROM SUBROUTINE


                  END                     ; directive 'end of program'
mohdismiaswaly
Apprentice
 
Posts: 39
Joined: Mon Nov 05, 2012 2:51 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby ABSF » Fri Mar 08, 2013 3:32 pm

The problem of your code is here...

CODE: SELECT_ALL_CODE
; The main program begin here

UP    BTFSC   PORTB,0      ;IS BOTTON PUSHED?
      CALL   RELEASE      ;NO, LED ON FOR A WHILE
      CALL   PUSH      ;YES, LED OFF FOR A WHILE
      GOTO    UP      ;LOOP BACK AND REPEAT

PUSH     BCF      PORTB,6   ;LED OFF
      CALL   DELAY
      RETURN

RELEASE   BSF      PORTB,6   ;LED ON
      CALL    DELAY
      RETURN   


On the "BTFSC" instruction the branch will either go to "call release" or "call push". Let's assume that the button is not pushed. So it goes to "RELEASE" subroutine and switches ON the LED for a while (due to call delay) then it would return back to the instruction after "CALL RELEASE" that is "CALL PUSH" and switches off the LED for a while (Due to call delay again). After returning from "CALL PUSH", it then loop back to "UP" via the "goto up" instruction.

This will go on and on if the button remains not pushed.

You need to modify your code a little in order to accomplish what you want....

CODE: SELECT_ALL_CODE
UP    BTFSC   PORTB,0      ;IS BOTTON PUSHED?
      GOTO   HERE
      CALL   PUSH      ;YES, LED OFF FOR A WHILE
      GOTO    UP      ;LOOP BACK AND REPEAT
HERE  CALL   RELEASE      ;NO, LED ON FOR A WHILE
      GOTO    UP

PUSH     BCF      PORTB,6   ;LED OFF
      CALL   DELAY
      RETURN

RELEASE   BSF      PORTB,6   ;LED ON
      CALL    DELAY
      RETURN   



Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: Cytron PIC code assemble and got error in MPLAB

Postby Brian Griffin » Fri Mar 08, 2013 5:30 pm

When writing assembly code, write them down on a piece of paper first. And try tracing the thing from top to bottom. It helps and save a lot of time, especially in more complicated code.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Cytron PIC code assemble and got error in MPLAB

Postby mohdismiaswaly » Fri Mar 08, 2013 6:08 pm

Hello Allen,

Thanks for your reply and help..now after I edit based on your code, there is no blinking issue....but new issue come out..

I start with button pressed (logic low), yes the LED OFF
Once I release the button (logic high), the LED start to ON
After that I press the button again, suppose the LED OFF again, but that is not happening here....the LED still in ON state as above...


Any help?
Thanks
mohdismiaswaly
Apprentice
 
Posts: 39
Joined: Mon Nov 05, 2012 2:51 pm

Re: Cytron PIC code assemble and got error in MPLAB

Postby ABSF » Fri Mar 08, 2013 10:54 pm

mohdismiaswaly WROTE:I start with button pressed (logic low), yes the LED OFF
Once I release the button (logic high), the LED start to ON
After that I press the button again, suppose the LED OFF again, but that is not happening here....the LED still in ON state as above...


Did you wait long enough? Because of the delay, the LED doesnt respond immediately to the button. After pressing or releasing the button you have to wait for a while before the LED is ON or OFF.

I read the datasheet of 4550 and found out that RB0 is also the AN12 of the ADC and was defaulted to analogue on power up. So you have to set it to "digital" using CONFIG on CONFIG3H register.

On the 4550, the port pin is set or clear using LATB and not on PORTB as stated in the datasheet(though it also works using PORTB). One more thing is that "PUSH" is a reserve word for the instruction PUSH. I was wondering how you get your program assembled without fail on the MPLAB.... I have to change "PUSH" to "_PUSH" in order to get it assembled successfully.

And did you put a 10K resistor pulling MCLR high?

Read more on chapters 10-2, 21-2 and 25-1 of the datasheet.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 1 guest

cron