Basic 16F84

Status
Not open for further replies.

uaefame

New Member
I am using 16F84 microchip,
Code:
;EQUATES SECTION

TMR0		EQU	1
STATUS		EQU	3
PORTA		EQU	5
POTRB		EQU	6
TRISA		EQU	85H
TRISB		EQU	86H
OPTION_R	EQU	81H
ZEROBIT		EQU	2
COUNT		EQU	0CH

;******************************************************
LIST 	P=16F84;
ORG	0;
GOTO	start;

;******************************************************

;CONFIGURATION BITS

__CONFIG H'3FF0'

;*********************************************************

;SUBROUTINES SECTION

;1 SECOND DELAY

DELAY1		CLFR		TMR0
LOOPA		MOVF		TMR0,W
		SUBLW		.32
		BTFSS		STATUS,
				ZEROBIT
		GOTO		LOOPA
		RETLW		0

;0.5 SECOND DELAY
DELAYP5		CLFR		TMR0
LOOPB		MOVF		TMR0,W
		SUBLW		.16
		BTFSS		STATUS,
				ZEROBIT
		GOTO		LOOPB
		RETLW		0

;*****************************************************************

;CONFIGURATION SECTION

start 	BSF			STATUS,5
		MOVLW		B'00011111'
		MOVWF		TRISA
		MOVLW		B'00000000'
		MOVWF		TRISB
		MOVLW		B'00000111'
		MOVWF		OPTION_R
		BCF			STATUS,5
		CLRF		PORTA
		CLRF		PORTB


;**********************************************************************

;PROGRAM STARTS NOW

END

These are the codes, I borrowed these codes from a book. I am trying to learn how to build these codes.

Using Mplab i press control+F10 and these are the error that i faced 27error!
Code:
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Hisham\Desktop\Spring 2008\Design 2\Design II modified\Open loop\Test.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 20:58:34 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "C:\Documents and Settings\Hisham\Desktop\Hesham.asm" /l"Hesham.lst" /e"Hesham.err" /o"Hesham.o" /d__DEBUG=1
Warning[205] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 14 : Found directive in column 1. (LIST)
Warning[205] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 15 : Found directive in column 1. (ORG)
Warning[203] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 16 : Found opcode in column 1. (GOTO)
Warning[205] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 22 : Found directive in column 1. (__CONFIG)
Error[122]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 30 : Illegal opcode (CLFR)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 31 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 32 : Executable code and data must be defined in an appropriate section
Error[128]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 33 : Missing argument(s)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 33 : Executable code and data must be defined in an appropriate section
Warning[207] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 34 : Found label after column 1. (ZEROBIT)
Error[115]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 34 : Duplicate label ("ZEROBIT" or redefining symbol that cannot be redefined)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 35 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 36 : Executable code and data must be defined in an appropriate section
Error[122]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 39 : Illegal opcode (CLFR)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 40 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 41 : Executable code and data must be defined in an appropriate section
Error[128]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 42 : Missing argument(s)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 42 : Executable code and data must be defined in an appropriate section
Warning[207] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 43 : Found label after column 1. (ZEROBIT)
Error[115]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 43 : Duplicate label ("ZEROBIT" or redefining symbol that cannot be redefined)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 44 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 45 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 51 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 52 : Executable code and data must be defined in an appropriate section
Message[302] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 53 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 53 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 54 : Executable code and data must be defined in an appropriate section
Message[302] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 55 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 55 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 56 : Executable code and data must be defined in an appropriate section
Message[302] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 57 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 57 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 58 : Executable code and data must be defined in an appropriate section
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 59 : Executable code and data must be defined in an appropriate section
Error[113]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 60 : Symbol not previously defined (PORTB)
Error[152]   C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 60 : Executable code and data must be defined in an appropriate section
Warning[205] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 67 : Found directive in column 1. (END)
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Hisham\Desktop\Spring 2008\Design 2\Design II modified\Open loop\Test.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 20:58:35 2008
FAILED
----------------------------------------------------------------------

Any solution, i am looking forard for help
 
