Code:
'PIC 16F76
'----------------------------------------------------------------------------
'Clock setup
Define OSC 20
'Interrupt setups
INTCON = %11000000 'Enable: Global interrupts, Peripheral interrupts
PIE1 = %01000000 'Enable: ADC interrupt
'ADC setups
ADCON0 = %10000001 'ADC CLOCK = 625kHz, Select ch.0, enable ADC
'Pin setups
TRISA = %00000001 'PortA: 1-5 = output, 0 = input, 6-7 = N/A
TRISB = %11111111 'PortB: 0-7 = input (defaults)
TRISC = %11111111 'PortC: 0-7 = input (defaults)
'Usart setups
SPBRG = %00011001 'Set 9600 baud w/20MHz clock
TXSTA = %00100110 'Enable transmit, set BRGH high
RCSTA = %10010000 'Enable Usart, enable receiver
'----------------------------------------------------------------------------
'LCD setup (16 x 4 lines)
DEFINE LCD_LINES 4
Define LCD_BITS 4 '4 data interface lines
Define LCD_DREG PORTB 'LCD data port
Define LCD_DBIT 4 'LCD data bits 0-4
Define LCD_RSREG PORTB 'LCD register select port
Define LCD_RSBIT 3 'LCD register select bit
Define LCD_EREG PORTB 'LCD enable port
Define LCD_EBIT 0 'LCD enable bit
'----------------------------------------------------------------------------
Setup_YN var byte
Torch_Lock_Val var byte
CNT VAR BYTE
CNT2 VAR BYTE
Hyst_Val var byte
First_Run var bit
Enable_In var PORTC.0
Torch_V_Now var byte
Torch_Up var PORTE.0
Torch_Dn var PORTE.1
Torch_Lock_Val = 120
Hyst_Val = 0
first_run = 1
low enable_in
pause 1000
LCDout $fe, 1
LCDout $fe, $03, "WELCOME TO THE"
Lcdout $fe, $42, "DOUBLE DOWN IND."
Lcdout $fe, $14, "TORCH HEIGHT CONTROL"
Lcdout $fe, $54, "LCD WARMING UP"
FOR CNT2 = 1 TO 5
FOR CNT = 0 TO 4
Lcdout $fe, $63 + CNT, "."
PAUSE 400
Lcdout $fe, $63 + CNT, $20
NEXT CNT
NEXT CNT2
Start:
IF Enable_In = 0 then
PIE1.6 = 0 'Turn off ADC interrupt
'***** START MSG1 *****
LCDout $fe, 1
LCDout $fe, $03, "CONTROL IS IN"
Lcdout $fe, $43, "STANDBY MODE."
LCDout $fe, $15, "WOULD YOU LIKE TO"
Lcdout $fe, $55, "RUN SETUP? (Y/N)"
Lcdout $fe, $66
LCDOUT $fe, $0F
'***** END MSG1 *****
HSERIN [Setup_YN]
if setup_yn != "Y" then goto start
Bad_Torch_Lock_Val:
'***** START MSG2 *****
LCDout $fe, 1
LCDout $fe, $01, "ENTER A ", $22, "LOCK TO", $22
Lcdout $fe, $40, "TORCH VOLTAGE VALUE:"
LCDout $fe, $17, $22, "X", $22, " TO EXIT OR"
Lcdout $fe, $56, "(000 - 256) ___"
Lcdout $fe, $63
LCDOUT $fe, $0F
'***** END MSG2 *****
HSERIN [DEC Torch_Lock_Val]
if (Torch_Lock_Val >= 0) and (Torch_Lock_Val <= 256) then goto Bad_Hyst_Val
if Torch_Lock_Val = "X" then goto start
'***** START ERR_MSG1 *****
LCDout $fe, 1
LCDout $fe, $02, "ONLY (000 - 256)"
Lcdout $fe, $40, "ALLOWED!"
LCDout $fe, $17, "PLEASE STANDBY"
FOR CNT = 0 TO 19
Lcdout $fe, $54 + CNT, "."
PAUSE 150
NEXT CNT
'***** END ERR_MSG1 *****
GOTO Bad_Torch_Lock_Val
Bad_Hyst_Val:
'***** START MSG3 *****
LCDout $fe, 1
LCDout $fe, $01, "ENTER A HYSTERESIS"
Lcdout $fe, $42, "+/- VOLTAGE VALUE:"
LCDout $fe, $17, $22, "X", $22, " TO EXIT OR"
Lcdout $fe, $58, "(0 - 5) _"
Lcdout $fe, $63
LCDOUT $fe, $0F
'***** END MSG3 *****
HSERIN [DEC hyst_Val]
if (hyst_Val >= 0) and (hyst_Val < 6) then
'***** START MSG4 *****
LCDout $fe, 1
LCDout $fe, $03, "SETUP COMPLETE"
Lcdout $fe, $40, "TORCH LOCK VALUE=", Torch_Lock_Val
LCDout $fe, $15, "HYSTERESIS VALUE=", hyst_Val
FOR CNT = 0 TO 19
Lcdout $fe, $54 + CNT, "."
PAUSE 300
NEXT CNT
'***** END MSG4 *****
goto start
endif
if hyst_Val = "X" then goto start
'***** START ERR_MSG2 *****
LCDout $fe, 1
LCDout $fe, $04, "ONLY (0 - 5)"
Lcdout $fe, $46, "ALLOWED!"
LCDout $fe, $17, "PLEASE STANDBY"
FOR CNT = 0 TO 19
Lcdout $fe, $54 + CNT, "."
PAUSE 150
NEXT CNT
'***** END ERR_MSG2 *****
GOTO Bad_Hyst_Val
first_run = 1
ELSE
PIE1.6 = 1 'Turn on ADC interrupt
ADCON0.2 = 1 'Start ADC conversion
if PIR1.6 = 1 THEN GOTO New_ADC 'New ADC interrupt flag
if first_run = 1 then
LCDout $fe, 1
Lcdout $fe, $01, "PLASMA VOLTAGE=", Torch_V_Now
Lcdout $fe, $40, "--------------------"
Lcdout $fe, $14, "TORCH LOCK VALUE=", Torch_Lock_Val
LCDout $fe, $55, "HYSTERESIS VALUE=", hyst_Val
FIRST_RUN = 0
ELSE
Lcdout $fe, $10, Torch_V_Now
ENDIF
select case Torch_V_Now
case Torch_V_Now > Torch_Lock_Val + hysT_val
high torch_dn
low torch_up
case Torch_V_Now < Torch_Lock_Val - hysT_val
high torch_up
low torch_dn
case else
low torch_up
low torch_dn
end select
endif
GOTO Start
New_ADC:
Torch_V_Now = ADRES 'Read ADC value into VAR
PIR1.6 = 0 'Clear ADC interrupt flag
Return
Does that seem to eliminate the string parsing gig altogether? I think I'm so stuck in the thinking of no LCD... First time I've messed with 'em. I think it just saved me a load of brain fry... I dunno?
Bookmarks