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.

PIC16F84a

Status
Not open for further replies.

uaefame

New Member
Hello Everyone,

I decided from now on to learn PIC, I mean to understand why my program getting error and how can i improve it.

Here are my codes
Code:
    list      p=16F84A             ; list directive to define processor
    #include <p16F84a.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

STATUS	equ 03h
TRISA	equ 85h
PORTA	equ 05h

		bsf		STATUS,5
		movlw	OOh
		movwf	TRISA
		bcf		STATUS,5

START	movlw	02h
		movwf	PORTA
		movlw	00h
		movwf	PORTA
		goto	START

        END

I know its simple, but i am interested where did i make the mistake and how can i fix it.

Thanks in advance

Best regards,
Hesham Ismail
 
Last edited:
Unnecessary. These are already all defined in the file you included in the line "#include <P16F84A.INC>".
Code:
STATUS	equ 03h
TRISA	equ 85h
PORTA	equ 05h


Here you've typed in the letter O rather than the numeral 0 (zero). :p A rather silly mistake. :D
Code:
	movlw	OOh


And if you meant to clear TRISA, why not just use "clrf TRISA"?
Code:
	movwf	TRISA


If you're trying to blink an LED on RA2, you really should put a delay in there. This will just turn on the LED at about half intensity (50% duty cycle) and leave it on (as far as any human can tell, anyway). Sure it's blinking, but so fast that no human could ever see it.
Code:
START	movlw	02h
	movwf	PORTA
	movlw	00h
	movwf	PORTA
	goto	START

	END
 
Last edited:
Thanks futz,
can you show me the codes while using clrf TRISA and can you explain to me what clrf mean?

I am learning about delay now I will do my best to learn now. Wish me good luck.

Best regards,
Hesham Ismail
 
can you show me the codes while using clrf TRISA and can you explain to me what clrf mean?
Look in your datasheet in Section 7.0 on Page 38.
bleh.jpg
All the opcodes are listed and described in that section.
 
Hello everyone

What is the different between BTFSS & BTFSC?

I started learning PIC from this website:
1-**broken link removed**

But it seem confusing a bit for me?

Do you know another Good PIC website? I mean for beginner like me?

Thanks in advance
 
What is the different between BTFSS & BTFSC?

BTFSS tests the specified bit and skips the next instruction if it is one (set).
BTFSC tests the specified bit and skips the next instruction if it is zero (clear).

edit: posted at the same time!
 
Last edited:
Hello again,

I build a circuit shown in the attachment.

I am trying to turn led on and off every 2 second here are the codes.

Code:
    list      p=16F84A             ; list directive to define processor
    #include <p16F84a.inc>         ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC


	cblock
	d1
	d2
	d3
	endc

		bsf		STATUS,5
		movlw	00h
		movwf	TRISA
		bcf		STATUS,5

START	movlw	02h
		movwf	PORTA
		call 	Delay2sec
		movlw	00h
		movwf	PORTA
		call 	Delay2sec
		goto	START


Delay2sec
			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay2sec_0

			;4 cycles (including call)
	return
	END

The problem nothing light ups can u suggest to me what is going wrong?

Btw i am using 4MHz clock.

When I build it no error mentioned when i try it out nothing happened?

Thanks in addvance
 

Attachments

  • Pic16f84a.JPG
    Pic16f84a.JPG
    51.9 KB · Views: 225
Can you explain more?

cblock address? I don't know what this mean?

Actually i am using this website to generate delay

Delay Generator

You mean i add these codes

cblock 0x0c
d1,d2,d3
endc

Thanks in advance
 
Last edited:
Can you explain more?

cblock address?

You mean i add these codes

Code:
	cblock	0x0c
	d1,d2,d3
	endc
Yes. You have to tell cblock where to put those variables.

If you don't put any address I assume the assembler would put the cblock at 0x00. That wipes out your first three SFRs, which are INDF, TMR0 and PCL. You aren't using the first two, so no problem. But wiping out PCL is a HUGE problem. Your program crashes instantly.
 
Why count is
equ to 08h its not a general purpose registor!!!

You are correct, the first general purpose reg is 0x0C [ 0Ch]
 

Attachments

  • esp03 Oct. 23.gif
    esp03 Oct. 23.gif
    17.2 KB · Views: 193
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top