Code:
'**********************************************************************
' Programme: Test1.PBP (c)RGL 05-2023
' ---> PIC 12F675
'***********************************************************************
' PicBasicPro Compiler V:2.40 448 Words compiled
'*** PIC Pinouts/Specifications
'------------------------------------
' PIC 12F675 (Internal 4Mhz Osc) DEFINE OSC =Default.Value =4
' __ __
' Vcc +| U |- Gnd
' (nc)GP5 x| |< GP0 _Config Jumper
' _Horizontal GP4 >| |> GP1 _Servo1
' _Vertical GP3 >| |> GP2 _Servo2
' -----
@ Device Pic12F675, intrc_osc, wdt_off, pwrt_on, mclr_off, protect_off
DEFINE OSC 4 '10us Pulsout Unit: 100 = 1ms @4Mhz
' 1ms Pause Unit : 1 = 1ms @4Mhz
CMCON = 7 'Comparator Off
ANSEL = 0 'Set Port to Digital i/o
ADCON0 = 0 'All ADC Off
TRISIO = %011001 ; 1=Input
GPIO = %00 ; Make all pins 0 except input pins
OSCCAL = $38 ' $38=56d ' Also to be manually placed at 3FF Address (3438)!
'*** In/Out pins ..................................................
'GND pin8 - Gnd
Input 0 : Symbol _Config = GPIO.0 'Jumper pin7 - In0
Output 1 : Symbol _Servo1 = GPIO.1 'Servo1 pin6 - Out1
Output 2 : Symbol _Servo2 = GPIO.2 'Servo2 pin5 - Out2
Input 3 : Symbol _Vertical = GPIO.3 'Vertical Position pin4 - In3
Input 4 : Symbol _Horizontal = GPIO.4 'Horizontal Position pin3 - In4
;Input 5 : Symbol _xxx = GPIO.5 pin2 - nc
' 'Vcc pin1 - Vcc
'*** Variables
Menu VAR byte 'Program Mode index (0 to 3)
Vertical VAR word 'Vertical Position
Horizontal VAR word 'Horizontal Position
RVertical VAR word 'Reverse Vertical Position Value (3msec - Vertical)
RHorizontal VAR word 'Reverse Horizontal Value (3msec - Horizontal)
'=== MAIN PROGRAM =====================================================
Init:
READ 0, Menu 'Read Eeprom when starting (Check Mode Prg)
MainLoop:
IF _Config=0 Then Gosub MODE ' Enabled Mode Configuration Jumper
Pulsin _Vertical,1,Vertical 'Read Vertical Position
gosub Tri
Pulsin _Horizontal,1,Horizontal 'Read Horizontal Position
gosub Tri
Goto MainLoop
'=======================================================================
' --- SUBROUTINES ---
'=======================================================================
TRI:
Select Case Menu
Case 0
Gosub PRG0
Case 1
Gosub PRG1
Case 2
Gosub PRG2
End Select
Return
'-------------------------------------------------
MODE: 'Change and memorize the 3 Menu Program index (0 to 2)
Menu = Menu + 1
IF Menu > 2 Then Menu = 0
WRITE 0,Menu 'Write to Eeprom @Addr.0 the menu index
PAuse 1000 '1 sec
Return
'-------------------------------------------------
PRG0:
IF Horizontal <120 then '1ms (<1,2ms)
Pulsout _Servo1,Horizontal
Pulsout _Servo2,Vertical
Else
IF Horizontal < 170 then '1,5ms (<1,7ms)
Pulsout _Servo1,100 '1ms
Pulsout _Servo2,100 '1ms
Else '2ms (>=1,7ms)
Pulsout _Servo1,Vertical
Pulsout _Servo2,Horizontal
Endif
Endif
Return
'-------------------------------------------------
PRG1:
RHorizontal = 300-Horizontal 'Reverse Horizontal Pösition (3msec-Horizontal)
IF Horizontal <120 then '1ms (<1,2ms)
Pulsout _Servo1,RHorizontal
Pulsout _Servo2,Vertical
Else
IF Horizontal < 170 then '1,5ms (<1,7ms)
Pulsout _Servo1,200 '2ms
Pulsout _Servo2,100 '1ms
Else '2ms (>=1,7ms)
Pulsout _Servo1,Vertical
Pulsout _Servo2,Horizontal
Endif
Endif
Return
'-------------------------------------------------
PRG2:
RHorizontal = 300-Horizontal 'Reverse Horizontal Pösition (3msec-Horizontal)
RVertical = 300-Vertical 'Reverse Vertical Position (3msec-Vertical)
IF Horizontal <120 then '1ms (<1,2ms)
Pulsout _Servo1,Horizontal
Pulsout _Servo2,Vertical
Else
IF Horizontal < 170 then '1,5ms (<1,7ms)
Pulsout _Servo1,100 '1ms
Pulsout _Servo2,200 '2ms
Else '2ms (>=1,7ms)
Pulsout _Servo1,RVertical
Pulsout _Servo2,RHorizontal
Endif
Endif
Return
'-------------------------------------------------
'==== END OF PRG ===============================================
Bookmarks