Skip to main content

Instruction Examples

This page provides practical instruction tables for programming reference.

Instruction Table Format​

FieldDescription
LINEProgram line number, 3-digit hexadecimal address
OPCODEInstruction opcode, 2-digit hexadecimal value (e.g., 00, 01, FF)
OP-0First parameter (combining OP-00 + OP-01 as 16-bit value)
OP-1Second parameter (combining OP-10 + OP-11 as 16-bit value)
RemarkFunctional description
Format Notes
  • LINE: Program address, 3-digit hexadecimal, range 000 ~ FFF
  • OPCODE: Opcode, 2-digit hexadecimal (e.g., 00, 01, FF)
  • OP-0 / OP-1: Parameter values, 4-digit hexadecimal each
  • Unused parameters should be set to 0000
  • Program termination marker: OPCODE=0x0F, OP-0=0000, OP-1=0000

0x00 NOP - No Operation​

Do nothing, program counter moves on to next line. Can be used as a placeholder for future modifications.

LINEOPCODEOP-0OP-1Remark
0000000000000No operation, proceed to next line
0010000000000Reserved line for future modifications
0020000000000Reserved line for future modifications
0030F00000000Program termination

0x01 Set Digital Output​

Set digital output pins to HIGH or LOW. HIGH turns LED on, LOW turns LED off.

LINEOPCODEOP-0OP-1Remark
0000100000001Set DO0 HIGH
0010000000000No operation
0020100000000Set DO0 LOW
0030000000000No operation
0040100000009Set DO[3:0] to HIGH,LOW,LOW,HIGH
0050F00000000Program termination

0x02 Set Delay​

Set a delay before executing the next line. Unit can be millisecond, second, or minute.

LINEOPCODEOP-0OP-1Remark
0000100000001Set DO0 HIGH
0010203E80000Delay 1000 ms
0020100000000Set DO0 LOW
0030203E80000Delay 1000 ms
0040F00000000Program termination

0x03 Set Timer​

Set a down counter as timer. Register R23 is set to 0001 during countdown, reset to 0000 when done.

LINEOPCODEOP-0OP-1Remark
0000313880000Set 5000 ms timer
0010300000000Check R23 status
0020F00000000Program termination

0x04 Conditional Jump: Greater than Literal Value​

If value in R00 is greater than the given literal, jump to target line.

LINEOPCODEOP-0OP-1Remark
0001000000000Write 0000 to register R00
0010200010001Delay 1 second for viewing result
0021200000001Increment value in register R00 by 1
0030400080010Is R00 > 8? If yes, jump to line 010
0040500080020Is R00 < 8? If yes, jump to line 020
0050600080030Is R00 == 8? If yes, jump to line 030
0060203E80000Delay 1000 milliseconds
0070E00000001Return to line 001 for loop execution
0100100FF000CTurn on LED3 and LED2
0110E00000001Return to line 001 for loop execution
0200100FF0003Turn on LED1 and LED0
0210E00000001Return to line 001 for loop execution
0300100FF0006Turn on LED2 and LED1
0310E00000001Return to line 001 for loop execution

0x05 Conditional Jump: Less than Literal Value​

See 0x04 example above.


0x06 Conditional Jump: Equals Literal Value​

See 0x04 example above.


0x07 Conditional Jump: Greater than Register Value​

If value in R00 is greater than the value in specified register, jump to target line.

LINEOPCODEOP-0OP-1Remark
0001000000000Write 0000 to register R00
0011000050008Write 0008 to register R05
0021200000001Increment value in register R00 by 1
0030700050010Is R00 > R05? If yes, jump to line 010
0040800050020Is R00 < R05? If yes, jump to line 020
0050900050030Is R00 == R05? If yes, jump to line 030
0060203E80000Delay 1000 milliseconds
0070E00000002Return to line 001 for loop execution
0100100FF0008Turn on LED3
0110E00000001Return to line 001 for loop execution
0200100FF0004Turn on LED2
0210E00000001Return to line 001 for loop execution
0300100FF0002Turn on LED1
0310E00000001Return to line 001 for loop execution

