While I believe I understand some of the library usage, I have a question about this code line, what does it do?
Code: Select all
optoencoder_gpioDriverInit(T_OPTOENCODER_P(@_MIKROBUS1_GPIO))
Code: Select all
'
'Example for Opto_Encoder Click
'
' Date : Feb 2018.
' Author : MikroE Team
'
'Test configuration PIC :
'
' MCU : P18F87K22
' Dev. Board : EasyPIC PRO v7
' PIC Compiler ver : v7.1.0.0
'
'---
'
'Description :
'
'The application is composed of three sections :
'
'- System Initialization - Initializes PWM pin and INT pin as INPUT.
'- Application Initialization - Initializes Driver init and opto encoder init.
'- Application Task - (code snippet) - Detects the change of step and logs to usb uart number of stepped steps.
'
program Click_Opto_Encoder_PIC
include Click_Opto_Encoder_types
include Click_Opto_Encoder_config
dim
newStep as int16_t
oldStep as int16_t
text as char[256]
sub procedure systemInit()
mikrobus_gpioInit(_MIKROBUS1, _MIKROBUS_INT_PIN, _GPIO_INPUT)
mikrobus_gpioInit(_MIKROBUS1, _MIKROBUS_PWM_PIN, _GPIO_INPUT)
mikrobus_logInit(_LOG_USBUART, 9600)
mikrobus_logWrite("--- System Inti --- ", _LOG_LINE)
Delay_ms(100)
end sub
sub procedure applicationInit()
optoencoder_gpioDriverInit(T_OPTOENCODER_P(@_MIKROBUS1_GPIO))
optoencoder_init()
end sub
sub procedure applicationTask()
newStep = optoencoder_getPosition()
if ((oldStep <> newStep)) then
IntToStr(newStep, text)
mikrobus_logWrite(" Step: ", _LOG_TEXT)
mikrobus_logWrite(text, _LOG_LINE)
oldStep = newStep
end if
end sub
main :
oldStep = 0
systemInit()
applicationInit()
while (1)
applicationTask()
wend
end.
Code: Select all
'
'Example for Opto_Encoder Click
'
program Click_Opto_Encoder_PIC_test
include Click_Opto_Encoder_types
include Click_Opto_Encoder_config
dim
newStep, oldStep as int16_t
sub procedure systemInit()
dim Rotary_Encoder_A as sbit at RC0_bit
Rotary_Encoder_B as sbit at RC1_bit
Delay_ms(100)
end sub
sub procedure applicationInit()
optoencoder_gpioDriverInit(T_OPTOENCODER_P(@_MIKROBUS1_GPIO))
optoencoder_init()
end sub
sub procedure applicationTask()
newStep = optoencoder_getPosition()
if ((oldStep <> newStep)) then
' do something here
oldStep = newStep
end if
end sub
main :
oldStep = 0
systemInit()
applicationInit()
while (1)
applicationTask()
wend
end.