# Light 1 LED!

Status
Not open for further replies.

#### Squintz

##### New Member
Can somone post a schematic and code for making a PIC16f84a light 1 LED and turn it off again. Or something similar. I Finally have all the stuff i think i need to program a pic and i had built a circuit and programed my pic with agiven code from a web site tutorial but it does nothing.

So i want something very simple and basic so that i can verify that my software and programmer and PICS that i have are working.

From there i will learn how to write code and design circuits on my own but it kind of hard to get into writing code and making circuits if your not sure the parts you have are working from the start.

Thanxs for any help

#### Squintz

##### New Member
Thanx for the site but i want something much mor simple. Least amount of components and only a few lines of code.

I first have to learn how to use my programming software before i can venture out to the bigger things.

Baby Steps

#### kcox

##### New Member
what language are you looking for?

C, Pic Basic, or Pic Assembly?

#### Exo

##### Active Member
Code:
	LIST P=16F84A
#include <P16F84A.INC>

ERRORLEVEL -302		;suppress bank selection messages

CBLOCK	0x0C		  ;block of variable defenitions, starting at memory adress 0x0c
Loop1				    ;The pic16F84A's RAM starts at this adress (see datasheet)
Loop2
Loop3				    ;all counters for the delay loop
ENDC				     ;variables end

BCF		TRISB, 0	 ;clear TRISB, bit 0 -> makes PORTB bit 0 an output (for the led)
BANKSEL	PORTB		;back to bank 0

MainLoop				    ;this part will be repeated over and over and ...

BCF		PORTB, 0	 ;make the led pin low (led will light)
CALL	Delay		   ;and call the delay
BSF		PORTB, 0	 ;make the led pin high (led will go out)
CALL	Delay		   ;and wait again
GOTO	MainLoop	   ;back to beginning

Delay	;the delay routine

MOVLW	0x10
MOVWF	Loop1		;put 10h in loop1

MOVLW	0xFF
MOVWF	Loop2		;put FFh in Loop2

MOVLW	0xFF
MOVWF	Loop3		;put FFh in Loop3

DECFSZ	Loop3, F  ;subtract 1 from loop3, skip next instruction if result = 0
GOTO	\$-1			;go back 1 instruction

DECFSZ	Loop2, F

DECFSZ	Loop1, F		;if not 0, then reload loop2

RETURN

END

#### Attachments

• 33.5 KB Views: 773

#### Exo

##### Active Member
my mistake, the led should be connected the otherway around

#### Squintz

##### New Member
Thank you. That is exactly what i wanted. Next i will ask you to explain but not until i get the circuit built and tested.

#### Kane2oo2

##### New Member
isnt there any other way to get a simple circuit like that to flash an led?

like instead of using a crystal cant you simply use a capacitor of some sort?

Kane

#### Exo

##### Active Member
Yes, you can use an RC osc.

Connect the Resistor to VDD , other side to the Capacitor and the capacitor to GND. Connect the CLockIN from your pic between the R and the C

I often use 470K with a 22pf cap

Don't forget to program the pic with RC osc. in the config word.

#### Barry

##### New Member
Hello all,
Slightly off topic - a question for EXO. What software do u use for your circuit diagrams ie the circuit posted on this page. Thank you.
Barry.

Barry.

#### Kane2oo2

##### New Member
wooooo

i had a few other kits which were for the 16f84A and they had a test ciruit on em ....i forgot all about it

it has an inbuilt oscillator and everything (doh)

but im happy now as i know everything works
can get onto learning assembly :?

Kane

Status
Not open for further replies.