Creating a Blinking LED with PIC 16F84A and 32K Crystal

  • Thread starter thankz
  • Start date
In summary: W register. The third line will move the W register to the TRISA register. As we said, this register is 8-bit. So, it will remain in this position for just one instruction. The same thing will happen with the next line, but this time the W register will be loaded with the value '11110000' (b'11110000'). Then, this value will be moved to the TRISB register. Now, the TRISA register will have its 8th bit set to 1 (the LSB) and the TRISB register will have its first 4 bits set to 1. The remaining 4 bits of the TRISB
  • #1
thankz
265
40
tell me if this code is right to make my pic 16f84a blink, I'm using a 32k crystal on pins 16 and 15 with two 68pf caps to ground, a 470ohm resistor connected to a led (connected to ground) on pin 6, pin 14,4 and 3 are connected to vcc which is 5 volts, pin 5 is connected to ground.

I,m using a 7805 connected to a 9v battery with two bypass caps, all my voltages measure right on the breadboard.

here is the code:



;EQUATES SECTION
TMR0 EQU 1
STATUS EQU 3
PORTA EQU 5
PORTB EQU 6
ZEROBIT EQU 2
COUNT EQU 0CH

LIST P=16F84
ORG 0
GOTO START

;SUBROUTINE 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 BSF STATUS,5

MOVLW B'00011111'
TRIS PORTA

MOVLW B'00000000'
TRIS PORTB

MOVLW B'00000111'
OPTION

BCF STATUS,5
CLRF PORTA
CLRF PORTB

BEGIN BSF PORTB,0
CALL DELAYP5
BCF PORTB,0
CALL DELAYP5
GOTO BEGIN


END

the code assembles in mplab and programs correctly on the programmer, I don't know what the problem is?
 
Engineering news on Phys.org
  • #2
I see no obvious reason. You may need to experiment.

Write absolutely minimum code to test the minimum hardware at one time. For example, enable the LED port as output, turn on the LED. Is the LED now on? Edit the code to turn off the LED, is the LED now off?

Cut away everything unnecessary, for example, delete the calls to the two delay subroutines. That will give you a high frequency square wave on the LED. Is the LED then off, on or half way between.

You need to write code correctly the first time. That requires great discipline and slow initial progress. Beginners often have trouble with microcontrollers because they try to advance too quickly with untested code.

Is TRIS a macro for MOVWF ?
 
Last edited:
  • #3
You don't state how you are programming the part. I recall that different programmers allow for the configuration bits to be set - not to be confused with the program. You need to make sure the configuration bits are set to use your clock/crystal setup. As was suggested, the most basic program should be your beginning program. It will help you vastly to have access to either a scope or a digital logic probe, something that can tell you if a logic level is on/off/changing. The logic probe I have had for 30+ years can detect pulses on the order of 30nS and show the signal is toggling. However, a scope is a much more useful tool. The first scope I purchased was many many years ago for around $50. Many old scopes, CRT type are available at a very low cost at local ham meets or craigs list, etc. A scope will be a very useful tool on a bench. For a few dollars more, many low frequency USB scope pods allow you to use your computer as a scope.

Pics are great, and most of the learning on programming them is experience. But once you progress to a point to turn on or use interrupts, you will find you need more tools to help determine what is working. Microchip's ICE units which let you debug your code on the device are very useful. These items do cost a little money, but they will save you hours and the premature loss of hair.

That being said, if you have access to anything that can detect a fast pulse train; differentiate it from constant logic high or low, the first program should change an output high then low and jump back to start. Once you see that that is working correctly, you know it is programming and starting your program correctly and you can move forward.
 
Last edited:
  • #4
no tris is not a macro for movwf here is some info I got off the web about it.Setting the type of the port pins (Input or Output) - The TRIS register
--------------------------------------------------------------------------------

Before you start playing with the port pins, you should declare their type. Each one can be Input or Output. There is also an analog state, but this will discussed on the advanced section. On power on of the PIC or after a reset, all ports become inputs. This is done to avoid driving an output pin directly to the VDD or VSS. To define the type of an I/O pin, you use the TRIS register. There are two TRIS registers, the TRISA and the TRISB that corresponds to the 8 pins of each port set, the A and the B. The TRIS registers are 8-bit registers. The LSB (Less significant byte) corresponds to pin #0 and the MSB (Most significant byte) to the pin #7. When one bit of this register is set to '1', the corresponding port pin shall become an input. When it is set to '0', then this port pin shall become an output. Let's see an example:

