Re: Port indexing & PWM for LED fade
Hi All,
I tried this just the way it's published to no avail, but did manage to make it work after tinkering a bit. I used a PIC Demo board featuring a PIC16F690 and the 4 LEDs on Port C as follows:
Code:
#CONFIG
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _WDT_ON
#ENDCONFIG
DEFINE OSC 4
TRISA = 0
TRISB = 0
TRISC = 0
;------[ Set Hardware ]------------------------------------------------------
OSCCON=$70 '$70=8MHz, $60=4MHz
ANSEL=$00
ANSELH=$0
ADCON0=$00
CM1CON0=0
CM2CON0=0
PORTA=%00000000
PORTB=%00000000
PORTC=%00000000 ' RAC6&7 set with Hserout command
TRISA=%00000011 ' PORTA RA0 & RA1 input all other output
TRISB=%00000000 ' PORTB all set to Onput
TRISC=%00000000 ' PortC RC7&RC6 for hserout
Avar var byte
Duty var byte
Cycle var byte
;--[ Main Program ]-------------------------------------------------------------
Start:
gosub FadeTest
goto start
;--[ Routine for fade on and fade off LEDs]------------------------------------
FadeTest:
for avar = 8 to 11
PortC = avar << 2 &%00000001 ;& OP damps a leading on signal
cycle=4 ;cycle is number of cycles of pulse
for Duty= 0 to 220 step 1
pwm Avar,Duty,cycle
next Duty
cycle=3 ;cycle is number of cycles of pulse
for Duty= 220 to 0 step -2
pwm Avar,Duty,cycle
next Duty
next Avar
Avar = 8
Return
end
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks