Skip to main content

External devices

Instructions in this category are used to determine which peripheral or functions are enabled or disabled.

E.g. Using corresponding instructions to set duty cycles of PWM output pins, enable/disable specific functions such as temperature sensor and real time clock modules.

0xC0 Activation Switches: Peripheral and Modules

Enable/Disable peripherals in bitwise. Peripheral and functional modules are listed below:

bitFunciton
0ADC Conversion
1Environment Sensor
2Real Time Clock
3Colour Sensor
4External PWM Generator
5IMU
6Full Colour LED
7~11N/A reserved
INST_ACTIVATE_MODULESHexOP-0OP-1
Activate AD Conversion, PWM Generator and RTCC000000015

The example above configures the 12 bits with a hexadecimal number 0015, the correspoding binary value is:

(0015)16=(0000  0001  0101)2(0015)_{16}=(0000\;0001\;0101)_{2}

Indicating bit-4, bit-2 and bit-0 are enabled as described in the description of the instruction above.

info
OP/sOPRangeRemark
OP-00000Ignored
OP-10000~0FFFbitwise switches
tip
  • R28 is status register of peripheral enables.

0xC1 Activation Switch: Analog-Digital Conversion

Enable or disable analog-to-digital conversion (ADC).

tip

Check the corresponding bit in R28 for AD conversion status. Once enabled, the result of AD conversion will be updated in R24, R25, R26 and R27.

INST_ACTIVATE_ADSHexsOP00sOP01OP-1
Enable AD ConversionC100010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xC2 Activation Switch: Inertial Measurement Unit

Enable or disable inertial measurement unit module.

tip

Check the corresponding bit in R28 for IMU data. Once enabled, the measurement result of accelerometer will be updated in R29, R2A, R2B; the measurement result of gyroscope will be stored in R2C, R2D, R2E.

INST_ACTIVATE_IMUHexsOP00sOP01OP-1
Enable IMU sensorC200010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xC3 Activation Switch: Humidity/Temperature Sensor

Enable or disable humidity sensor BME280.

tip

Check the corresponding bit in R28 for BEM280 sensor. Current temperature and humidity are stored in R2F and R30 respectively.

INST_ACTIVATE_BMEHexsOP00sOP01OP-1
Enable BMP280/BME280C300010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xC4 Activation Switch: Colour Detection Sensor

Enable or disable colour detection sensor.

tip

Check the corresponding bit in R28 for colour detection sensor. When enabled, the detected colour components R, G and B will be updated in R31, R32 and R33.

INST_ACTIVATE_TCSHexsOP00sOP01OP-1
Enable colour sensorC400010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xC5 Activation Switch: External PWM Generator

Enable or disable external PWM generator module.

tip

Check the corresponding bit in R28 for external PWM generator module. Once enabled, instructions for configuring PWM channel and duty cycles are activated.

INST_ACTIVATE_PCAHexsOP00sOP01OP-1
Enable external PWM generatorC500010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xCB Activation Switch: Real Time Clock (RTC) Module

Enable or disable real time clock module.

tip

Check the corresponding bit in R28 for RTC module,

INST_ACTIVATE_DS1307HexsOP00sOP01OP-1
Enable RTCC800010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xCC Activation Switch: Full Colour LED

Enable or disable the control of full colour LEDs.

tip

Check the corresponding bit in R28 for full colour LEDs control.

INST_ACTIVATE_WS2812BHexsOP00sOP01OP-1
Enable full colour LED controlCC00010000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100Disable module
01Enable module
OP-10000Ignored

0xDD~0xDF Marks: Opcodes As Data (experimental)

Mark the current instruction line as data storage (experimental).

INST_DATA_LINEHexOP-0OP-1
Instruction is ignoredDD~DFABCDBEEF
info
OP/sOPValue/RangeRemark
OP-00000Ignored
OP-10000Ignored

0xE0 Declare Input Keys in Run-Time

At run time, when a program is running, declare the 6 user input keys as extra inputs. The declaration terminates when the program is stopped.

caution

When the input keys are declared, program debugging needs additional + combo keys to start.

INST_USE_BUTTONS_IN_PROGHexOP-0OP-1
Declare user keys in run timeE000000000
info
OP/sOPValue/RangeRemark
OP-00000Ignored
OP-10000Ignored

0xE3 Configuration:Set Date/Time

