• 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.

Effects

Status
Not open for further replies.

stephenpic

New Member
Hi,

Im very new to PIC's and have the PIC kit 1 flash starter. I decided to make something for use in moded pc's ( Any computer with a window kit ). Since my computer has a window on the side I though it would be a good starting project to make a little light effect thing for the inside of the case. The project uses 2 LED's which at the moment are just two of the standard red ones on the development board but which i intend to use high-brightness ones in there place; a blue and green one. The first LED turns on for a few seconds which will light the inside of the case up ( probably not bright enough to work very well in the light ( if this is the case i could consider using 2 LED's in place of each 1 ) and then the LED turns off and the second one kicks in for a few seconds lighting the inside of the case in the second colour, then it goes to a 'skitzo' mode where its a quick flash of each coloured LED hopefully producing an eye catching effect. Then back to the begginning again. I have two queries though, firstly how would i use a standard molar connector inside the pc to connect to my PIC ( it has 3 pins and runs on 12 V ) so would i just need some resisters or something larger? Secondly a more general question could anyone offer any advice on my code ( probably much better ways of than the multiple calls to the delay ) or any general comments.

Thanks!

BTW I have uploaded a small video file of the effect in action! Its less than 0.5MB so it wont take long to load.
http://www.onlinehoster.com/pc/AAAA0001.AVI


Code: ( Learning from examples on 256.co.uk )
----------------

;12F675 2 LED Flashing Effects

list p=12F675
#include "p12f675.inc"

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

del_lo equ 0x20
del_hi equ 0x21

;nop
goto init

return

init
banksel 0x80 ;select upper register bank
clrf ANSEL ;make all I/O ports digital
movlw 0x0f
movwf TRISIO ;make GP4 and GP5 outputs
banksel 0x00 ;select lower register bank
clrf GPIO ;initialise all outputs
clrf del_lo ;initialise delay counter low byte
clrf del_hi ;initialise delay counter high byte

Lightup
;Keep LED 1 ( D0 ) on for a few seconds and then LED 2 ( D1 )
bsf GPIO,4 ;set output GP4 high
call longdelay ;go for a long delay
bcf GPIO,4 ;set output GP4 low
bsf GPIO,5 ;set output GP5 high
call longdelay ;go for a long delay
bcf GPIO,5 ;set output GP5 low
goto skitzo ;goto skitzo effect


skitzo
bsf GPIO,4 ;set output GP4 high
call quickdelay ;delay
bcf GPIO,4 ;set output GP4 low
call quickdelay ;delay
bsf GPIO,5 ;set output GP5 high
call quickdelay ;delay
bcf GPIO,5 ;set output GP5 low
call quickdelay ;delay
bsf GPIO,4 ;set output GP4 high
call quickdelay ;delay
bcf GPIO,4 ;set output GP4 low
call quickdelay ;delay
bsf GPIO,5 ;set output GP5 high
call quickdelay ;delay
bcf GPIO,5 ;set output GP5 low
call quickdelay ;delay
bsf GPIO,4 ;set output GP4 high
call quickdelay ;delay
bcf GPIO,4 ;set output GP4 low
call quickdelay ;delay
bsf GPIO,5 ;set output GP5 high
call quickdelay ;delay
bcf GPIO,5 ;set output GP5 low
call quickdelay ;delay
bsf GPIO,4 ;set output GP4 high
call quickdelay ;delay
bcf GPIO,4 ;set output GP4 low
call delay ;delay
bsf GPIO,5 ;set output GP5 high
call quickdelay ;delay
bcf GPIO,5 ;set output GP5 low
call quickdelay ;delay
goto Lightup ;go back and do it again


longdelay
call delay ;delay
call delay ;delay
call delay ;delaye
call delay ;delay
call delay ;delay
call delay ;delay
call delay ;delay
call delay ;delay

return ;return to where the subroutine was called

delay
decfsz del_lo,f ;decrement the low order delay register
goto delay ;go back if it hasn't reached zero
decfsz del_hi,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called

quickdelay
decfsz del_hi,f ;decrement the high order delay register
goto delay ;go back if it hasn't reached zero
return ;return to where the subroutine was called

end
 

petesmc

New Member
On a standard molex connector, the red wire is 5V. So no need for resistors or anything. I have used it directly into PIC without problems. Just be careful with it, as it can supply like 20A, so no short circuits.

No suggestions with the code except you might want to try this out for the delays: http://www.mnsi.net/~boucher/picloops.html

-Peter
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Have a look at my tutorials at http://www.winpicprog.co.uk, almost all of them use delays (and if they don't, the delay routines are often still in the code).

What I tend to do is have a delay routine which delays a certain time, say 1mS. Then call that from another routine which loops a certain number of times - I usually pass the value in the W register.

So code like this:

movlw d'100'
call DelayW

Will delay 100mS, assuming the delay called in DelayW is 1mS. You can find examples in the tutorials.

I also tend to have a number of preset delays as well, basically just preloading W as before, so:

call Delay20

will delay 20mS

call Delay255

will delay 255mS
 

stephenpic

New Member
Thanks for the info on the molex connector, i dont supose you have any photo's of a PIC connectec or schematics, i haven't taken anything of my development board before so Im not too sure how i too hook everything up.

Thanks nigel ill check out the tuts :)
 

petesmc

New Member
I usually just cut a cable/connector from something else, like an old PSU, or a fan or something, then solder the cables needed directly onto the PCB. Though, i did by some PCB molex connectors the other day.

-Peter
 

Exo

Active Member
Also consider when the project is finished and you want to use high-power leds you should buffer the Pic's outputs with transistors or something.
Pic can only supply 20-25mA on an output, high power leds, specially blue ones, tend to use much more
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top