uaefame said:
Any solution, i am looking forard for help
I have just the thing for you. On my new web-site there's a simple newbie circuit and some easy asm code to show you how to get started properly. And there's photos of the breadboard too. You can take it from there.
**broken link removed**
 
Woops. I just noticed that my schematic didn't match the photos. It would work just fine, but might confuse you since they didn't match. I just changed it to match.

So if you just looked at it or downloaded it, refresh your browser by going to the page and hitting F5 and go look at it or download it again.
 
Last edited:
And here's your code cleaned up and with many corrections. There were misspellings and indentation errors and things that were done just plain strangely. It now assembles with no errors. Ignore those two warnings. They're taken care of in the code, but it warns you anyway.

By the way, this code does nothing yet. Just sets a few registers and falls into empty memory. Then it runs thru the nops (empty memory) and rolls over and starts again... and goes again and again and again, doing nothing.
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

	cblock	0x0c
	COUNT
	endc

ZEROBIT	EQU	2

	org	0
	goto	start

;SUBROUTINES SECTION

;1 SECOND DELAY
DELAY1	clrf	TMR0
LOOPA	movf	TMR0,W
	sublw	.32
	btfss	STATUS,ZEROBIT
	goto	LOOPA
	retlw	0

;0.5 SECOND DELAY
DELAYP5	clrf	TMR0
LOOPB	movf	TMR0,W
	sublw	.16
	btfss	STATUS,ZEROBIT
	goto	LOOPB
	retlw	0

;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00011111'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;PROGRAM STARTS NOW

	end
And don't use "OPTION_R". Use the proper equates from the datasheet and the include file. The correct thing to use in place of "OPTION_R" is "OPTION_REG".
 
Last edited:
Thank alot, Most of the error disapear thanks alot.
Code:
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Hisham\Desktop\Spring 2008\Design 2\Design II modified\Open loop\Test.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 21:47:33 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "C:\Documents and Settings\Hisham\Desktop\Hesham.asm" /l"Hesham.lst" /e"Hesham.err" /o"Hesham.o" /d__DEBUG=1
Message[302] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 38 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\DOCUMENTS AND SETTINGS\HISHAM\DESKTOP\HESHAM.ASM 40 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPLink.exe" "..\..\..\..\..\..\..\Program Files\Microchip\MPASM Suite\LKR\16f84.lkr" "Hesham.o" /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"Test.cof" /M"Test.map" /W
MPLINK 4.15, Linker
Copyright (c) 2007 Microchip Technology Inc.
Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x0000002e
Errors    : 1

Link step failed.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Hisham\Desktop\Spring 2008\Design 2\Design II modified\Open loop\Test.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 21:47:35 2008
FAILED
----------------------------------------------------------------------

This error was notice
 
hi,
I would suggest you create a folder on your hard drive thats dedicated to your assembler output.

This will make your error messages easier to read and the assembled files more accessible.

You should add near the top of your program.
errorlevel -302

this will stop the 'Bank' warning messages
 
uaefame said:
This error was notice
How is your Project set up? Here's what I get when I assemble:
Code:
Release build of project `C:\MCU\16F84A\blinky\blinky.mcp' started.
Thu Mar 27 10:57:34 2008
----------------------------------------------------------------------
Make: The target "C:\MCU\16F84A\blinky\uae_test.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F84 "uae_test.asm" /l"uae_test.lst" /e"uae_test.err"
Message[302] C:\MCU\16F84A\BLINKY\UAE_TEST.ASM 38 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\MCU\16F84A\BLINKY\UAE_TEST.ASM 40 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\MCU\16F84A\BLINKY\UAE_TEST.ASM 42 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Loaded C:\MCU\16F84A\blinky\uae_test.cod.
----------------------------------------------------------------------
Release build of project `C:\MCU\16F84A\blinky\blinky.mcp' succeeded.
Thu Mar 27 10:57:35 2008
----------------------------------------------------------------------
BUILD SUCCEEDED
 
Like this:
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
	errorlevel -302

	cblock	0x0c
	COUNT
	endc

ZEROBIT	EQU	2

	org	0
	goto	start

;SUBROUTINES SECTION