bank1
movlw b'00000001'
movwf TRISA

movlw b'11110000'
movwf TRISB
bank0
What someone would notice at the very first are the bank1 and bank0 macros. The TRIS registers are located in the bank 1. On the other hand, the PORT registers are located in the bank 0. I have experience many hours of hard mind-crashing debugging on my non-working programs, simply because i forgot to switch to bank 1 when setting the TRIS registers or because i forgot to switch back to bank 0. Once more, the bank 0 is the position with the most common registers. This is good because it saves you from switching between bank positions. But if you forger to check a register's bank position and fail to change bank, then funny results will happen

The above code, will run as follows: The first line will switch to bank 1. The second line will load the binary number '00000001' into the W register. The third line will write the contents of the W register (00000001) into the TRISA register. This will set the type of port pins for the RA as follows:

PIN # RA# PIN TYPE
17 RA0 INPUT
18 RA1 OUTPUT
1 RA2 OUTPUT
2 RA3 OUTPUT
3 RA4 OUTPUT
4 RA5 OUTPUT
15 RA6 OUTPUT
16 RA7 OUTPUT The LSB bit of the number that was written into the TRISA register was '1', that is why the RA0 pin has become an INPUT. On the contrary, all other bits are '0', therefore, all other RA pins are outputs.

Before you see the following table, try to imagine what will happen to the RB port pins. According to the program, the byte '11110000' was written in the TRISB register:

PIN # RB# PIN TYPE
6 RB0 OUTPUT
7 RB1 OUTPUT
8 RB2 OUTPUT
9 RB3 OUTPUT
10 RB4 INPUT
11 RB5 INPUT
12 RB6 INPUT
13 RB7 INPUT The first four bits are '0', therefore the pins RB0 through RB3 shall become OUTPUTS. The other four bits are '1' therefore the pins RB4 through RB7 are inputs.
***************************************************************************************

I took your advice and tried to make the code shorter ,here is the code I'm using to try and make the led come on:

;---------------------------------------------------------------------
; FILE: helloLed.asm
; AUTH: P.Oh
; DATE: 1.0 - 04/13/02 15:09
; DESC: 1.0 - Makes B0,B2,B4,B6 LO and B1,B3,B5,B7 HI
; NOTE: Tested on PIC16F84-04/P.
; Page numbers in code are in Easy Pic'n book
; REFs: Easy Pic'n p. 23 (Predko p. 173 is bogus?)
;----------------------------------------------------------------------
list p=16F84
radix hex

;----------------------------------------------------------------------
; cpu equates (memory map)
myPortB equ 0x06 ; (p. 10 defines port address)
;----------------------------------------------------------------------

org 0x000

start movlw 0x00 ;load W with 0x00 make port B output (p. 45)
tris myPortB ;copy W tristate, port B outputs (p. 58)

movlw b'10101010' ; load W with bit pattern (p. 45)
movwf myPortB ;load myPortB with contents of W (p. 45)

circle goto circle ; done

end

;----------------------------------------------------------------------
; at blast time, select:
; memory uprotected
; watchdog timer disabled
; standard crystal (4 MHz)
; power-up timer on
;--------------------------------------------------------------------- still no luck, I'm using multiple chips so I know they airn't broke, ?
 
  • #5
to mjhilger, I got a scope I'm getting nothing on the output and have turned the watchdog timer off, set for rc and xt, have the power timer on and code protect off. here are some screen shots:
 

Attachments

  • 1.jpg
    1.jpg
    37.2 KB · Views: 385
  • 2.jpg
    2.jpg
    76.9 KB · Views: 344
  • #6
configuration bits cannot have RC & XT selection at the same time. 2 bits define 4 different Clocking selection, determine if you are trying to use the RC or the XT as the clock and check the bits or set the _config accordingly. If you are not sure which you need, you should download the user guide and read the section regarding the config bits and what the clock input implies. Its been a while since I have used that particular part, but the RC uses the internal

And yes you need to program the tristate buffers in the output mode for the pin you are trying to toggle. Use the scope and make sure your osc lines are oscillating. For your 32KHz crystal you should use the LP setting.
 
  • #7
I figured it out, I was setting the fuses in mplab and not the programmer itself.

you were close, thanks for all the help!
 
  • #8
heres a pic lol :-p
 

Attachments

  • pic.jpg
    pic.jpg
    30.7 KB · Views: 360
  • #9
