Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Do help me analyze this program in PIC16F84A,,

Status
Not open for further replies.
delay program

-Sorry I misunderstood about the variables declaring.

-I did try to run my first post of the codes but its wrong..

-What should I do?

I uploaded the .hex file I compiled from the original code that was in your first post (if you want to save it, change the extension from .txt to .hex) and it simulates in MPLAB IDE without any problems for me.

And just so it doesn't confuse you, the code will be functionally identical if you remove the
Code:
org 0X000
goto Init

org 0X004
retfie
from the beginning.
 
Try this:
Code:
	list p=16F84A
	#include <p16F84A.inc>

	errorlevel  -302              ; suppress message 302 from list file (Bank bits warning message)

	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

d1 equ 0x0D
d2 equ 0x0E
d3 equ 0x0F
d4 equ 0x10

	org 0X000
	goto Init

	org 0X004
	retfie


Init
	bsf STATUS,RP0
	clrf TRISB
	clrf TRISA
	bcf STATUS,RP0

	clrf PORTA
	clrf PORTB

Main 
	bsf PORTB,0
	call Del5M
	bcf PORTB,0
	call Del5M
	goto Main

Del5M 
	movlw 0x54
	movwf d1
	movlw 0xA1
	movwf d2
	movlw 0xFD
	movwf d3
	movlw 0x02
	movwf d4
Delay_0
	decfsz d1, f
	goto $+2
	decfsz d2, f
	goto $+2
	decfsz d3, f
	goto $+2
	decfsz d4, f
	goto Delay_0

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

	end
 
delay program

-I did try to run these codes (the one you sent me a while ago) but it failed to build. these are the error messages:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "lumayk.asm" /l"lumayk.lst" /e"lumayk.err" /c-
Warning[205] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 1 : Found directive in column 1. (LIST)
Error[173] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 62 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM)
Halting build on first failure as requested.
BUILD FAILED: Mon Sep 01 00:24:49 2008

Try this:
Code:
	list p=16F84A
	#include <p16F84A.inc>

	errorlevel  -302              ; suppress message 302 from list file (Bank bits warning message)

	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

d1 equ 0x0D
d2 equ 0x0E
d3 equ 0x0F
d4 equ 0x10

	org 0X000
	goto Init

	org 0X004
	retfie


Init
	bsf STATUS,RP0
	clrf TRISB
	clrf TRISA
	bcf STATUS,RP0

	clrf PORTA
	clrf PORTB

Main 
	bsf PORTB,0
	call Del5M
	bcf PORTB,0
	call Del5M
	goto Main

Del5M 
	movlw 0x54
	movwf d1
	movlw 0xA1
	movwf d2
	movlw 0xFD
	movwf d3
	movlw 0x02
	movwf d4
Delay_0
	decfsz d1, f
	goto $+2
	decfsz d2, f
	goto $+2
	decfsz d3, f
	goto $+2
	decfsz d4, f
	goto Delay_0

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

	end
 
-I did try to run these codes (the one you sent me a while ago) but it failed to build. these are the error messages:

Code:
Warning[205] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 1 : Found directive in column 1. (LIST)
Put a tab or some spaces before the LIST directive.

Code:
Error[173]   C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 62 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM)
Your source file and/or project is buried too deep in the hard drive's directory heirarchy. MPLAB only allows 62 characters in a file path. Build a new project directory closer to root, or just shorten directory and file names till it fits.
 
Last edited:
62 characters in a file path

-I have already deleted on what has been saved that maybe have causes the error.
-Still no improvement.. maybe theres something wrong with the codes?


Code:
Warning[205] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 1 : Found directive in column 1. (LIST)
Put a tab or some spaces before the LIST directive.

Code:
Error[173]   C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM 62 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYK.ASM)
Your source file and/or project is buried too deep in the hard drive's directory heirarchy. MPLAB only allows 62 characters in a file path. Build a new project directory closer to root, or just shorten directory and file names till it fits.
 
-I have already deleted on what has been saved that maybe have causes the error.
-Still no improvement.. maybe theres something wrong with the codes?
That source file looks fine to me. I didn't try to assemble it or look at it in any great detail though. What errors and warnings - exactly - are you getting now?

It's also possible that you have set up your project incorrectly.
 
Last edited:
built failed

