Multi Input Logic For Hybrid Repeaters Source Code

Ideas, technical topics, help and discussion for ATV repeater builders
Post Reply
User avatar
g7kpm
Posts: 49
Joined: Sat Feb 23, 2008 9:00 pm

Multi Input Logic For Hybrid Repeaters Source Code

Post by g7kpm » Wed Jun 23, 2021 10:05 pm

'*******************************************************************************
'* Name : Simple Multi Input ATV repeater logic controller *
'* Author : Jason, G7KPM (Should I admit to this??? HI) *
'* Notice : Copyright (c)2020 Grimsby ATV Group GB3CT & GB3GG *
'* *
'* Date : 03/04/2020 *
'* Version : 1.0 *
'* Notes : This program is provided as is and may be modified *
'* : to suit your requirements. *
'* : Thanks and best 73s, Grimsby ATV Group *
'* : www.gb3ct.co.uk *
'*******************************************************************************

Device = 16F877A
Declare All_Digital TRUE
Xtal 20
TRISD = 0x00 'Set MCU port D to an output
TRISB = 0xff 'Set MCU port B as an input
TRISC = 0x00 'Set MCU port C as an output
TRISE = %00000111 'set MCU port E as input
ADCON1 = 6

'Declare PORTB_Pullups 1

Dim iperror As Word
Dim duration As Dword 'Variable to hold the momentary pulse in milliseconds
Dim cameolatch As Bit : cameolatch = 0
Dim outputlatch As Bit : outputlatch = 0
Dim ip As Word 'variable to hold the values read on the input detector
Dim oldip As Word 'variable to hold the former value of the input detector to compare with new read. if less than old read, activate K
Dim fullscreen As Bit
Dim quad As Bit
Dim ninescreen As Bit
Dim i As Word
Dim pulsedone As Bit
Dim quadpulsedone As Bit
Dim cameopulsedone As Bit
Dim testcardpulsedone As Bit
Dim kpulsedone As Bit


oldip = 0 'init
pulsedone = 0
cameopulsedone = 0
quadpulsedone = 0
testcardpulsedone = 0
cameolatch = PORTE.1 'true = momentary, false = latched
outputlatch = PORTE.2 'true = momentary, false = latched
duration = 1000 'set pulse in milliseconds duration for momentary mode
Low PORTD : Low PORTA.0 : Low PORTA.1 : Low PORTA.2 : Low PORTA.3 'reset all outputs to low
GoSub post 'Enable Power On Self Test if requred

'GoSub kscreen 'Sound a K to show System ready
'GoSub testcard 'Display testcard as default

'____________________Main Loop Start _________________________________________________________________________________
main:
ip = PORTB
DelayMS 1000
If ip > oldip Then GoSub kscreen 'check to see if anyone has disconnected and activate a K screen if so
'Inputs in inverted binary!
If ip = 255 Then GoSub testcard : GoTo main 'If no input active, then select testcard and repeat main loop unless input on portb is < 255
If ip = 254 Then GoTo videoselect 'input 1 active
If ip = 253 Then GoTo videoselect 'input 2 active
If ip = 251 Then GoTo videoselect 'input 3 active
If ip = 247 Then GoTo videoselect 'input 4 active
If ip = 239 Then GoTo videoselect 'input 5 active
If ip = 223 Then GoTo videoselect 'input 6 active
If ip = 191 Then GoTo videoselect 'input 7 active
If ip = 127 Then GoTo videoselect 'input 8 active

'If ip < 16 Then GoSub quadselect ' if more than one input 1 - 4 is active then select Quad mode
If ip > 231 Then GoSub quadselect ' if more than one input 1 - 4 is active then select Quad mode
'If ip >15 Then GoSub ninescreenselect' if input above 4 is selected then enter 9 screen mode
If ip < 232 Then GoSub ninescreenselect
oldip = ip

GoTo main ' repeat main loop for eternity (or until it crashes or the power is tuned off :0) xoxoxo

'______________________________________End of Main Loop_______________________________________________________________________________


'_____________________________________'Subroutine to select inputs 1 - 8 full screen__________________________________________________
videoselect:

Low PORTA.0 : Low PORTA.1 : Low PORTA.2 : Low PORTA.3 'turn of cameo, quad and testcard
If outputlatch = 0 And ip = 254 Then High PORTD.0 : oldip = ip : ip = 0 : GoTo main 'outputlatch = FALSE then ouputs are LATCHED. TRUE = momentary
If outputlatch = 0 And ip = 253 Then High PORTD.1 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 251 Then High PORTD.2 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 247 Then High PORTD.3 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 239 Then High PORTD.4 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 223 Then High PORTD.5 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 191 Then High PORTD.6 : oldip = ip : ip = 0 : GoTo main
If outputlatch = 0 And ip = 127 Then High PORTD.7 : oldip = ip : ip = 0 : GoTo main
'Actions if momentary is selected with jumper. Pulse putput for a duration set with variable 'duration'
If pulsedone = 1 Then GoTo main 'pulse has already happened to return to the main loop else continue
If ip = 254 Then High PORTD.0 : DelayMS duration : Low PORTD.0 'input 1 active
If ip = 253 Then High PORTD.1 : DelayMS duration : Low PORTD.1 'input 2 active
If ip = 251 Then High PORTD.2 : DelayMS duration : Low PORTD.2 'input 3 active
If ip = 247 Then High PORTD.3 : DelayMS duration : Low PORTD.3 'input 4 active
If ip = 239 Then High PORTD.4 : DelayMS duration : Low PORTD.4 'input 5 active
If ip = 223 Then High PORTD.5 : DelayMS duration : Low PORTD.5 'input 6 active
If ip = 191 Then High PORTD.6 : DelayMS duration : Low PORTD.6 'input 7 active
If ip = 127 Then High PORTD.7 : DelayMS duration : Low PORTD.7
pulsedone = 1 'flag pulse has happened to ensure it is once only and reset during the K routine
oldip = ip
ip = 255
GoTo main

