Code: Select all
#include <PULSE.bas>
WHILE 1
PWM (15, 128, 20)
LOOP
Code: Select all
#include <PULSE.bas>
WHILE 1
PWM (15, 128, 20)
LOOP
Code: Select all
SUB I2Cwait
dim start as integer
start = TIMER
while (TIMER - start) < I2CwaitTime
loop
END SUB
Code: Select all
while ((TIMER - start) < timeperiod)
i = duty
while (i)
i = i - 1
loop
OUT(pin) = 0
i = 256-duty
while (i)
i = i - 1
loop
OUT(pin) = 1
loop
Code: Select all
' on pin for time (msec) do bit-banged PWM of duty cycle (0-255)
SUB PWM (pin, duty, timeperiod)
DIM i as INTEGER
DIM start AS INTEGER
OUTPUT (pin)
duty = duty & 0xFF
if(duty) then OUT(pin) = 1 else OUT(pin) = 0
INTERRUPT(0)
timeperiod = timeperiod * 1000
start = TIMER
if (duty=0 OR duty=255) then ' check always high or low
while ((TIMER - start) < timeperiod)
loop
else
while ((TIMER - start) < timeperiod)
i = duty
while (i)
i = i - 1
loop
OUT(pin) = 0
i = 256-duty
while (i)
i = i - 1
loop
OUT(pin) = 1
loop
endif
INTERRUPT(1)
INPUT (pin) ' allow pin to float
END SUB