Code:
low porta.2 : low porta.1 : low porta.3 : low porta.0
@ __CONFIG _BOREN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _LVP_OFF & _WDT_ON & _INTOSC_OSC_NOCLKOUT & _MCLRE_OFF
'---------------------------- Port Assignments --------------------------------
' porta.0 Output 3 LED
' porta.1 Output 1 LED
' porta.2 Run LED
' porta.3 Output 2 LED
' porta.4 Unused
' porta.5 MCLR
' porta.6 Unused
' porta.7 Unused
' portb.0 Input 3
' portb.1 Input 2
' portb.2 Input 1
' portb.3 HPWM Output
' portb.4 Up Button
' portb.5 Down Button
' portb.6 Program Button
' portb.7 Debug Output
'---------------------------- EEPROM Locations --------------------------------
' 0 Output 1 Setting
' 1 Output 2 Setting
' 2 Output 3 Setting
'---------------------------- Debug Settings ----------------------------------
' DEFINE DEBUG_REG PORTB ' Debug port
' DEFINE DEBUG_BIT 7 ' Debug port bit
' DEFINE DEBUG_BAUD 2400 ' Debug baud rate
' DEFINE DEBUG_MODE 1 ' Debug mode 1 = inverted
' DEFINE DEBUG_PACING 300 ' Delay 'in micro sec' between characters sent
i con 254 ' Control byte
clr con 1 ' Clear the display
line1 con 128 ' Move cursor to home position on line 1
line2 con 192 ' Move cursor to home position on line 2
'------------------------------- Variables -------------------------------------
StillPressed var bit
x var byte
Output1 var word
Output2 var word
Output3 var word
StartupDelay var byte
TimeOut var byte
'------------------------ Miscellaneous Variables ------------------------------
Output3LED var porta.0
Output1LED var porta.1
RunLED var porta.2
Output2LED var porta.3
UpButton var portb.4
DownButton var portb.5
SetupButton var portb.6
Input1 var portb.0
Input2 var portb.2
Input3 var portb.1
'--------------------------- Port Initialization ------------------------------
TRISA = %00100000
TRISB = %11110111
CMCON = %00000111
CCP1CON = %00001111
OPTION_REG.7 = 0
'----------------------------- Main Program Loop -------------------------------
data 65,129,194
include "Elapsed.pbp"
gosub ResetTime ' Reset Time to 0d-00:00:00.00
gosub StartTimer ' Start the Elapsed Timer
clear
low porta.2 : low porta.1 : low porta.3 : low porta.0
StartupDelay = 34
TimeOut = 20
DelayedStartup:
if portb.7 = 0 then main
toggle RunLED
pause 250
if Seconds < StartupDelay then DelayedStartup
' debug i,clr
Main:
if SetupButton = 0 and StillPressed = 0 then
StillPressed = 1
gosub ResetTime
goto Setup
endif
StillPressed = 0
high RunLED
read 0,Output1 : read 1,Output2 : read 2,Output3
if Input3 = 0 then
' debug i,line1,"OUTPUT 3 = ",dec3 Output3," "
low Output1LED : low Output2LED : high Output3LED : hpwm 1,Output3,1000
goto main
endif
if Input2 = 0 then
' debug i,line1,"OUTPUT 2 = ",dec3 Output2," "
low Output1LED : high Output2LED : low Output3LED : hpwm 1,Output2,1000
goto main
endif
if Input1 = 0 then
' debug i,line1,"OUTPUT 1 = ",dec3 Output1," "
high Output1LED : low Output2LED : low Output3LED : hpwm 1,Output1,1000
goto main
endif
' debug i,line1,"OUTPUT = OFF "
low Output1LED : low Output2LED : low Output3LED : hpwm 1,0,1000
goto main
'-------------------------------------------------------------------------------
Setup:
low RunLED
low Output1LED
low Output2LED
low Output3LED
if SetupButton = 0 and StillPressed = 1 then Setup
StillPressed = 0
pause 50
read 0, Output1
Output1Setup:
high Output1LED
' debug i,line1,"OUTPUT 1 = ",dec3 Output1," "
hpwm 1,Output1,1000
if SetupButton = 0 and StillPressed = 1 then Output1Setup
StillPressed = 0
pause 50
StillPressed1:
if SetupButton = 0 then
gosub ResetTime
StillPressed = 1
low Output1LED
pause 250
if SetupButton = 0 then StillPressed1
write 0,Output1
read 1, Output2
goto Output2Setup
endif
if UpButton = 0 then
gosub ResetTime
x = x + 1
if Output1 + x > 254 then
Output1 = 255
goto Output1Setup
endif
Output1 = Output1 + x
pause 100
goto Output1Setup
endif
if downbutton = 0 then
gosub ResetTime
x = x + 1
if Output1 < x then
Output1 = 0
goto Output1Setup
endif
Output1 = Output1 - x
pause 100
goto Output1Setup
endif
StillPressed = 0
x = 0
if Seconds => TimeOut then
read 0, Output1
goto main
endif
goto Output1Setup
'-------------------------------------------------------------------------------
Output2Setup:
high Output2LED
' debug i,line1,"OUTPUT 2 = ",dec3 Output2," "
hpwm 1,Output2,1000
if SetupButton = 0 and StillPressed = 1 then Output2Setup
StillPressed = 0
pause 50
StillPressed2:
if SetupButton = 0 then
gosub ResetTime
StillPressed = 1
low Output2LED
pause 250
if SetupButton = 0 then StillPressed2
write 1,Output2
read 2, Output3
goto Output3Setup
endif
if UpButton = 0 then
gosub ResetTime
x = x + 1
if Output2 + x > 254 then
Output2 = 255
goto Output2Setup
endif
Output2 = Output2 + x
pause 100
goto Output2Setup
endif
if downbutton = 0 then
gosub ResetTime
x = x + 1
if Output2 < x then
Output2 = 0
goto Output2Setup
endif
Output2 = Output2 - x
pause 100
goto Output2Setup
endif
StillPressed = 0
x = 0
if Seconds => TimeOut then
read 1, Output2
goto main
endif
goto Output2Setup
'-------------------------------------------------------------------------------
Output3Setup:
high Output3LED
' debug i,line1,"OUTPUT 3 = ",dec3 Output3," "
hpwm 1,Output3,1000
if SetupButton = 0 and StillPressed = 1 then Output3Setup
StillPressed = 0
pause 50
StillPressed3:
if SetupButton = 0 then
gosub ResetTime
StillPressed = 1
low Output3LED
pause 250
if SetupButton = 0 then StillPressed3
write 2,Output3
goto main
endif
if UpButton = 0 then
gosub ResetTime
x = x + 1
if Output3 + x > 254 then
Output3 = 255
goto Output3Setup
endif
Output3 = Output3 + x
pause 100
goto Output3Setup
endif
if downbutton = 0 then
gosub ResetTime
x = x + 1
if Output3 < x then
Output3 = 0
goto Output3Setup
endif
Output3 = Output3 - x
pause 100
goto Output3Setup
endif
StillPressed = 0
x = 0
if Seconds => TimeOut then
read 2, Output3
goto main
endif
goto Output3Setup
Bookmarks