-Still the same:
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84A "lumaydelay.asm" /l"lumaydelay.lst" /e"lumaydelay.err" /c-
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 23 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 24 : Register in operand not in bank 0. Ensure that bank bits are correct.
Error[173] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 82 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM)
Halting build on first failure as requested.
BUILD FAILED: Mon Sep 01 01:40:23 2008

-Maybe its about the: Register in operand not in bank 0. But I don't kow much about shifting banks.

That source file looks fine to me. I didn't try to assemble it or look at it in any great detail though. What errors and warnings - exactly - are you getting now?

It's also possible that you have set up your project incorrectly.
 
-Still the same:
Those first two warnings are not the same.

Code:
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 23 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 24 : Register in operand not in bank 0.  Ensure that bank bits are correct.
These warnings are to remind you to do your bank changes. They appear even if you have done the proper bank selects. They are not errors.

Code:
Error[173]   C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 82 : Source file path exceeds 62 characters
You still haven't done what I said previously. Shorten up the path to your project/source file. Do whatever it takes. Put it in the root directory if necessary. It isn't - I do it every day - mine are three levels down from root.

Do you understand computer file and directory heirarchy? I run across a lot of people who only use Windoze's stupid pretty pictures (icons) and have no clue how the underlying directory structure works. Maybe that's why you're not understanding this? You're allowed 62 characters for your full file path. No more!

That's your only error. Fix it and you're in business.

-Maybe its about the: Register in operand not in bank 0. But I don't kow much about shifting banks.
No. That wouldn't prevent assembly of the program.

Use the banksel directive to switch banks. Here's a simple example:
Code:
	org	0x0000
init
	banksel OSCCON			;bank 1
	movlw	b'01110000'		;set 8MHz osc
	movwf	OSCCON
	clrf	TRISB
	banksel	PORTA			;bank 0

main	bsf	PORTB,0
	call	delay
	bcf	PORTB,0
You can't put a banksel in a line with a label on it (see the init label), as it's a directive (basically a macro), and not an actual instruction. No problem - just put it on the line after the label like I did above.

Just use banksel with the SFR that you plan to use next. Or memorize which ones do what (you only need to know two or three for most things) and use them that way. As you can see in the above source, I used "banksel PORTA", but I don't use PORTA. I use PORTB. Doesn't matter. They're both in bank 0.
 
Last edited:
simulator

-Yes I have done what you said,, and its right. My simulator was inside a folder and I took it out.

-I have able to load it too. The problem now is that when I put in the hardware no light has been produce. If ever that no light will be produce for the first five minutes. its not it is. I have waited more than five minutes, still the LED did not lit.

-In the hardware I have made the circuit for crystal. I don't know if its the crystal or the program that is wrong.

-the circuit for 4MHz crystal I made goes like this: one pin of the crystal is connected to the 16th pin of the PIC, the other pin on the 15th. also connected to each of the legs of the crystal is the 30 pf capacitor. the other leg of the capacitor to the ground. there are two capacitors in here. for referrence see this site: http://www.sapteka.net/pic16f84testing.htm

Those first two warnings are not the same.

Code:
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 23 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Message[302] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 24 : Register in operand not in bank 0.  Ensure that bank bits are correct.
These warnings are to remind you to do your bank changes. They appear even if you have done the proper bank selects. They are not errors.

Code:
Error[173]   C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\CODE\LUMAYDELAY.ASM 82 : Source file path exceeds 62 characters
You still haven't done what I said previously. Shorten up the path to your project/source file. Do whatever it takes. Put it in the root directory if necessary. It isn't - I do it every day - mine are three levels down from root.

Do you understand computer file and directory heirarchy? I run across a lot of people who only use Windoze's stupid pretty pictures (icons) and have no clue how the underlying directory structure works. Maybe that's why you're not understanding this? You're allowed 62 characters for your full file path. No more!

That's your only error. Fix it and you're in business.


No. That wouldn't prevent assembly of the program.

Use the banksel directive to switch banks. Here's a simple example:
Code:
	org	0x0000
init
	banksel OSCCON			;bank 1
	movlw	b'01110000'		;set 8MHz osc
	movwf	OSCCON
	clrf	TRISB
	banksel	PORTA			;bank 0

main	bsf	PORTB,0
	call	delay
	bcf	PORTB,0
You can't put a banksel in a line with a label on it (see the init label), as it's a directive, and not an actual instruction. No problem - just put it on the line after the label like I did above.

