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.
**broken link removed**
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
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.
**broken link removed**
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