' ========================================================================= ' ' File...... PWM.SXB ' Purpose... Generate sawtooth wave with PWM instruction ' Author.... (c) Parallax, Inc. -- All Rights Reserved ' E-mail.... support@parallax.com ' Started... ' Updated... 29 OCT 2004 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' PWM To Genrate RGB Colors From A RGB Led ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- DACBLUE VAR RB.0 ' output to RC network DACRED VAR RB.1 ' output to RC network DACGREEN VAR RB.2 ' output to RC network ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- dutyA VAR Byte dutyB VAR Byte dutyC VAR Byte dutyD VAR Byte dutyE VAR Byte dutyF VAR Byte ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: FOR dutyA = 255 TO 0 STEP -1 'LoopC inside loopB inside loopA PWM DACBLUE, dutyA, 15 FOR dutyB = 255 TO 0 STEP -1 PWM DACGREEN, dutyB, 15 FOR dutyC = 255 TO 0 STEP -1 PWM DACRED, dutyC, 15 NEXT dutyC NEXT dutyB NEXT dutyA 'FOR dutyD = 0 TO 255 STEP 1 'PWM DACRED, dutyD, 15 'NEXT 'FOR dutyE = 0 TO 255 STEP 1 'PWM DACBLUE, dutyE, 15 'NEXT 'FOR dutyF = 0 TO 255 STEP 1 'PWM DACGREEN, dutyF, 15 'NEXT GOTO Start