The thing that drew my attention to TRIS was these two lines in your source. I guessed that TRIS was now part of the assembler.

MOVLW B'00011111'
TRIS PORTA

MOVLW B'00000000'
TRIS PORTB

Anyhow,,,, coding the way you are now will only allow the PIC16x84 do one thing at the time. Here is some minimum code that allows interrupts and multitasking. It has a real time interrupt and can check if a task is due to run. You can write a couple of routines, one to turn the LED on and initiate the time to turn it off, and another to turn it off and initiate the time to turn it on. They will play ping-pong in the background while your foreground code runs in available time. It is small and fast with only a few dozen actual instructions generated.

This was written to make project development faster and more reliable for beginners. There is enough embedded documentation and example code, so you can paste in your code. You may need to change the chip type assembler directives from C to F version, and flip? the protection fuse setting bit.
Code:
;============================================================================================
	title "proto.ASM file for use with PIC16C84"
;	Created by VK7ZID in October 1997 -  April 2000
;
; Assemble with    " <path>\mpasm.exe /C- /E- /P16c84 /X-  <path>\filename.asm "
;
;============================================================================================

;--------------------------------------------------------------------------------------------
; Assembler directives and defaults
;--------------------------------------------------------------------------------------------
	; b=8 column tab size for output listing
	; r=dec, change numeric radix to decimal for output listing
	; n=0, set zero lines per page to prevent page headers in listing
	list b=8, r=dec, n=0	; output listing only
	radix	dec			; decimal is now default input radix
	processor	pic16c84	; Processor type is an assembler directive
;
;--------------------------------------------------------------------------------------------
; Configuration Register Fuse Bits
;--------------------------------------------------------------------------------------------
	; Top 9 bits are not used, they read as all ones, writing as all zeros is OK
	; Foscillator     0 = LP,    1 = XT,    2 = HS,    3 = RC
	; Watchdog timer	Disable = 0	Enable = 4
	; Power up timer	Disable = 0	Enable = 8
	; Code	Protected = 0	Unprotected = 16	( reversed in the Pic16F84 ? )
	__config	16+8+0+1		; yes, it is a ( double underscore config )
	; turns CodeProtect off, PowerUpTimer on, watchdog off, select xtal oscillator mode
;
;--------------------------------------------------------------------------------------------
; Memory Bounds	( again use the double underscore )
;--------------------------------------------------------------------------------------------
	__maxram	h'2F'	; highest register file address used in pic16c84
	__badram	h'07'	; register 7 does not exist
;
;--------------------------------------------------------------------------------------------
; Definitions and the naming of bits and registers goes in here
;--------------------------------------------------------------------------------------------
	#define	w	0	; destination is W reg if dest = 0
	#define	f	1	; destination is RegisterFile if dest = 1
	#define	c	0	; Carry flag is status bit zero
	#define	dc	1	; Digit Carry flag is status bit one
	#define	z	2	; Zero flag is status bit two
;
	cblock	0	; Bank 0 special register file names
	indf, tmr0, pcl, status, fsr, porta, portb, undef, eedata, eeaddr, pclath, intcon
	endc
;
	cblock	0	; Bank 1 special register file names
	indf, optreg , pcl, status, fsr, trisa, trisb, undef, eecon1, eecon2, pclath, intcon
	endc
;
;============================================================================================
; Macro code for later use goes in here
;============================================================================================
bank0	macro
		bcf	status,5	; clear bit 5 in status reg to select bank zero
	endm
;
;--------------------------------------------------------------------------------------------
bank1	macro
		bsf	status,5	; set bit 5 in status reg to select bank one 
	endm
;
;--------------------------------------------------------------------------------------------
skipz	macro
		btfss	status,z	; test and skip if zero
	endm
;
;--------------------------------------------------------------------------------------------
skipnz	macro
		btfsc	status,z	; test and skip if non-zero
	endm
;
;--------------------------------------------------------------------------------------------
skipc	macro
		btfss	status,c	; test and skip if carry is set
	endm
;
;--------------------------------------------------------------------------------------------
skipnc	macro
		btfsc	status,c	; test and skip if no carry
	endm
;
;--------------------------------------------------------------------------------------------
; Variables are stored in the register file, starting at location  0C hex
;--------------------------------------------------------------------------------------------
	; Your user variables follow, along with those needed for included routines
	cblock	0CH	; start of 36 available bytes of ram in register file 
		; uservar1		; users variables here please
	endc			; note that a total of only 36 bytes of ram are available
	; don't forget to initialise critical variables before enabling interupts