Set date and time of the DS1307 real time clock module using values in 6 continuous registers, with year, month, date, hour, minute and second.

tip

Current date and time are shown on page 3 on the secondary display, activation switch of RTC must be enabled to update.

INST_SET_DATE_TIMEHexsOP00sOP01OP-1
Use 6 registers to set date and time, starting from R0AE3000A0000

For instance, values stored in R0A~R0F are:

RegisterValue/Range
R0A07E4
R0B0004
R0C0004
R0D000A
R0E0000
R0F0000

Date and time of the RTC clock will be set to 2020-04-04 10:00:00.

info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100~3FRegister Index
OP-10000Ignored

0xE4 Configuration:Set Colour of a LED

Set colour of one WS2812B LED with an index.

INST_WS2812B_SET_COLORHexsOP00sOP01sOP10sOP11
Set LED 00 to orange colourE400FF8000
info
OP/sOPValue/RangeRemark
sOP0000~0FIndex of target LED
sOP0100~FFRed 0-255
sOP1000~FFGreen 0-255
sOP1100~FFBlue 0-255

0xE5 Configuration: Set Colour for Multiple LEDs

Set colour of multiple WS2812B LED in batch mode.

INST_WS2812B_REGx_SET_COLORHexsOP00sOP01sOP10sOP11
set multiple LEDs' colour using high-byte of 3 registers in series for R,G and B respectively E531010002
info
OP/sOPValue/RangeRemark
sOP0000-3FStart of register index
sOP0100Use low-byte of each register
01Use high-byte of each register
sOP1000 - 0FLED Index
sOP1101 - 0Fnumber of LEDs to set

In the example above, OP01 is 01, meaning that the high-byte of registers are used. Suppose values in R31~R33 are 0x1521, 0x8377 and 0xFF00, then the LEDs are set to colour 0x1583FF, start from LED 00 (included), two LEDs are rendered with the chosen colour.

0xE6 Configuration: Dimming Mode of Full Colour LEDs

Set all LEDs to one of the following modes: turned off, turned on with set colour, breathing with set colour, turned on with all white.

caution

Before using E6 to set , ``

INST_WS2812B_OP_SET_MODEHexsOP00sOP01OP-1
Set LEDs to breathing modeE600020000
info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100全灭
01当前颜色全亮
02当前颜色呼吸灯
03白色全亮
OP-10000Ignored

0xE8 Play a Tone

Play a tone from the preset three (high, mid, low) octaves.

INST_MELODYHexOP-0OP-1
Play a mid-tone SiE8000E0007
info
OP/sOPValue/RangeRemark
OP-001~07Low tone Do~Si
08~0EMid tone Do~Si
0F~15High tone Do~Si
00Rest
OP-10000Sixty-fourth note
0001Thirty-second note
0002Dotted thirty-second note
0003Sixteenth note
0004Dotted sixteenth note
0005Eighth note
0006Dotted eighth note
0007Quarter note
0008Half note
0009Whole note

0xEB Configuration: external PWM generator

Choose PWM channels (0-15) in a bitwise way, set the chosen channels high-time with a value.

INST_PCA9685_CHANNEL_REGB_REGVHexsOP00sOP01sOP10sOP11
Use the value in R00 as channel selections,set the chosen channels with the value stored in R02EB00000002

sOP01 points to R00 for channel selection. Suppose the stored value is 0087, in binary it is:

(0087)16=(0000  0000  1000  0111)2(0087)_{16}=(0000\;0000\;1000\;0111)_{2}

Bit 0, 1, 2 and 7 are '1', so channel 0, 1, 2 and 7 are selected.

sOP11 points to R02 for high-time, suppose the stored value is 0800, in decimal it is:

(0800)16=(2048)10(0800)_{16}=(2048)_{10}

The range of high-time is [0, 4095], corresponding to [0%, 100%] in duty cycle. Therefore 0800 or 2048 is about 50% duty cycle.

tip

For details of PCA9685 chip and the definition of duty cycle please refer to the official datasheet.

The JoyKit configures its PCA9685 chip to 50Hz (20ms period), each full cycle contains 4096 levels.

info
OP/sOPValue/RangeRemark
sOP0000Ignored
sOP0100~3FRegister index for channel selection
sOP1000Ignored
sOP1100~3FRegister index for high-time