;1 SECOND DELAY
DELAY1	clrf	TMR0
LOOPA	movf	TMR0,W
	sublw	.32
	btfss	STATUS,ZEROBIT
	goto	LOOPA
	retlw	0

;0.5 SECOND DELAY
DELAYP5	clrf	TMR0
LOOPB	movf	TMR0,W
	sublw	.16
	btfss	STATUS,ZEROBIT
	goto	LOOPB
	retlw	0

;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00011111'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;PROGRAM STARTS NOW

	end

Code:
Release build of project `C:\MCU\16F84A\blinky\blinky.mcp' started.
Thu Mar 27 11:00:46 2008
----------------------------------------------------------------------
Make: The target "C:\MCU\16F84A\blinky\uae_test.o" is out of date.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F84 "uae_test.asm" /l"uae_test.lst" /e"uae_test.err"
Loaded C:\MCU\16F84A\blinky\uae_test.cod.
----------------------------------------------------------------------
Release build of project `C:\MCU\16F84A\blinky\blinky.mcp' succeeded.
Thu Mar 27 11:00:47 2008
----------------------------------------------------------------------
BUILD SUCCEEDED
 
Last edited:
I did as ericgibbs told me, I change the file path.

Code:
Debug build of project `D:\Openloop\test.mcp' started.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 22:18:04 2008
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "D:\Openloop\test.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "C:\Documents and Settings\Hisham\Desktop\hesham2.asm" /l"hesham2.lst" /e"hesham2.err" /o"hesham2.o" /d__DEBUG=1
Executing: "C:\Program Files\Microchip\MPASM Suite\MPLink.exe" "C:\Program Files\Microchip\MPASM Suite\LKR\16f84.lkr" "hesham2.o" /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test.cof" /M"test.map" /W
MPLINK 4.15, Linker
Copyright (c) 2007 Microchip Technology Inc.
Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x0000002e
Errors    : 1

Link step failed.
----------------------------------------------------------------------
Debug build of project `D:\Openloop\test.mcp' failed.
Preprocessor symbol `__DEBUG' is defined.
Thu Mar 27 22:18:05 2008
FAILED

I can't figure out the error.

I am using linker file 16F84.lkr
 
uaefame said:
I can't figure out the error.

I am using linker file 16F84.lkr
If you're assembling just one asm source file you don't need any linker file.
 
OMG, Problem solved i can't belive it.
I assembled for the first time.
OMG.
Thanks everyone
I just removed the linker and it worked thanks alot.
 
Thanks everyone specially "futz" For helping me around.
I am looking for a way to improve these codes

Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	COUNT
	endc

ZEROBIT	EQU	2

	org	0
	goto	start;

;SUBROUTINES SECTION

;1 SECOND DELAY
DELAY1	clrf	TMR0
LOOPA	movf	TMR0,W
	sublw	.32
	btfss	STATUS,ZEROBIT
	goto	LOOPA
	retlw	0

;0.5 SECOND DELAY
DELAYP5	clrf	TMR0
LOOPB	movf	TMR0,W
	sublw	.16
	btfss	STATUS,ZEROBIT
	goto	LOOPB
	retlw	0

;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00000010'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;program starts here
begin	bsf	PORTB,0
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		bcf PORTB,0;
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second
		call DELAY1; wait 1second	
		goto begin		
	end

At the end, Some codes keep repeating "call delay1" to have a delay for 1 second how can i increase the delay without repeating the same line again and again
 
uaefame said:
At the end, Some codes keep repeating "call delay1" to have a delay for 1 second how can i increase the delay without repeating the same line again and again
Make a longer delay. Have a look at the piclist delay generator.

The d1, d2, d3, d4 variables go in the cblock.

There are better ways, but I use it all the time. It's quick and easy, and I don't have to think too much about it.
 
Great way and i will thanks you all day.
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	COUNT
	endc

ZEROBIT	EQU	2

	org	0
	goto	start;

;SUBROUTINES SECTION

;1 SECOND DELAY
DELAY1	clrf	TMR0
LOOPA	movf	TMR0,W
	sublw	.32
	btfss	STATUS,ZEROBIT
	goto	LOOPA
	retlw	0

;0.5 SECOND DELAY
DELAYP5	clrf	TMR0
LOOPB	movf	TMR0,W
	sublw	.16
	btfss	STATUS,ZEROBIT
	goto	LOOPB
	retlw	0

; Delay = 60 seconds
; Clock frequency = 0.032 MHz

; Actual delay = 60 seconds = 480000 cycles
; Error = 0 %

	cblock
	d1
	d2
	d3
	endc

			;479995 cycles
	movlw	0xDA
	movwf	d1
	movlw	0x0C
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;5 cycles
	goto	$+1
	goto	$+1
	nop


;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00000010'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;program starts here
begin	bsf	PORTB,0
		bcf PORTB,0;
		goto begin		
	end

How can i call this delay, at the end of the program bcf PORTB,0; after it i want a delay of 60second
 
Dude, don't make a second cblock. Put the variables in the first one.
Like this:
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	COUNT,d1,d2,d3
	endc

ZEROBIT	EQU	2

	org	0
	goto	start;

Also, that second cblock you made has nothing to tell it where to place the variables. It probably assumes zero and kills three of your SFR's. This means instant crash, and the program does nothing. Look at the above code. See where it tells the assembler to put the cblock at 0x0c, which is the start of user RAM in the F84.

To call the delay, you have to put a label at the beginning of the delay routine and a return at the end. Then use
Code:
	call	delay
to call the subroutine.

The delay routine would look like
Code:
delay	movlw	0xDA
	movwf	d1
	movlw	0x0C
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0
	return
The delay generator will put the label and the return for you if you tell it to Generate Routine and tell it what label you want on your routine.
 
Last edited:
Thanks futz i learned in microcontroller today alot and you are giving me motivation to read and explore.

This will sound a bit hard but i will try to explain it into simple language. I am trying to send an output signal high RB0 for 1minute and in the same time another output high signal RB1for 1second.

Is this possible because RB0 i achieved it as shown below but for RB1?? no clue
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	COUNT,d1,d2,d3
	endc

ZEROBIT	EQU	2

	org	0
	goto	start;

;SUBROUTINES SECTION

;1 SECOND DELAY
DELAY1	clrf	TMR0
LOOPA	movf	TMR0,W
	sublw	.32
	btfss	STATUS,ZEROBIT
	goto	LOOPA
	retlw	0

;0.5 SECOND DELAY
DELAYP5	clrf	TMR0
LOOPB	movf	TMR0,W
	sublw	.16
	btfss	STATUS,ZEROBIT
	goto	LOOPB
	retlw	0

; Delay = 60 seconds
; Clock frequency = 0.032 MHz

; Actual delay = 60 seconds = 480000 cycles
; Error = 0 %
;479995 cycles
delay	movlw	0xDA
	movwf	d1
	movlw	0x0C
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0
	;5 cycles
	goto	$+1
	goto	$+1
	nop	
return
	
;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00000010'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;program starts here
begin	bsf	PORTB,0;
		call delay
		bcf PORTB,0;
		call delay 
		goto begin		
	end

I am trying to send at the same time different delay into different port.
 
uaefame said:
This will sound a bit hard but i will try to explain it into simple language. I am trying to send an output signal high RB0 for 1minute and in the same time another output high signal RB1for 1second.
Umm... Bonehead-simple method? Set both pins high
Code:
	bsf	PORTB,0
	nop
	bsf	PORTB,1
or
Code:
	movlw	0x03
	iorwf	PORTB,F
or if you don't care about what happens to the rest of the PORTB pins
Code:
	movlw	0x03
	movwf	PORTB
and delay 1 second. Clear RB1 (bcf PORTB,1) and delay for 59 seconds. Then clear RB0 (bcf PORTB,1) .

There are fancier, more elegant ways of doing that, but the above super-simple method gets the job done.
 
Last edited:
FUtz, Thanks alot for reading my post and giving me simple answer.
I am doing a traffic light 5second on red diode 2 second yellow diode and finally 5second on green diode.

Here is the codes for 16F84 pic i couldn't do it without FUtz he help me all the way through i am just curious how small this file can be, I mean did i add unneceassry thing in it. If you have a way to reduce the file size please let me know, If this file have silly mistake please let me know thanks

Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	COUNT,d1,d2,d3
	endc

ZEROBIT	EQU	2

	org	0
	goto	start;

;SUBROUTINES SECTION

;5second delay
delay5sec	movlw	0x3F
			movwf	d1
			movlw	0x20
			movwf	d2
Delay5sec_0
			decfsz	d1, f
			goto	$+2
			decfsz	d2, f
	goto	Delay5sec_0

	;2 cycles
	goto	$+1
	return
;2second delay
			
delay2sec	movlw	0x7F
			movwf	d1
			movlw	0x0D
			movwf	d2
Delay2sec_0
			decfsz	d1, f
			goto	$+2
			decfsz	d2, f
			goto	Delay2sec_0

			;2 cycles
	goto	$+1	
	return
;*********************
;CONFIGURATION SECTION

start
	banksel	TRISA		;bank 1
	movlw	B'00000010'
	movwf	TRISA
	movlw	B'00000000'
	movwf	TRISB
	movlw	B'00000111'
	movwf	OPTION_REG
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

;program starts here
begin	bsf	PORTB,0;
		call delay5sec
		bcf PORTB,0;
		bsf PORTB,1;
		call delay2sec
		bcf PORTB,0
		bcf PORTB,1
		bsf PORTB,2
		call delay5sec
		goto begin		
	end
 
uaefame said:
i am just curious how small this file can be, I mean did i add unneceassry thing in it. If you have a way to reduce the file size please let me know, If this file have silly mistake please let me know thanks
Yes, there are some silly mistakes, but they mostly aren't hurting anything. You're putting semicolons ( ; ) after your lines. That's not necessary. This isn't C. It doesn't hurt anything though. A semicolon tells the assembler that everything on that line after the semicolon is a comment. The assembler ignores comments.

I prefer to put my subroutines below the main program.

You're configuring OPTION_REG for no reason. You aren't using any of that stuff.

You had an unused variable and an unused equate. I removed them.

You forgot to turn off RB2 after the delay. Fixed.

You're not indenting consistently. Use Tabs instead of spaces, and keep things lined up neatly. Makes it much more readable. If it's clear and easy to read, it's easier to spot errors.

The nop's between pairs of bcf/bsf statements on the same SFR are to prevent possible Read/Modify/Write problems. The chip can be still working on the first one when the second one comes along too soon, and the first one gets wiped out.

Here it is cleaned up and rearranged to suit me.
Code:
	LIST	P=PIC16F84
	#INCLUDE "P16F84.INC"
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
	errorlevel -302

	cblock	0x0c
	d1,d2,d3
	endc

	org	0
init
	banksel	TRISA		;bank 1
	clrf	TRISA
	clrf	TRISB
	banksel	PORTB		;bank 0
	clrf	PORTB
main	bsf	PORTB,0
	call	delay5sec
	bcf	PORTB,0
	nop			;slight delay for possible RMW problem
	bsf	PORTB,1
	call	delay2sec
	bcf	PORTB,1
	nop			;slight delay for possible RMW problem
	bsf	PORTB,2
	call	delay5sec
	bcf	PORTB,2
	goto	main

delay5sec			;5second delay
	movlw	0x3F
	movwf	d1
	movlw	0x20
	movwf	d2
Delay5sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay5sec_0
	return
			
delay2sec			;2second delay
	movlw	0x7F
	movwf	d1
	movlw	0x0D
	movwf	d2
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay2sec_0
	return

	end
 
Last edited:
Oh, I bet I know what your indenting problem is. At least some of it, that is. MPLAB is set by default for 4 space tabs. This site expects 8 space tabs.

In MPLAB go to Edit/Properties and click on the "ASM' File Types tab at the top of the box that pops up. At the bottom, change Tab Size: to 8. Leave Keep Tabs selected. Click OK.

4 space tabs are better for C but not so good for assembler.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…