;
;============================================================================================
; Power up code starts here following reset of chip
;============================================================================================

	org	0	; Reset vector
			; note, three spare instruction locations available here
	goto	startup
;
;--------------------------------------------------------------------------------------------
; Main interrupt handling code goes here, save the status and w registers
;--------------------------------------------------------------------------------------------
	cblock		; assign variables to next place in register file
		temp_wreg	; used during interupts to protect w register
		temp_stat	; used during interupts to protect status register
	endc
	org	4		; Interupt Vector
	movwf	temp_wreg	; save w reg to temporary 
	swapf	status,w	; nibble swap status into w reg
	movwf	temp_stat	; save status to temporary
;		
;--------------------------------------------------------------------------------------------
; Identify source of interrupt as T0_ovflo, INTPIN or RBdelta
;--------------------------------------------------------------------------------------------
	btfss	intcon,2	; test if T0 overflowed flag is set
	goto	intpin	; no, so go and test external intpin flag
				; flag was set so handle real time interupt
;		
;--------------------------------------------------------------------------------------------
; Real time clock interrupt and task scheduling is handled here
;--------------------------------------------------------------------------------------------
	; Ignore the reload of tmr0 if you do not need a specific interrupt rate
	; as tmr0 will just roll over and continue to generate an interrupt each roll
	; select the best interrupt rate with the option register prescaler value
	; this code is commented out because it is not normally needed
	; first reload tmr0 with next tick period if needed, it counts up
	; DataToLoad = 255 - ((OscHz / (4 * PreScale * IntRateHz )) - 12)	?
	; bank0		; tmr0 is in bank0
	; movlw	255	; DataToLoad
	; movwf	tmr0	; loads tmr0 and resets the prescaler to zero
	; warning, loading tmr0 may not be reliable if other interupts are also enabled
	; note that the prescaler is also reset to zero when tmr0 is loaded
;
;--------------------------------------------------------------------------------------------
; this chain of tasks is executed every time an interrupt is generated by a tmr0 overflow
;--------------------------------------------------------------------------------------------
task_1	; Your multi-line action block for task_1 goes in here
;
task_2	; Your multi-line action block for task_2 goes in here
		; etc
;
;--------------------------------------------------------------------------------------------
; schedules are executed after the delay count reaches zero
; if counter is zero then execution of that schedule is skipped and left at zero
; delete or replicate the schedule code as you need it, change labels if you replicate it
;--------------------------------------------------------------------------------------------
; first example is an 8 bit down-counter, max delay 255 interupts	( about 2 seconds )
	cblock		; assign variables to next place in register file
		dc_1		; none, one or more down counters
	endc
	movf	dc_1,f	; test for zero
	btfss	status,z	; (loading dc_? with a tick count schedules the task)
	decfsz	dc_1,f	; (loading dc_? with 0 cancels a scheduled task)
	goto	xit_sch1	; this instruction is destination of two skip sources
	;
sched_1	; Your handler for sched_1 once only action block goes in here
	;
xit_sch1
	;
;--------------------------------------------------------------------------------------------
; second example is a 16 bit up-counter, max delay 65,288 interupts ( about 10 minutes )
	cblock		; assign variables to next place in register file
		uc_lo		; for scheduling later events
		uc_hi		; high byte of 16 bit up-counter
	endc
	movf	uc_hi,f	; test if high byte is zero, if zero ignore this schedule
	btfsc	status,z	; if msb is zero, schedule is inactive, canceled or expired  
	goto xit_sch2		; load the two byte up-counter with complement of count wanted
	incfsz	uc_lo,f	; to start the delay up-counter load lsb first, then msb last
	goto xit_sch2		; maximum time is when uc_hi = 01 hex and uc_lo = 00 hex
	incfsz	uc_hi,f	; with 109 Hz interrupt this gives about 10 minutes delay
	goto xit_sch2		; it executes once when all bytes reach zero at timeout
	;
sched_2	; Your handler for sched_2 once only action block goes here
	;
xit_sch2
	;
;--------------------------------------------------------------------------------------------
XitTmr
	bcf	intcon,2	; we have handled tmr0 int so finally clear the flag
;--------------------------------------------------------------------------------------------
intpin
	btfss	intcon,1	; test if the external int pin flag is set
	goto	RBdelta	; no so jump it to next flag test