'______________________________________________________________________________________________________________________________________

quadselect:

If ip = 255 Then Return 'ensure we are not here because there are no inputs active from main loop!
Low PORTD 'turn off full screen inputs
Low PORTA.0 : Low PORTA.1 : Low PORTA.2 'ensure cameo, quad and testcard outputs are turned off
If cameolatch = 0 Then High PORTA.3 : Return 'set quad select pin high as cameolatch is true then return to main routine
If quadpulsedone = 1 Then Return 'go back to main as pulse has already happened else continue. This variable is reset FALSE in the K routine
High PORTA.3 : DelayMS duration : Low PORTA.3 'send a pulse to select quad set by the variable duration
let quadpulsedone = 1 'flag that pulse has happened
Return

'*************************************************************************************************************************************

ninescreenselect:

Low PORTD 'turn off full screen inputs
Low PORTA.0 : Low PORTA.1 : Low PORTA.3 'turn of cameo, quad and testcard
If cameolatch = 0 Then High PORTA.2 'set nine screen select pin high as cameolatch is true
If cameolatch = 1 And cameopulsedone = 0 Then High PORTA.2 : DelayMS duration : Low PORTA.2 : cameopulsedone = 1'send a pulse set by the value of duration to select 9 screen
Return

'*************************************************************************************************************************************

kscreen:

Low PORTD 'turn off any outputs selecting video inputs 1 - 8
Low PORTA.3 : Low PORTA.2 : Low PORTA.1
High PORTA.0 ' Activate K screen output
If cameolatch = 1 Then High PORTA.0 : DelayMS duration : Low PORTA.0
Sound PORTC.4,[120,30,0,5,120,10,0,5,120,30] ' sound something which vaguely resembles the letter K in morse...to pin C.4
DelayMS 3000 'waste some time for 3 seconds
oldip = ip ' K has happened so reset oldip to the value of the new input read
Low PORTA.0 'turn off K screen
pulsedone = 0 'reset output switch pulse variable pulsedone to false as switching has occured
cameopulsedone = 0 'reset cameo pulse occured to false
quadpulsedone = 0 'reset quad pulse occured flag to false
testcardpulsedone =0 'reset testcard occured flag to false
Return

'_____________________________________________________________________________________________________________________________________

testcard:

Low PORTD : Low PORTA.4 : Low PORTA.2 : Low PORTA.0
If outputlatch = 0 Then High PORTA.1 'enable testcard latched output if outputlatch = FALSE
If outputlatch = 1 And testcardpulsedone = 0 Then High PORTA.1 : DelayMS duration : Low PORTA.1 'Enable testcard momentary output if outputlatch = TRUE if pulse not done B4
ip = 255
testcardpulsedone = 1
Return

post: 'Optional Power On Self Test

Low PORTD
High PORTD.0
DelayMS 300
Low PORTD.0
DelayMS 300
High PORTD.1
DelayMS 300
Low PORTD.1
DelayMS 300
High PORTD.2
DelayMS 300
Low PORTD.2
DelayMS 300
High PORTD.3
DelayMS 300
Low PORTD.3
DelayMS 300
High PORTD.4
DelayMS 300
Low PORTD.4
DelayMS 300
High PORTD.5
DelayMS 300
Low PORTD.5
DelayMS 300
High PORTD.6
DelayMS 300
Low PORTD.6
DelayMS 300
High PORTD.7
DelayMS 300
Low PORTD.7
DelayMS 300
Low PORTD
'Test Quad, 9 screen, K screen and testcard selection
High PORTA.0
DelayMS 300
Low PORTA.0
DelayMS 300
High PORTA.1
DelayMS 300
Low PORTA.1
DelayMS 300
High PORTA.2
DelayMS 300
Low PORTA.2
DelayMS 300
High PORTA.3
DelayMS 300
Low PORTA.3
DelayMS 300
GoSub kscreen
Return
pcb layout atv logic controller.jpg
pcb layout atv logic controller.jpg (727.67 KiB) Viewed 4313 times
SyncDetector&Logic.jpg
SyncDetector&Logic.jpg (1.1 MiB) Viewed 4313 times

Post Reply

Return to “ATV Repeater Technical Topics”