0x08 Conditional Jump: Less than Register Value​

See 0x07 example above.


0x09 Conditional Jump: Equals Register Value​

See 0x07 example above.


0x0A Advanced Conditional Jump: Register Comparison​

Compare value in R00 with specified register, jump based on comparison result.

LINEOPCODEOP-0OP-1Remark
0001000000064Write 100 to R00
0011000000050Write 80 to R05
0020A000300050100
0030100000001Set DO0 HIGH
0040F00000000Program termination
Judge Codes
CodeCondition
01Equal (=)
02Not equal (≠)
03Greater than (>)
04Less than (<)
05Greater than or equal (≥)
06Less than or equal (≤)
07Is zero
08Is not zero

0x0B Advanced Conditional Jump: Digital Input​

Jump based on digital input signals on DI0-DI3 pins.

LINEOPCODEOP-0OP-1Remark
000250000000FConfigure lower 4 digital IO pins as input
0010BFF0D0010If four digital inputs are 0101, jump to line 010
0020E00000000Return to line 000 for re-evaluation
0030000000000NOP
0100100FF00F0Turn on LEDs on four output pins
0110F00000000Program termination

0x0C Call: Jump to Subroutine​

Call a subroutine at the specified line. Use 0x0D to return.

LINEOPCODEOP-0OP-1Remark
0000000000000NOP
0010C00100000Call subroutine at line 010
0020F00000000Program termination
0030000000000NOP
0040000000000NOP
0100100FF00FFTurn on all LEDs
0110C00200000Call subroutine at line 020
0120D00000000Return to caller at line 001
0200200010001Delay 1 second
0210100FF0000Turn off all LEDs
0220D00000000Return to caller at line 011

0x0D Return: Back from Subroutine​

Return from a subroutine called by 0x0C.

See 0x0C example above.


0x0E Unconditional Jump​

Jump to the specified line without any condition.

LINEOPCODEOP-0OP-1Remark
000250000000FConfigure lower 4 digital IO pins as input
0010BFF0D0010If four digital inputs are 0101, jump to line 010
0020E00000001Return to line 000 for re-evaluation
0030000000000NOP
0100100FF00F0Turn on LEDs on four output pins
0110F00000000Program termination

0x10 Write Value to Register​

Modify the value in the specified register.

LINEOPCODEOP-0OP-1Remark
00010001C03E8Write 03E8 to register R1C
0010000000000NOP
00213001C0000Output lower 8 bits of R1C to digital port
0030F00000000Program termination

0x11 Register Copy​

Copy value of one register to another.

LINEOPCODEOP-0OP-1Remark
00010001C03E8Write 03E8 to register R1C
00111001D001CCopy value of register R1C to R1D
00213001D0000Output lower 8 bits of R1D to digital port
0030F00000000Program termination

0x12 Increment/Decrement Register​

Increment or decrement register value, with optional overflow control.

LINEOPCODEOP-0OP-1Remark
00010001CFF00Write FF00 to register R1C
00112001C03E8Increment R1C by 03E8, no overflow allowed
00213001C0000Output lower 8 bits of R1C to digital port
0030200050001Delay 5 seconds
00412011C03E8Increment R1C by 03E8, overflow allowed
00513001C0000Output lower 8 bits of R1D to digital port
0060F00000000Program termination

0x13 Register Value to Digital Output​

Use the least 8 bits of a register as digital output value.

LINEOPCODEOP-0OP-1Remark
00010001C03E8Write 03E8 to register R1C
00111001D001CCopy value of register R1C to R1D
00213001D0000Output lower 8 bits of R1D to digital port
0030F00000000Program termination

0x14 Digital Input Value to Register​

Capture digital input values and save to a register.

LINEOPCODEOP-0OP-1Remark
00010002500FFConfigure all digital IO pins as input
00114001C0000Write digital input port value to register R1C
0020000000000NOP
0030E00000001Return to line 001 for loop execution