;--------------------------------------------------------------------------------------------
	;
	; Your code to handle the ext interrupt from RB0/INT pin goes here
	;
;--------------------------------------------------------------------------------------------
	bcf	intcon,1	; clear its flag and test next
;--------------------------------------------------------------------------------------------
RBdelta
	btfss	intcon,0	; test if portb bits change flag is set
	goto	interexit	; finished handling the interupts		
;--------------------------------------------------------------------------------------------
	;
	; Your code to handle an interrupt due to a change of portb goes here
	;
;--------------------------------------------------------------------------------------------
	bcf	intcon,0	; finished handling all interupts, all flags are now clear
;--------------------------------------------------------------------------------------------
; Restore the status and W registers, then return from interupt
;--------------------------------------------------------------------------------------------
interexit
	swapf	temp_stat,w	; nibble swap the status back to w reg
	movwf	status	; restore the status reg
	swapf	temp_wreg,f	; nibble swap back through w reg
	swapf	temp_wreg,w	; to avoid changing zero status
	retfie		; return from interupt, re-enable global interrupt flag
;
;============================================================================================
startup  ; Main program gets to continue here, chained from goto instruction at location zero
;============================================================================================
; Initialise variables ( move the first three instructions to 000 hex if you need space )
;--------------------------------------------------------------------------------------------
	clrf	dc_1	; disable all down-counters for scheduled tasks
	clrf	uc_lo
	clrf	uc_hi
;
;--------------------------------------------------------------------------------------------
; load the Option Register, Real Time Interupts, ( RB pull-ups, TMR0 source, prescaler )
;--------------------------------------------------------------------------------------------
;   Oscillator frequency and prescaler modulus determines interrupt rate from TMR0, 
;     option register bits      000     001     010     011     100     101     110     111
;Crystal   Crystal   TMR0out         
; basis       kHz    Rate Hz     /2     /4      /8      /16     /32     /64     /128    /256
;2^15        32.768    32.00   16.00   8.000   4.000   2.000   1.000   0.500   0.250   0.125
;2^15*100  3276.800  3200.00 1600.00 800.000 400.000 200.000 100.000 50.0000 25.0000 12.5000
;NTSC TV   3579.545  3495.65 1747.82 873.912 436.956 218.478 109.239 54.6195 27.3098 13.6549
;2^12*900  3686.400  3600.00 1800.00 900.000 450.000 225.000 112.500 56.2500 28.1250 14.0625
;4 MHz     4000.000  3906.25 1953.12 976.562 488.281 244.141 122.070 61.0352 30.5176 15.2588 
;2^12*kHz  4096.000  4000.00 2000.00 1000.00 500.000 250.000 125.000 62.5000 31.2500 15.6250
;2^22	     4194.304  4096.00 2048.00 1024.00 512.000 256.000 128.000 64.0000 32.0000 16.0000
;PAL TV    4433.619  4329.70 2164.85 1082.42 541.213 270.607 135.303 67.6516 33.8258 16.9129
;BaudRate  4915.200  4800.00 2400.00 1200.00 600.000 300.000 150.000 75.0000 37.5000 18.7500
;
;prescaler value sets interrupt rate only when internal TMR0 is used with prescaler
	bank1
	movlw	b'00000100'	; internal tmr0 with prescale 1/32, portB soft pull-ups enabled
	movwf	optreg	; 3.579545MHz / ( 4 * 32 * 256 ) = 109.239 Hz int rate
;
;--------------------------------------------------------------------------------------------
; Registers Port A & B direction   ( still in bank1 )
;--------------------------------------------------------------------------------------------
;	floating inputs should be internally pulled up or externally terminated when not driven
;	unused outputs should be left open
	movlw	b'00011111'	; 0 is output, 1 is input, port A default to inputs
	movwf	trisa		; there is no internal pull-up of portA inputs 
	movlw	b'11111111'	; default port B to all inputs
	movwf	trisb		; internal pull-up is controlled by option register bit 7
;
;--------------------------------------------------------------------------------------------
; Register Port A & B initial data values where used as outputs
;--------------------------------------------------------------------------------------------
	bank0			; return to bank 0
	movlw	b'00011111'	; porta has only 5 bits
	movwf	porta	
	movlw	b'11111111'	; portb has 8 bits
	movwf	portb	
