'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' RMCS-220X Pump Drive
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$Regfile = "m32def.dat"
$Crystal = 16000000
$Baud = 9600
$hwstack = 256
$swstack = 128
$framesize = 156
Config Timer0 = TIMER, PRESCALE= 8
Config LCD = 16 * 2
Config LCDBUS = 4
Config LCdPIN = Pin, DB4 = PortB.4, DB5 = PortB.5, DB6 = PORTB.6, DB7 = PortB.7, E = PortB.3, Rs = PORTB.2
Config PinD.4 = Input
Config PinD.5 = Input
Config PinD.6 = Input
Config PinD.7 = Input
Incsw Alias PinD.4
Decsw Alias PinD.5
Selsw Alias PinD.6
Modsw Alias PinD.7
config Scl = PortC.5
config SDA = PortC.4
i2cinit
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Variable Declaration
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Dim Waddress as byte,Raddress as byte,Value as Byte,Address as Byte, M_add as word
Dim Micsecs as byte,Milsecs as word,Secs as byte,Mins as byte,Hrs as Byte
Dim Rng_min as byte, rng_max as byte, user_sel as byte, keypress as bit
Dim run as Byte, Mtrdirec as byte, rxbyte as Byte, Srlint as bit
Dim Del as byte, spdlsb as byte, spdmsb as byte
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' System Subroutine Declarations
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Declare sub Splash()
Declare Sub Chk_Ky()
Declare sub Delayy()
Declare Sub Rmcs220_Speed()
Declare Sub Write_eeprmc64(m_add As Word , Value As Byte)
Declare Sub Read_eeprmc64(m_add As Word , Value As Byte)
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' System Main Program
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Const Reg1 = &h0 ' Read/Write Motor Max Speed
Const Reg2 = &h1 ' Read/Write Motor Speed and Direction
Const Reg3 = &h2 ' Read/Write Speed Damping
Const Reg4 = &h3 ' Read/Write Encoder Position
Const Reg5 = &h4 ' Read/Write Go toPosition Comand
Const Reg6 = &h5 ' Read/Write Speed feedback Gain term
Const Reg7 = &h6 ' Read/Write P-Gain term
Const Reg8 = &h7 ' Read/Write I-Gain term
Const Reg9 = &h8 ' Read/Write Go to Position Comand
Enable Interrupts
Enable Int0
Enable Urxc
Enable Timer0
On Int0 Kybisr
On Urxc Srlisr
On Timer0 Tmr0isr
load timer0, 200
start timer0
Call Splash
M_add = 10
Value = 65
Call Write_eeprmc64(M_add, Value)
Do
Locate 1, 1
LCD "Secs:"; Secs
Locate 2,1
LCD "Mins:";Mins
Loop
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Splash Screen
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Splash()
CLS
Cursor off
LCD "Spectrochem"
Lowerline
LCD " Instruments"
del = 200
call delayy
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Delay
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Delayy()
Micsecs = 0
Milsecs = 0
Cls
Do
Loop Until Milsecs >= Del
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' RMCS220 Speed
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Rmcs220_Speed()
Waddress = &h10
Raddress = &h11
I2cstart
I2cwbyte Waddress
I2cwbyte Reg2
I2cwbyte Spdlsb
I2cwbyte Spdmsb
I2cstop
Del = 10
Call Delayy
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IIC routines @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' EEPROM Write Operation
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Write_eeprmc64(m_add As Word , Value As Byte)
Local M_ladd As Byte
Local M_hadd As Byte
Waddress = &HA0
Raddress = &HA1
M_ladd = Low(m_add)
M_hadd = High(m_add)
I2cstart
I2cwbyte Waddress
I2cwbyte M_hadd
I2cwbyte M_ladd
I2cwbyte Value
I2cstop
Del = 10
Call Delayy
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' EEPROM Read Operation
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Read_eeprmc64(m_add As Word , Value As Byte)
Local M_ladd As Byte
Local M_hadd As Byte
Waddress = &HA0
Raddress = &HA1
M_ladd = Low(m_add)
M_hadd = High(m_add)
I2cstart 'generate start
I2cwbyte Waddress 'slave adsress
I2cwbyte M_hadd
I2cwbyte M_ladd 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Raddress 'slave address (read)
I2crbyte Value , Nack 'read byte
I2cstop 'generate stop
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' System Keyboard routines
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Keyboard scan routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub Chk_ky()
If Keypress = 1 Then
Debounce Incsw , 0 , Inc_sw , Sub
Debounce Decsw , 0 , Dec_sw , Sub
Debounce Selsw , 0 , Sel_sw , Sub
Debounce Modsw, 0 , Mod_sw, Sub
If Run = 1 then
Select case Mtrdirec
Case is = 0:
Spdlsb = User_sel
Spdmsb = 0
Call Rmcs220_speed
Case is = 1:
Spdlsb = 1
Spdmsb = User_sel
Call Rmcs220_speed
End select
End if
Keypress = 0
Enable Int0
End If
End Sub
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Incsw routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Inc_sw:
If User_sel < Rng_max Then
User_sel = User_sel + 1
End If
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Decsw routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Dec_sw:
If User_sel > Rng_min Then
User_sel = User_sel - 1
End If
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Selsw routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sel_sw:
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Modsw routine
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Mod_sw:
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' System Interrupts
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' INT0 Interrupt
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Kybisr:
Keypress = 1
Disable Int0
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Serial Interrupt
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Srlisr:
Rxbyte = Udr
Srlint = 1
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Timer0 Interrupt
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Tmr0isr:
Incr Micsecs
If Micsecs >= 10 then
Micsecs = 0
Incr Milsecs
if Milsecs >= 1000 then
Milsecs = 0
Incr Secs
If Secs >= 60 then
Secs = 0
Incr Mins
If Mins >= 60 then
Mins = 0
Incr Hrs
If Hrs >= 23 then
Hrs = 0
End if
End If
End If
End If
End If
Load Timer0, 100
Return |