0x15 Bit Shift​

Shift bits in a register left or right, with optional circular mode.

LINEOPCODEOP-0OP-1Remark
0001000010001Write 1 to register R01
0011300010000Output value in R01 to register R01
0020200010001Delay 1 second
0031511010001Circular left shift R01 by 1 bit
0040E00000001Return to line 001 for loop execution

0x16 Bit Inversion​

Reverse all bits in a register.

See 0x19 example below.


0x17 Bitwise AND​

Bitwise AND of two registers, result stored in first register.

See 0x19 example below.


0x18 Bitwise OR​

Bitwise OR of two registers, result stored in first register.

See 0x19 example below.


0x19 Bitwise XOR​

Bitwise XOR of two registers, result stored in first register.

LINEOPCODEOP-0OP-1Remark
000100025000FConfigure lower 4 digital IO pins as input
0011000078009Write 8009 to register R07
002100009FF00Write FF00 to register R09
0030BFF0E0010If digital input is 0x0E, jump to line 010
0040BFF0D0020If digital input is 0x0D, jump to line 020
0050BFF0B0030If digital input is 0x0B, jump to line 030
0060BFF070040If digital input is 0x07, jump to line 040
0070E00000000Return to program start for loop execution
0101600070000Invert all bits in R07
0110E00000000Return to program start for loop execution
0201700070009R07 AND R09, result stored in R07
0210E00000000Return to program start for loop execution
0301800070009R07 OR R09, result stored in R07
0310E00000000Return to program start for loop execution
0401900070009R07 XOR R09, result stored in R07
0410E00000000Return to program start for loop execution

0x1A Addition​

Add two registers, result stored in first register.

See 0x1D example below.


0x1B Subtraction​

Subtract two registers, result stored in first register.

See 0x1D example below.


0x1C Multiplication​

Multiply two registers, result stored in first register.

See 0x1D example below.


0x1D Division​

Divide two registers, result stored in first register.

LINEOPCODEOP-0OP-1Remark
000100025000FConfigure lower 4 digital IO pins as input
0011000060020Write 0020 to register R06
0021000081234Write 1234 to register R08
0030BFF0E0010If digital input is 0x0E, jump to line 010
0040BFF0D0020If digital input is 0x0D, jump to line 020
0050BFF0B0030If digital input is 0x0B, jump to line 030
0060BFF070040If digital input is 0x07, jump to line 040
0070E00000000Return to program start for loop execution
0101A00080006Addition, result 0x1254 stored in R08
0110E00000000Return to program start for loop execution
0201B00080006Subtraction, result 0x1214 stored in R08
0210E00000000Return to program start for loop execution
0301C00080006Multiplication, result 0x4680 stored in R08
0310E00000000Return to program start for loop execution
0401D00080006Division, result 0x91 stored in R08
0410E00000000Return to program start for loop execution

0x1E Modulo​

Calculate remainder of two registers, result stored in first register.

LINEOPCODEOP-0OP-1Remark
0001000060020Write 0020 to register R06
0011000081234Write 1234 to register R08
0020200010001Delay 1 second for viewing R08 changes
0031E00080006Modulo calculation, result stored in R08
0040F00000000Program termination

0x1F Random Number​

Generate a random number and store it in the specified register.

LINEOPCODEOP-0OP-1Remark
0001F00050000Generate a random number in R05
0010200010001Delay 1 second
0020E00000000Return to program start for loop execution

0x20 Byte Recombination​

Recombine lower bytes of two registers, store in first register.

See 0x21 example below.


0x21 Byte Swap​

Swap higher and lower bytes of a register.

LINEOPCODEOP-0OP-1Remark
000100025000FConfigure lower 4 digital IO pins as input
0011000052450Write 2450 to register R05
002100006FF00Write FF00 to register R06
0030BFF0E0010If digital input is 0x0E, jump to line 010
0040BFF0D0020If digital input is 0x0D, jump to line 020
0050E00000000Return to program start for loop execution
0102000050006Recombine R05 and R06 lower bytes, store in R05
0110200010001Delay 1 second for viewing register result
0120E00000000Return to program start for loop execution
0202100050000Swap higher and lower bytes of R05
0210200010001Delay 1 second for viewing register result
0220E00000000Return to program start for loop execution

