+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Help needed with assembly programing in mplab

    Hello guys
    i have a small problem here

    can i use
    IF/ENDIF With mplab ?

    i've tried this but it gave me an error

    i've set EXTRA variable at the start of the program

    EXTRA equ 42h
    While 42h is a general purpose register

    then on a condition i've set value 1 to EXTRA

    movlw 01h
    movwf EXTRA

    Now i have the value 1 in my variable
    i want to chaek this
    i've used this

    if EXTRA = 1
    Go on here
    endif

    but it didnt work the compiler generated an error on (=)
    ive tried to replace it with equ but it didnt work too

    anybody know how to check this plz ?
    ur help will be appriciated

  2. #2
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Help needed with assembly programing in mplab

    Try this:

    if (EXTRA == .1)
    ...
    endif
    Regards!



  3. #3
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Thx dear for ur support
    i've tried this with mplab ide 8.15
    Thi simulator jumps over all the if Condition like its not exist
    so it cant check the condition of the variable



  4. #4
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Re: Help needed with assembly programing in mplab

    Are you sure, that .1 is in your EXTRA?
    Try all this:

    Code:
    movlw   .1
    movwf   EXTRA
    
    IF(EXTRA==.1)
    ...
    ENDIF



    •   Alt17th March 2010, 09:51

      advertising

        
       

  5. #5
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    yes im sure of that
    but in the simulator it skips over the if and goes to carry on here without checking if
    Canm it be that the simulator cant simulate if statement ?

    movlw .1
    movwf EXTRA

    IF(EXTRA==.1)
    ...
    ENDIF

    carry on here



  6. #6
    Advanced Member level 5
    Points: 36,328, Level: 46

    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    5,951
    Helped
    1841 / 1841
    Points
    36,328
    Level
    46

    Re: Help needed with assembly programing in mplab

    The 'IF' statement is an assembler directive, not a program instruction.

    Depending on whether the condition is true or not, it will assemble the block of code within the IF statement. You use it for example when you want to skip hardware checking while debugging software or is there are similar variants of a program and you want to selectively add or omit blocks of code.

    It looks like what you are trying to do is compare two values to see if they are equal. to do this, either subract them or XOR them and check for a zero result.

    Brian.



    •   Alt17th March 2010, 10:28

      advertising

        
       

  7. #7
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Re: Help needed with assembly programing in mplab

    What about something like this:

    Code:
    ;------ if routine
    movlw  .1
    movwf  MAX
    
    _IF	movf	MAX,w
    	sublw	.1
    	bnz	_FALSE
    
    _TRUE	;CODE BODY HERE!
    
    _FALSE	;FAILED IF TEST



    •   Alt17th March 2010, 23:40

      advertising

        
       

  8. #8
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Hello Guys
    thx for ur support really
    & sorry for bothering you
    My project is a timer which it work good
    When pushing a button it works for 1 min
    i need it to give extra time when pushing the button again
    So i've put a value when pushing the button again when the timer is running
    that why i need to check if the value at the end of my timer to start timer again if its 1

    this is the Code i've wrote to check The IF work
    still not working!!
    in this simple code without the if directive
    it wil make the led connected to pin RA2 work
    with the IF when trying to test the code with mplab sim
    the cursor stops at the line(movwf Extra) & ignores the if
    So plz what's the wrong with this ?

    thx again

    Here is a part of the program



    PROCESSOR 16F84
    #include <p16f84a.inc>

    __CONFIG _CP_OFF &_WDT_OFF &_PWRTE_OFF &_XT_OSC
    ;*****Set up the Constants****

    Extra equ 42h ;free register

    org 0x00
    goto Main
    Main
    bsf 03h,5 ;Go to Bank 1
    movlw 00h ;Put 0h into W
    movwf TRISB ;Move W onto TRISB
    movlw 03h ;Put 3h into W
    movwf TRISA ;RA0 , RA1 pins set to input
    bcf 03h,5 ;Come back to Bank 0

    movlw 0x00 ;Put 0h into W
    movwf PORTA ;Move W into

    movlw 01h
    movwf Extra

    IF(Extra==01h)
    movlw 0x4 ;Put 4h into W
    movwf PORTA
    ENDIF

    end



  9. #9
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Re: Help needed with assembly programing in mplab

    betwixt told you, why it happens so. I also post a code sample for replacement of IF sentence. Try it and report.



  10. #10
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Thx Friends
    it works perfect as i need
    i still have a small prolem which is after use of about one hour of my circuit the pic dont respond to anything untill i restart the power supply



  11. #11
    Advanced Member level 5
    Points: 36,328, Level: 46

    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    5,951
    Helped
    1841 / 1841
    Points
    36,328
    Level
    46

    Re: Help needed with assembly programing in mplab

    That's because there is no end in the program execution, it 'falls off the end' when it runs out of code.

    You need to loop the code so it is ready to run again when needed.

    I also strongly recommend you learn how to use the 'banksel' directive. The instructions are in the MPLAB help files. It will make your program much easier to follow and reduces the chance of banking errors.

    Brian.



  12. #12
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Thx mr
    my program have End ofcourse
    This is not all of my program
    Is There is a way to activate the watch dog timer in the first loop in my program
    Which is waiting a switch to activate the timer then stop it when it comes to delay loop ?

    & special thx to (ljudsko)



  13. #13
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Re: Help needed with assembly programing in mplab

    When you don't know, how to write sentences in assbembler like while, for loops or if-else instructions, you can use program above. It is in big help.



  14. #14
    Advanced Member level 5
    Points: 36,328, Level: 46

    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    5,951
    Helped
    1841 / 1841
    Points
    36,328
    Level
    46

    Re: Help needed with assembly programing in mplab

    To use the watchdog timer, all you have to do is enable it by setting the configuration bits and clear it with the "clrwdt" instruction inside the loop.

    It is a free-running counter that causes a reset if it reaches 256. When you use the "clrwdt" instruction it resets the value to zero. As long as you call the instruction before the counter reaches 256 it will never cause a reset.

    Brian.



  15. #15
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Hello Friends
    Thx for your help & thx for the program its very helpful
    Im a beginer at this programming But i need this program
    So i can study pic Programming later from the begining
    But now im just looking for what i need to make this work

    My program is quite simple:
    Waiting a push button to be pressed then a led will light on
    &a timer start a delay of 1 min then another led lights on
    which i call Warningon & another 1 min delay start then all
    lights will be off when the second dealy is working if The
    switch pressed again it will start from the begining Delay 1

    Its All works perfectly but my problem now is sometimes after
    about 30 min of work it stops responding to the switch
    all what i do is to restart the power supply
    What is the problem here ?
    is there anything wrong with my waiting loop Which keeps
    waiting the button all the time ?

    Is there a problem with the free registers which i use for
    counters in my delay loop ?

    Thanks again

    PROCESSOR 16F84
    #include <p16f84a.inc>

    __CONFIG _CP_OFF &_WDT_OFF &_PWRTE_OFF &_XT_OSC
    ;*****Set up the Constants****

    COUNT1 equ 30h
    COUNT2 equ 31h
    COUNT3 equ 32h
    COUNT4 equ 33h
    COUNT5 equ 34h
    COUNT6 equ 35h
    COUNT7 equ 36h
    COUNT8 equ 37h
    COUNT9 equ 38h
    COUNT10 equ 39h
    COUNT11 equ 40h
    COUNT12 equ 41h
    Extra equ 42h

    org 0x00
    goto Main

    Main
    bsf 03h,5
    movlw 00h
    movwf TRISB
    movlw 03h
    movwf TRISA
    bcf 03h,5
    movlw 0x80
    movwf PORTB
    movlw 0x00
    movwf PORTA
    movlw 0x00
    movwf Extra

    Call Settingcounters

    Waiting
    Btfsc PORTA,1
    Call Lightson
    goto Waiting

    Lightsoff movlw 0x00
    movwf PORTA
    Return

    Lightson movlw 0x4
    movwf PORTA
    Call Loop1
    Return

    Loop1 Btfsc PORTA,1
    Nop
    decfsz COUNT1,1
    goto Loop1
    movlw 0xC8
    movwf COUNT1
    decfsz COUNT2,1
    goto Loop1
    movlw 0x64
    movwf COUNT2
    decfsz COUNT3,1
    goto Loop1
    movlw 0x0A
    movwf COUNT3
    decfsz COUNT4,1
    goto Loop1
    movlw 0x3C
    movwf COUNT4
    call Warningon
    Return

    Warningon movlw 0Ch
    movwf PORTA
    Call Loop2
    Return



    Loop2 Btfsc PORTA,1
    Call Lightson
    decfsz COUNT6,1
    goto Loop2
    movlw 0xC8
    movwf COUNT6
    decfsz COUNT7,1
    goto Loop2
    movlw 0x64
    movwf COUNT7
    decfsz COUNT8,1
    goto Loop2
    movlw 0x0A
    movwf COUNT8
    decfsz COUNT9,1
    goto Loop2
    movlw 0x3C
    movwf COUNT9




    Settingcounters movlw 0xC8
    movwf COUNT1
    movlw 0x64
    movwf COUNT2
    movlw 0x0A
    movwf COUNT3
    movlw 0x3C
    movwf COUNT4
    movlw 0xFF
    movwf COUNT5
    movlw 0xC8
    movwf COUNT6
    movlw 0x64
    movwf COUNT7
    movlw 0x0A
    movwf COUNT8
    movlw 0x3C
    movwf COUNT9
    movlw 0xC8
    movwf COUNT10
    movlw 0x64
    movwf COUNT11
    movlw 0x14
    movwf COUNT12

    Return

    end



  16. #16
    Advanced Member level 5
    Points: 36,328, Level: 46

    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    5,951
    Helped
    1841 / 1841
    Points
    36,328
    Level
    46

    Re: Help needed with assembly programing in mplab

    And for your next lesson.... How to use Code tags.

    When posting sections of code, PLEASE click on the box marked "Code" above the message window at the start of the code section and click it again at the end. It stops the forum software removing all the formatting and makes it much easier to read.

    Brian.



  17. #17
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Yes its nice looking now
    thx Brian

    Code:
    
    PROCESSOR	16F84
    	#include <p16f84a.inc>
    
    	__CONFIG _CP_OFF &_WDT_OFF &_PWRTE_OFF &_XT_OSC
    	;*****Set up the Constants**** 
    
    COUNT1    equ           30h                 
    COUNT2    equ           31h     
    COUNT3	equ	32h
    COUNT4	equ	33h
    COUNT5	equ	34h
    COUNT6	equ	35h
    COUNT7	equ	36h
    COUNT8	equ	37h
    COUNT9	equ	38h
    COUNT10	equ	39h
    COUNT11	equ	40h
    COUNT12	equ	41h
    Extra	equ	42h
    
    	org	0x00
    	goto	Main
    
    Main
    	bsf            03h,5		
    	movlw       00h           	
    	movwf      TRISB        	
    	movlw	03h		
    	movwf	TRISA		
    	bcf            03h,5         	
    	movlw	0x80		
    	movwf	PORTB		
    	movlw	0x00		
    	movwf	PORTA		
    	movlw	0x00
    	movwf	Extra
    
    Call Settingcounters
    		
    Waiting							
    	Btfsc	PORTA,1			
    	Call	Lightson		
    goto	Waiting
    
    Lightsoff	movlw	0x00
    	movwf	PORTA
    Return					
    
    Lightson	movlw	0x4	
    	movwf	PORTA	
    	Call Loop1			
    Return
    
    Loop1   	Btfsc	PORTA,1		
    	Nop     			
    	decfsz       COUNT1,1	 
    	goto          Loop1 		
    	movlw	0xC8		
    	movwf	COUNT1      
            	decfsz       COUNT2,1    
            	goto          Loop1
    	movlw	0x64
    	movwf	COUNT2               
    	decfsz	COUNT3,1	
    	goto	Loop1
    	movlw	0x0A
    	movwf	COUNT3		
    	decfsz	COUNT4,1	
    	goto	Loop1
    	movlw	0x3C
    	movwf	COUNT4	
    	call	Warningon		
    Return	
    
    Warningon	                movlw	0Ch
    		movwf	PORTA
    		Call	Loop2
    Return
    			
    
    
    Loop2	Btfsc	PORTA,1
    	Call 	Lightson    
    	decfsz       COUNT6,1
    	goto          Loop2 
    	movlw	0xC8		
    	movwf	COUNT6       
           	decfsz       COUNT7,1     
           	goto          Loop2
    	movlw	0x64
    	movwf	COUNT7               
    	decfsz	COUNT8,1	         	
    	goto	Loop2
    	movlw	0x0A
    	movwf	COUNT8
    	decfsz	COUNT9,1
    	goto	Loop2
    	movlw	0x3C
    	movwf	COUNT9
    Return
    
    Settingcounters	movlw	0xC8		
    		movwf	COUNT1		
    		movlw	0x64		
    		movwf	COUNT2		
    		movlw	0x0A
    		movwf	COUNT3	
    		movlw	0x3C
    		movwf	COUNT4
    		movlw	0xFF
    		movwf	COUNT5
    		movlw	0xC8
    		movwf	COUNT6
    		movlw	0x64
    		movwf	COUNT7
    		movlw	0x0A
    		movwf	COUNT8
    		movlw	0x3C
    		movwf	COUNT9		
    		movlw	0xC8
    		movwf	COUNT10
    		movlw	0x64
    		movwf	COUNT11
    		movlw	0x14
    		movwf	COUNT12
    
    Return
    
    end



  18. #18
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Hello guys
    Im still waiting ur reply for my last problem

    Thx



  19. #19
    Full Member level 2
    Points: 1,392, Level: 8
    bmandl's Avatar
    Join Date
    Feb 2010
    Location
    Slovenia
    Posts
    125
    Helped
    3 / 3
    Points
    1,392
    Level
    8

    Help needed with assembly programing in mplab

    Why don't you use mnemonics? Instead of bsf 03h,5, use bsf STATUS, RP0. The code will be much more readable. And one advice. Switch on your "power on timer" in the __CONFIG line. PWRTE_ON..
    Does your compiler puts any warnings on screen? It should. Use standard record of hexadecimal numbers. Don't use 03h. Just type 0x03... And first line of all: "list p=16f84a". Delete "PROCESSOR 16f84"...
    Oh:
    Code:
    movlw   0x00      
       movwf   PORTA      
       movlw   0x00
       movwf   Extra
    Why double use of movlw, if you have 0x00 in W already? Besides, you don't need to add 0x00 to W. Just use clrf PORTA (clear file PORTA).
    I advice you to use debbounce for reading of buttons. Few miliseconds will solve problems with errors with reading. Google for 'software debounce' or something. Just add delay, when you read if button is pressed and then again if it's released. When I come home, I will give you my example program for reading buttons.
    And for variables, I advice you also to use "cblock endc" statement for declaring, insead of adding them one by one with equ statement. You can do it like that:
    Code:
    cblock 0x30
    COUNT1,COUNT2,COUNT3,COUNT4,COUNT5,COUNT6,COUNT7,COUNT8,COUNT9,COUNT10,COUNT11,COUNT12,Extra
    endc
    Cblock will add any next variable in sequence to the next register you defined first (0x30 and then 0x31 and then 0x32 and so on).
    I will look at the program more detail, when I come home. I don't have much time now.



  20. #20
    Member level 5
    Points: 1,207, Level: 7

    Join Date
    Jan 2010
    Posts
    87
    Helped
    1 / 1
    Points
    1,207
    Level
    7

    Re: Help needed with assembly programing in mplab

    Hello ljudsko
    Thx for ur time & help

    I will try to make some enhancement to my code



+ Post New Thread
Please login
Page 1 of 2 12 LastLast