Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help needed with assembly programing in mplab

Status
Not open for further replies.

janosandi

Full Member level 4
Joined
Jan 23, 2010
Messages
210
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,788
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
 

Try this:

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

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
 

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

Code:
movlw   .1
movwf   EXTRA

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

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
 

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.
 

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
 

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
 

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

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
 

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.
 

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)
 

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.
 

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.
 

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
 

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.
 

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
 

Hello guys
Im still waiting ur reply for my last problem

Thx
 

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.
 

Hello ljudsko
Thx for ur time & help

I will try to make some enhancement to my code
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top