0x2A Addition with Literal​

Add a literal value to a register, result stored in register.

See 0x2D example below.


0x2B Subtraction with Literal​

Subtract a literal value from a register, result stored in register.

See 0x2D example below.


0x2C Multiplication with Literal​

Multiply a register by a literal value, result stored in register.

See 0x2D example below.


0x2D Division with Literal​

Divide a register by a literal value, result stored in register.

LINEOPCODEOP-0OP-1Remark
000100025000FConfigure lower 4 digital IO pins as input
0011000081234Write 1234 to register R08
0020BFF0E0010If digital input is 0x0E, jump to line 010
0030BFF0D0020If digital input is 0x0D, jump to line 020
0040BFF0B0030If digital input is 0x0B, jump to line 030
0050BFF070040If digital input is 0x07, jump to line 040
0060E00000000Return to program start for loop execution
0102A00080020Addition, result 0x1254 stored in R08
0110E00000000Return to program start for loop execution
0202B00080020Subtraction, result 0x1214 stored in R08
0210E00000000Return to program start for loop execution
0302C00080020Multiplication, result 0x4680 stored in R08
0310E00000000Return to program start for loop execution
0402D00080020Division, result 0x91 stored in R08
0410E00000000Return to program start for loop execution

0x2E Modulo with Literal​

Calculate remainder of a register divided by a literal value, result stored in register.

LINEOPCODEOP-0OP-1Remark
0000000000000No operation
0011000081234Write 1234 to register R08
0020200010001Delay 1 second for viewing R08 changes
0032E00080020Modulo calculation, result stored in R08
0040F00000000Program termination

0x30 Convert Register to BCD Code​

Convert the lower 8 bits of a register value to seven-segment display BCD code.

LINEOPCODEOP-0OP-1Remark
000C500010000Enable PCA9685 PWM signal generator
001C600010000Enable DS1307 RTC clock module
002303E000000Convert register R3E decimal to BCD code
003EA00000190Set PWM channel value to 0x0190 (range 0x0000-0x0FFF)
0041600000000Invert all bits in R00
005EA000000C8Set PWM channel value to 0x00C8 (range 0x0000-0x0FFF)
0060E00000002Return to line 002 for continued execution

0x32 Advanced Register Operations​

Perform various operations on register pairs.

LINEOPCODEOP-0OP-1Remark
00010000173E8Write 0x73E8 to R01
0011000021024Write 0x1024 to R02
0021000030000Write 0x0000 to R03
0033203000102R01 AND R02, result stored in R03
0043203010102R01 OR R02, result stored in R03
0053203020102R01 XOR R02, result stored in R03
0063203030102R01 + R02, result stored in R03
0073203040102R01 - R02, result stored in R03
0083203050102R01 × R02, result stored in R03
0093203060102R01 ÷ R02, result stored in R03
00A3203070102R01 × R02, result stored in R03
00B3200080102Write R02 value to R01, R03 not involved
00C32030B0102R01, R02 recombination, result stored in R03
00D32000C0100R01 high/low byte swap
00E32030D0102R01 ÷ R02 remainder, result stored in R03
00F0F00000000Program termination

0x55 Formatted Text Output​

Output values in a specified format to the screen at designated location.

LINEOPCODEOP-0OP-1Remark
000C300010000Enable temperature and humidity sensor
001110001002ECopy temperature value R2E to R01
002100028FFFFWrite 0xFFFF to R28 for color configuration
0035500000122Format and output R01 value with 2 decimal places at position (0,0)
0040203E80000Delay 1000 milliseconds
0051000280210Write 0x0210 to R28 for color configuration
0065A0000FFFFDraw a filled rectangle (0,0)-(255,255)
0070E00000000Write 0x0000 to R00