;
;--------------------------------------------------------------------------------------------
; Enable interupts to set the interrupt ball rolling
;--------------------------------------------------------------------------------------------
	; real time clock T0 interrupt can be stretched if (IntPin or RBdelta interupts)
	;	 are enabled and T0 is loaded each timeout with new value
	movlw	b'10100000'	; enable global and T0 interrupt flag only
	movwf	intcon	; intcon reg is mapped into both banks
;
;============================================================================================
;   --  We Have Lift Off  -- ,   code here is main program
;============================================================================================
maincode
;
;
;		Your code goes here
;
;
	goto	maincode	
;
;============================================================================================
; Subroutines follow in this last block
;============================================================================================
; Compact universal 16 bit forground delay timer
;--------------------------------------------------------------------------------------------
; call delay with inner loop count in the w register, (zero gives 256 cycles)
; 	 	outer loop count in delay_cnt,  (1 gives w register count only)
; at 32.768 KHz -> 610.4 usec per inner loop, .15625 sec per outer loop, max = 40.0 sec
; at 3.2768 MHz -> 6.104 usec per inner loop, 15.6 msec per outer loop, max = 0.400 sec
; at 3.5795 MHz -> 5.587 usec per inner loop, 1.43 msec per outer loop, max = 0.366 sec
; at 4.0000 MHz -> 5.000 usec per inner loop, 1.28 msec per outer loop, max = 0.327 sec
; at 4.0960 MHz -> 4.883 usec per inner loop, 1.25 msec per outer loop, max = 0.320 sec
; at 4.1943 MHz -> 4.768 usec per inner loop, 1.22 msec per outer loop, max = 0.312 sec
; at 4.4336 MHz -> 4.511 usec per inner loop, 1.15 msec per outer loop, max = 0.295 sec
; at 4.9152 MHz -> 4.069 usec per inner loop, 1.04 msec per outer loop, max = 0.266 sec
;--------------------------------------------------------------------------------------------
	cblock		; assign variable to next place in register file
		delay_cnt	; outer loop counter used in delay routine
	endc
delay	addlw	255		; subtract one from w reg
	btfsc	status,z	; have we reached zero yet
	decfsz	delay_cnt,f	; decrement the outer loop counter, w is zero
	goto	delay		; 20 oscillator cycles loop period
	return		; exit with zero in the w reg and zero in delay_cnt
;note that times may be stretched by background high priority interrupt handler overheads
;--------------------------------------------------------------------------------------------

;============================================================================================
; End of program
;============================================================================================
																
	end
 
  • #10
thanks, I might be able to use that in the future, right now I'm trying to make my pic blink 5 times when I press a button.

I guess the real fun will be when I try to turn this thing into a calculator lol.
 

Related to Creating a Blinking LED with PIC 16F84A and 32K Crystal

1. How do I set up the PIC 16F84A for blinking LED?

To set up the PIC 16F84A for blinking LED, you will need a PIC programmer, a breadboard, a 32K crystal, and some jumper wires. First, connect the PIC programmer to your computer and the breadboard. Then, insert the PIC 16F84A into the breadboard. Connect the 32K crystal to pins 13 and 14 of the PIC. Finally, use the jumper wires to connect pin 10 of the PIC to the positive leg of the LED, and pin 11 to the negative leg.

2. What is the purpose of the 32K crystal in this project?

The 32K crystal serves as the clock for the PIC 16F84A. It provides a steady and accurate timing signal for the microcontroller to execute its instructions. Without a crystal, the microcontroller would not be able to function properly and the LED would not blink.

3. Can I use a different crystal with a different frequency?

Yes, you can use a different crystal with a different frequency as long as it is compatible with the PIC 16F84A. However, the code in this guide is specifically written for a 32K crystal, so you will need to make adjustments to the code if you use a different frequency.

4. How do I upload the code to the PIC 16F84A?

To upload the code to the PIC 16F84A, you will need to use a PIC programmer and a computer. First, open the code file in a software such as MPLAB IDE. Then, connect the PIC programmer to your computer and the breadboard. Finally, use the software to upload the code onto the PIC 16F84A.

5. Can I modify the code to make the LED blink at a different rate?

Yes, you can modify the code to make the LED blink at a different rate. The code in this guide uses a delay function to control the blinking rate. You can change the value of the delay to make the LED blink faster or slower. However, keep in mind that the maximum delay value is limited by the clock frequency of the crystal you are using.

Similar threads

  • Electrical Engineering
Replies
2
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Electrical Engineering
Replies
10
Views
3K
  • Electrical Engineering
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Electrical Engineering
Replies
2
Views
2K
  • Mechanical Engineering
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top