Just use banksel and the SFR that you plan to use next. Or memorize which ones do what (you only need to know two for most things) and use them that way. As you can see in the above source, I used "banksel PORTA", but I don't use PORTA. I use PORTB. Doesn't matter. They're both in bank 0.
 
No, bad Janethx. You have to take the SOURCE FILE (ends with .asm) and put it in a baser directory. For example, I compile programs from a folder I made in the topmost layer of the directory structure (C: ), so the files I assemble are in C:\MPASM\, significantly less than 62 characters.

And the oscillation circuit you describe is exactly what it's supposed to be.
 
Last edited:
16F88's are easy to get... :)
And I believe the code would transfer without change.

As is the 16F628(A) which was the replacement for the 16F84 last century, when it was declared obselete. Very slight code changes are required, but it is only slight - there used to be a 16F84/16F628 migration document at MicroChip, but they appear to have removed it, and released the F84 again (at silly prices).
 
The problem now is that when I put in the hardware no light has been produce. If ever that no light will be produce for the first five minutes. its not it is. I have waited more than five minutes, still the LED did not lit.
Sounds like there's a problem with your circuit, or you don't know how to "Release From Reset" in MPLAB, so the chip will actually run. Or maybe you don't have a pullup resistor (10K to 33K is fine) on your MCLR pin?

Just for my own entertainment, I breadboarded one and tested it. Works fine with kchriste's code (with some very minor alterations to suit me). Five minutes on the nose.

The LED should turn on when the PIC gets power and comes out of reset. It should stay lit for five minutes and then turn off for five minutes.

Here's a couple pics of the circuit. Those are 22pF caps on the crystal:

**broken link removed**

**broken link removed**

And here's the code again:
Code:
	list p=16F84A
	#include <p16F84A.inc>
	errorlevel  -302
	__CONFIG _WDT_OFF & _XT_OSC

	cblock 0x0c
	d1,d2,d3,d4
	endc

	org	0x000
init
	banksel	TRISA		;bank 1
	clrf	TRISA
	clrf	TRISB
	banksel	PORTA		;bank 0
	clrf	PORTA
	clrf	PORTB

main	bsf	PORTB,0
	call	Del5M
	bcf	PORTB,0
	call	Del5M
	goto	main

Del5M	movlw	0x54
	movwf	d1
	movlw	0xa1
	movwf	d2
	movlw	0xfd
	movwf	d3
	movlw	0x02
	movwf	d4
Del5M_0	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	Del5M_0
	nop
	return

	end
 
Last edited:
Neat setup Futz, using Pickit2 in-circuit programmer and plugin power supply. I have to test my program in circuit next, I'm nervous about it... my first circuit.
 
Neat setup Futz, using Pickit2 in-circuit programmer and plugin power supply. I have to test my program in circuit next, I'm nervous about it... my first circuit.

Everyone has to build that first circuit, it's really not that bad. If your really nervous about it then post a picture here first, I'm sure there will be lot's of posters scrutinising it for mistakes. You can therefore be pretty sure there's no serious errors about 3 minutes after posting it.:D

Mike.
 
Neat setup Futz, using Pickit2 in-circuit programmer and plugin power supply. I have to test my program in circuit next, I'm nervous about it... my first circuit.
The power supply isn't plugged in. It's only serving as a "couple wires" to connect the power rails on both sides of the breadboard.

And I didn't have a 16F84A. Only a 16F84. The PICkit 2 won't program the 84 (84A only), so I used my Inchworm+/Unicorn (USB ICD2).

When I first built it I couldn't find my 4MHz crystal, so I jammed in a 18.4MHz. It would flash the LED once and then quit. I scratched my head for a while, tried a 20MHz. The 20MHz wouldn't work at all. Hmm... :p Looked at the datasheet and remembered that 16F84 is only rated for 10MHz. PICs overclock good, but not that good. :D
 
Last edited:
Everyone has to build that first circuit, it's really not that bad. If your really nervous about it then post a picture here first, I'm sure there will be lot's of posters scrutinising it for mistakes. You can therefore be pretty sure there's no serious errors about 3 minutes after posting it.:D

Mike.

Yes I do have a breadboard to prototype the circuit with LEDs. I'm mostly worried about the EEPROM functionning right. When I sim or debug I could not get the EEPROM to keep the value when I unplugged the chip and replugged it. But he said it worked for him, so I'll try it like that. with any luck it will work fine. The rest of the circuit is fairly simple, I'll post a picture when I have it.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top