0x56 Display String​

Display characters from consecutive registers in specified format.

LINEOPCODEOP-0OP-1Remark
000C300010000Enable temperature and humidity sensor
0011000045465Write 0x5465 to R04
0021000056D70Write 0x6D70 to R05
0031000066572Write 0x6572 to R06
0041000076174Write 0x6174 to R07
0051000087572Write 0x7572 to R08
006100009653AWrite 0x653A to R09
007100028FFFFWrite 0xFFFF to R28 for color configuration
008562020040CDisplay string from R04 in specified format
0090203E80000Delay 1000 milliseconds
00A1000280210Write 0x0210 to R28 for color configuration
00B5A0000FFFFDraw a filled rectangle (0,0)-(255,255)
00C0E00000000Write 0x0000 to R00

0x57 Draw Circle​

Draw a hollow circle with specified center and radius.

See 0x5B example below.


0x58 Draw Filled Circle​

Draw a filled circle with specified center and radius.

See 0x5B example below.


0x59 Draw Rectangle​

Draw a hollow rectangle with specified diagonal vertices.

See 0x5B example below.


0x5A Draw Filled Rectangle​

Draw a filled rectangle with specified diagonal vertices.

See 0x5B example below.


0x5B Draw Line​

Draw a straight line between two specified points.

LINEOPCODEOP-0OP-1Remark
000100028001FWrite 0x001F to R028 for color configuration
0015720202000Draw a hollow circle
00210002807E0Write 0x07E0 to R028 for color configuration
0035870701000Draw a filled circle
004100028F100Write 0xF100 to R028 for color configuration
0055930305580Draw a hollow rectangle
00610002807FFWrite 0x07FF to R028 for color configuration
0075A10102020Draw a filled rectangle
008100028FFFFWrite 0xFFFF to R028 for color configuration
0095B60602020Draw a straight line
00A0E00000000Return to line 000

0xAD Drawing Shapes (Comprehensive)​

Comprehensive drawing program demonstrating various shapes.

LINEOPCODEOP-0OP-1Remark
000100028001FWrite 0x001F to R028 for color configuration
0015720202000Draw a hollow circle
00210002807E0Write 0x07E0 to R028 for color configuration
0035870701000Draw a filled circle
004100028F100Write 0xF100 to R028 for color configuration
0055930305580Draw a hollow rectangle
00610002807FFWrite 0x07FF to R028 for color configuration
0075A10102020Draw a filled rectangle
008100028FFFFWrite 0xFFFF to R028 for color configuration
0095B60602020Draw a straight line
00A0E00000000Return to line 000

0xC0 Activation Switches: Peripheral Modules​

Enable/Disable peripherals in bitwise mode.

LINEOPCODEOP-0OP-1Remark
000C00000085FEnable ADC module
0010F00000000Program termination
Peripheral Bit Values
BitPeripheral
0ADC Conversion
1Environment Sensor
2Real Time Clock
3Colour Sensor
4External PWM Generator
6Full Colour LED

0xC1 Activation Switch: ADC Module​

Enable or disable analog-to-digital conversion.

LINEOPCODEOP-0OP-1Remark
000C100010000Enable ADC module
001AD00010005Save AD channel 1 value to register R05
0020100FF0000Turn off all LEDs
003020005FF00Delay by milliseconds value in R05
0040100FF0000Turn on all LEDs
005020005FF00Delay by milliseconds value in R05
0060E00000001Return to line 001

0xC3 Activation Switch: Temperature and Humidity Sensor​

Enable temperature and humidity sensor and display readings.

LINEOPCODEOP-0OP-1Remark
000C300010000Enable temperature and humidity sensor
001110001002ECopy temperature value from R2E to R01
002100028FFFFWrite 0xFFFF to R28 for color configuration
0035500000122Format and output R01 with 2 decimal places
0041000280210Write 0x0210 to R28 for color configuration
0055A0000FFFFDraw a filled rectangle (0,0)-(255,255)
0060E00000000Write 0x0000 to R00

