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.

Basic 16F84

Status
Not open for further replies.
THanks futz again, I am trying to simulate the .asm file but underneath its written 20Mhz, and i am only using 32khz i program my delay according to 32Khz and i have 32Khz crystal. Any clue how to change 20Mhz to 32Khz so i can simulate the program.

Thank in advance
 
I change the frequency to 32Khz. here is my codes
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

How can i test real time using simulator. I am using 32Khz crystal and i change the setting under debugger to 32khz.
 
Q1> Is there different between pic 16F84 and Pic 16F84A?
Q2> How can u know if there is a different or not?
 
hey what is mean by
movlw 0xDA
goto $+2
movlw 0x0C

movlw 0xDA moves hexadecimal DA into the working register.
On an 8 bit pic just about all data movements are done by moving stuff into the working register.

goto $+2 jumps two lines forward. It skips the following line

movlw 0x0C moves hexadecimal 0C into the working register. Unless there is a goto that goes to this line, the goto $+2 will mean that this line never gets used.
 
Hi
Q> what does this program do ?
I am using 4Mhz oscilator
Code:
LIST	P=PIC16F84A
	#INCLUDE "P16F84A.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	Delay1sec
	bcf	PORTB,0
	call    Delay1sec
	goto	main

Delay1sec
			;999990 cycles
	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
Delay1sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay1sec_0

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return


	end
 
When i build this program it built successfully. Then, i programmed it into a 16F84a but when i place an led in RB0 with correct resistor nothing happen!

I am trouble shooting my circuit

Q>how i know if the crystal i bought 4MHz is working or not?
 
Last edited:
Q>how i know if the crystal i bought 4MHz is working or not?
It would appear that you have the wrong oscillator type selected in your __CONFIG line. A 4MHz crystal should have XT selected, not LP. Your config line
Code:
	__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC
should read:
Code:
	__CONFIG _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC

The program can't get much simpler. If the LED is wired correctly, the MCU has 5V power and ground connected and your MCLR pin is pulled high with a 10K to 33K resistor then it has to work.

**broken link removed** you can have a look at to compare with how yours is set up.

Your crystal needs two (typically) 22pF loading capacitors to work properly. Wire them like this (not a 16F84, but same idea):
bleh.jpg
 
I change the codes you suggested still not working.

I will post the schematic that i am following
 

Attachments

  • LEDwith16F84a.JPG
    LEDwith16F84a.JPG
    82.8 KB · Views: 264
I will post the schematic that i am following
There's the problem. Like I said previously, MCLR must be pulled high with a resistor. Your schematic shows it pulled low. When MCLR is held low the PIC is in RESET, and halted. No program runs with MCLR pulled low like that.
 
Last edited:
Q> What you mean by pulled high and pulled low and when do i use pulled high or pulled low?
 
Wow it worked i connected MCLR to 5V and it worked i guess that was the problem.
Thanks futz for giving me guide :)
 
  • Like
Reactions: 3v0
A pull up or pull down resistor is used to create a default value or state for a signal. Now you have MCLR wired to +5V. If you connect an ICSP it will not work because the signal is stuck at +5V. If you were to put a 10K or 20K resistor between MCLR and +5V then MCLR would be +5V when no other signal was present. But because of the resistor a signal from an ICSP connector could change the value to VPP or GND as needed.

A pull down works the same way but the default become GND.

Most often the an input will have a pullup or pulldown and one or more other signals that will be tristated (turned off or made an input) when not in use.

HTH
 
Last edited:
Q> What you mean by pulled high and pulled low and when do i use pulled high or pulled low?
In case you didn't understand 3v0's pullup/pulldown explanation I found another on the interweb.

And, like 3v0 says, don't connect MCLR directly to VDD. Use a pullup resistor between the MCLR pin and VDD. 22K or 33K are good, but it isn't critical. Anything from 10K to 33K is fine.
 
And, like 3v0 says, don't connect MCLR directly to VDD. Use a pullup resistor between the MCLR pin and VDD.

This is really just personal choice, PIC's are designed for a direct MCLR connection if you wish, but obviously it prevents ICSP - if you don't use ICSP, then you don't need a resistor - if you do use ICSP, then you need a resistor and a diode.
 
This is really just personal choice, PIC's are designed for a direct MCLR connection if you wish, but obviously it prevents ICSP - if you don't use ICSP, then you don't need a resistor - if you do use ICSP, then you need a resistor and a diode.

I was under this assumption as well but it seems that later pics shouldn't have MCLR connected direct to Vdd.

From the 16F876A data sheet,
The behavior of the ESD protection on the MCLR pin
differs from previous devices of this family. Voltages
applied to the pin that exceed its specification can
result in both Resets and current consumption outside
of device specification during the Reset event. For this
reason, Microchip recommends that the MCLR pin no
longer be tied directly to VDD. The use of an RCR
network, as shown in Figure 14-5, is suggested.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top