0xC4 Activation Switch: Colour Sensor​

Enable colour detection sensor and read RGB values.

LINEOPCODEOP-0OP-1Remark
000C400010000Enable colour sensor
001E531010001Use high 8 bits of R31-R33 as RGB values
0020E00000001Return to line 001 for loop execution

0xC8 Set On-board PWM Channel Duty Cycle​

0xC5 Activation Switch: External PWM Generator​

Enable external PWM generator and control PWM channels.

LINEOPCODEOP-0OP-1Remark
000C500010000Enable external PWM generator
001C100010000Enable ADC module
0021000000003Write 0x0003 to R0
0031000010019Write 0x0019 to R1
004AD00000002Assign AD channel 0 value to R02
0051D00020001R02 divided by R01, quotient
00612000200C8R02 value increases by 0x00C8
0070000000000No operation
008EA00000002Write R02 value to PWM channel
0090E00000002Return to line 002

0xC6 Activation Switch: RTC Clock Module​

Enable DS1307 RTC clock module and display time.

LINEOPCODEOP-0OP-1Remark
000C600010000Enable DS1307 RTC clock module
00113003E0000Display lowest 4 bits of R3E on LED
0020E00000001Return to line 001

0xC8 Set Onboard PWM Channel Duty Cycle​

Enable built-in PWM and set duty cycle.

LINEOPCODEOP-0OP-1Remark
000C000000000Enable built-in PWM, disable buzzer
001C8000103E8Set channel 1 PWM value to 1000
0020E00000001Return to line 001

0xE4 Set Colour of an LED​

Set colour of one WS2812B LED with RGB values.

LINEOPCODEOP-0OP-1Remark
000E400FF8000Set LED 0 RGB value, display orange
0010200010001Delay 1 second
002E400FF0000Set LED 0 RGB value, display red
0030200010001Delay 1 second
004E40000FF00Set LED 0 RGB value, display green
0050200010001Delay 1 second
006E4000000FFSet LED 0 RGB value, display blue
0070F00000000Program termination

0xE5 Read Colour Sensor​

Read RGB values from colour sensor.

LINEOPCODEOP-0OP-1Remark
000C400010000Enable colour sensor
001E531010001Use high 8 bits of R31-R33 as RGB values
0020E00000001Return to line 001 for loop execution

0xE8 Play a Tone​

Play a tone from preset three octaves.

LINEOPCODEOP-0OP-1Remark
000C000000800Switch to buzzer mode
001E8000F0001Thirty-second note, high Do
002E800000001Thirty-second rest
003E8000F0001Thirty-second note, high Do
004E800110001Thirty-second note, high Mi
005E800130001Thirty-second note, high Sol
0060F00000000Program termination
Tone Values
RangeOctave
01~07Low Do~Si
08~0EMid Do~Si
0F~15High Do~Si
00Rest
Note Duration Values
ValueDuration
0000Sixty-fourth note
0003Sixteenth note
0005Eighth note
0007Quarter note
0008Half note
0009Whole note

0xEA PCA9685 Register Channel and Value​

Write value to selected PCA9685 PWM channel.

LINEOPCODEOP-0OP-1Remark
000C500010000Enable external PWM generator
001C100010000Enable ADC module
0021000000003Write 0x0003 to R0
0031000010019Write 0x0019 to R1
004AD00000002Assign AD channel 0 value to R02
0051D00020001R02 divided by R01, quotient
00612000200C8R02 value increases by 0x00C8
0070000000000No operation
008EA00000002Write R02 value to PWM channel
0090E00000002Return to line 002
ParameterDescription
OP-0Specifies the register whose value is used to select channels by bit
OP-1Specifies the register whose value is used to set duty cycle
Special Note

Duty cycle is 12-bit, range 0000-0FFF. If R00 = 0x0003, channels 0 and 1 are configured. If R02 = 0x01FF, duty cycle ≈ 511/4095 ≈ 12.5%.