Code Sharing
๐ Lesson 1 - Getting Startedโ
Three-color LED - Sequential Execution to Endโ
- Mnemonic Form
- Instruction Form
000 JT 0000 0010
001 JT 0000 0011
002 JT 0000 0012
003 JS 0000 0000
000 41 0000 0010
001 41 0000 0011
002 41 0000 0012
003 0F 0000 0000
Three-color LED - Loop Execution - Adjust Color at Runtimeโ
- Mnemonic Form
- Instruction Form
000 JT 0000 0010
001 JT 0000 0011
002 JT 0000 0012
003 ZY 0000 0000
000 41 0000 0010
001 41 0000 0011
002 41 0000 0012
003 0E 0000 0000
Three-color LED - 1s Delay - Register Increment - Color Combinationโ
- Mnemonic Form
- Instruction Form
000 FZ 0010 0001
001 ZJ 0010 0001
002 YS 0001 0001
003 SS 0010 0001
004 ZY 0000 0001
000 10 0010 0001
001 12 0010 0001
002 02 0001 0001
003 13 0010 0001
004 0E 0000 0001
๐ Lesson 2 - Sensors & Controlโ
PWM Control LED Brightnessโ
- Mnemonic Form
- Instruction Form
000 FZ 0000 03E8
001 FZ 002A 0000
002 FZ 002B 0080
003 FZ 002C 0100
004 ZJ 002A 0010
005 ZJ 002B 0005
006 ZJ 002C 0002
007 XYZ 002C 0001
008 ZY 0000 0004
000 10 0000 03E8
001 10 002A 0000
002 10 002B 0080
003 10 002C 0100
004 12 002A 0010
005 12 002B 0005
006 12 002C 0002
007 05 002C 0001
008 0E 0000 0004
Explore Sound-controlled Lightโ
- Mnemonic Form
- Instruction Form
000 FZ 0000 1000
001 FZ 0025 0001
002 AD 0000 002A
003 AD 0001 002D
004 DYZ 2A00 0010
005 ZY 0000 0002
010 TZ 0001 0012
011 ZY 0000 0002
012 CD 007F 7F7F
013 YS 0005 0001
014 CD 0000 0000
015 ZY 0000 0002
000 10 0000 1000
001 10 0025 0001
002 AD 0000 002A
003 AD 0001 002D
004 04 2A00 0010
005 0E 0000 0002
010 0B 0001 0012
011 0E 0000 0002
012 E4 007F 7F7F
013 02 0005 0001
014 E4 0000 0000
015 0E 0000 0002
Indoor Temperature Monitoringโ
- Mnemonic Form
- Instruction Form
000 FZ 000C 0CBC
001 RFZ 0000 002E
002 XDZ 000C 0005
003 JT 0000 0010
004 ZY 0000 0000
005 JT 0000 0012
006 ZY 0000 0000
000 10 000C 0CBC
001 11 0000 002E
002 08 000C 0005
003 41 0000 0010
004 0E 0000 0000
005 41 0000 0012
006 0E 0000 0000
Simulate Indoor Lighting Circuitโ
- Mnemonic Form
- Instruction Form
000 FZ 0002 0001
001 FZ 0003 0000
002 DZ 3F02 0004
003 ZY 0000 0002
004 DZ 3F03 0006
005 ZY 0000 0004
006 DZ 0102 0008
007 ZY 0000 0010
008 FZ 0001 0000
009 CD 0000 0000
00A ZY 0000 0002
010 FZ 0001 0001
011 CD 0011 1111
012 ZY 0000 0002
000 10 0002 0001
001 10 0003 0000
002 06 3F02 0004
003 0E 0000 0002
004 06 3F03 0006
005 0E 0000 0004
006 06 0102 0008
007 0E 0000 0010
008 10 0001 0000
009 E4 0000 0000
00A 0E 0000 0002
010 10 0001 0001
011 E4 0011 1111
012 0E 0000 0002
Simulated Lucky Wheel Spinโ
- Mnemonic Form
- Instruction Form
000 DY 0000 0080
001 DY 0000 00B0
002 DY 0000 00A2
003 ZY 0000 0002
080 FZ 0000 0000
081 FZ 0001 0014
082 FZ 0002 0028
083 FZ 0003 003C
084 FZ 0004 0050
085 FZ 0005 0000
086 FZ 0006 0001
087 FZ 0007 0002
088 FZ 0011 0000
089 FZ 0012 0005
08A FH 0000 0000
090 XYZ 1112 0092
091 FH 0000 0000
092 DY 0000 00C0
093 DY 0000 00C0
094 SJS 0000 0000
095 CHU 0000 028F
096 DY 0000 00D0
097 DY 0000 00B0
098 ZJ 0011 0001
099 FH 0000 0000
0A2 DZ 3F06 00A4
0A3 ZY 0000 00A8
0A4 DZ 3F05 00A6
0A5 ZY 0000 00A4
0A6 DY 0000 0090
0A8 DZ 3F07 00AA
0A9 FH 0000 0000
0AA FZ 0011 0000
0AB FH 0000 0000
0B0 FZ 0028 0210
0B1 YXTC 8080 2000
0B2 FZ 0028 FFFF
0B3 SC 0000 0000
0B4 YS 00C8 0000
0B5 FH 0000 0000
0C0 CD 00FF 0000
0C1 YS 00C8 0000
0C2 CD 00FF FF00
0C3 YS 00C8 0000
0C4 CD 0000 FF00
0C5 YS 00C8 0000
0C6 CD 00FF 00FF
0C7 YS 00C8 0000
0C8 CD 0000 00FF
0C9 YS 00C8 0000
0CA FH 0000 0000
0D0 DYZ 0001 00D3
0D1 CD 00FF 0000
0D2 FH 0000 0000
0D3 DYZ 0002 00D6
0D4 CD 00FF FF00
0D5 FH 0000 0000
0D6 DYZ 0003 00D9
0D7 CD 0000 FF00
0D8 FH 0000 0000
0D9 DYZ 0004 00DC
0DA CD 00FF 00FF
0DB FH 0000 0000
0DC CD 0000 00FF
0DD FH 0000 0000
000 0C 0000 0080
001 0C 0000 00B0
002 0C 0000 00A2
003 0E 0000 0002
080 10 0000 0000
081 10 0001 0014
082 10 0002 0028
083 10 0003 003C
084 10 0004 0050
085 10 0005 0000
086 10 0006 0001
087 10 0007 0002
088 10 0011 0000
089 10 0012 0005
08A 0D 0000 0000
090 05 1112 0092
091 0D 0000 0000
092 0C 0000 00C0
093 0C 0000 00C0
094 1F 0000 0000
095 2D 0000 028F
096 0C 0000 00D0
097 0C 0000 00B0
098 12 0011 0001
099 0D 0000 0000
0A2 06 3F06 00A4
0A3 0E 0000 00A8
0A4 06 3F05 00A6
0A5 0E 0000 00A4
0A6 0C 0000 0090
0A8 06 3F07 00AA
0A9 0D 0000 0000
0AA 10 0011 0000
0AB 0D 0000 0000
0B0 10 0028 0210
0B1 58 8080 2000
0B2 10 0028 FFFF
0B3 55 0000 0000
0B4 02 00C8 0000
0B5 0D 0000 0000
0C0 E4 00FF 0000
0C1 02 00C8 0000
0C2 E4 00FF FF00
0C3 02 00C8 0000
0C4 E4 0000 FF00
0C5 02 00C8 0000
0C6 E4 00FF 00FF
0C7 02 00C8 0000
0C8 E4 0000 00FF
0C9 02 00C8 0000
0CA 0D 0000 0000
0D0 04 0001 00D3
0D1 E4 00FF 0000
0D2 0D 0000 0000
0D3 04 0002 00D6
0D4 E4 00FF FF00
0D5 0D 0000 0000
0D6 04 0003 00D9
0D7 E4 0000 FF00
0D8 0D 0000 0000
0D9 04 0004 00DC
0DA E4 00FF 00FF
0DB 0D 0000 0000
0DC E4 0000 00FF
0DD 0D 0000 0000
Main Program (000-003)โ
| Line | Instruction | Description |
|---|---|---|
| 000 | DY 0000 0080 | Call register initialization subroutine starting at line 080 |
| 001 | DY 0000 00B0 | Call screen display subroutine (circle+number) starting at line 0B0 |
| 002 | DY 0000 00A2 | Call lottery judgment loop subroutine starting at line 0A2 |
| 003 | ZY 0000 0002 | Jump back to line 002, continuous lottery loop |
Register Initialization (080-08A)โ
| Line | Instruction | Description |
|---|---|---|
| 080 | FZ 0000 0000 | R00 = 0, temporary storage for random number |
| 081 | FZ 0001 0014 | R01 = 0x14, write value 20 |
| 082 | FZ 0002 0028 | R02 = 0x28, write value 40 |
| 083 | FZ 0003 003C | R03 = 0x3C, write value 60 |
| 084 | FZ 0004 0050 | R04 = 0x50, write value 80 |
| 085 | FZ 0005 0000 | R05 = 0, constant for button comparison |
| 086 | FZ 0006 0001 | R06 = 1, constant for button comparison |
| 087 | FZ 0007 0002 | R07 = 2, constant for button comparison |
| 088 | FZ 0011 0000 | R11 = 0, prize counter (cumulative lottery rounds) |
| 089 | FZ 0012 0005 | R12 = 5, less-than jump threshold (for lottery round limit) |
| 08A | FH 0000 0000 | Initialization complete, return to main program |
Lottery Loop Control (090-099)โ
| Line | Instruction | Description |
|---|---|---|
| 090 | XYZ 1112 0092 | If R11 < R12 (lottery count less than 5 rounds), jump to line 092 |
| 091 | FH 0000 0000 | Lottery round limit reached, return to caller |
| 092 | DY 0000 00C0 | Call color light rotation subroutine starting at line 0C0 (visual transition) |
| 093 | DY 0000 00C0 | Call color light rotation again (extend visual effect) |
| 094 | SJS 0000 0000 | Generate random number, store in R00 |
| 095 | CHU 0000 028F | R00 = R00 รท 0x028F, scale random number to target range |
| 096 | DY 0000 00D0 | Call prize level judgment subroutine starting at line 0D0 |
| 097 | DY 0000 00B0 | Call screen display subroutine at line 0B0 (display current result) |
| 098 | ZJ 0011 0001 | R11 = R11 + 1, increment lottery counter |
| 099 | FH 0000 0000 | End of current subroutine, return |
Conditional Judgment and State Switching (0A2-0AB)โ
| Line | Instruction | Description |
|---|---|---|
| 0A2 | DZ 3F06 00A4 | Compare R06 with button value, jump to 0A4 if condition met |
| 0A3 | ZY 0000 00A8 | Unconditional jump to line 0A8 (state A processing path) |
| 0A4 | DZ 3F05 00A6 | Compare R05 with button value, jump to 0A6 if condition met |
| 0A5 | ZY 0000 00A4 | Jump back to line 0A4 (state hold) |
| 0A6 | DY 0000 0090 | Call lottery loop subroutine starting at line 090 |
| 0A8 | DZ 3F07 00AA | Compare R07 with button value, jump to 0AA if condition met |
| 0A9 | FH 0000 0000 | State judgment complete, return to main program |
| 0AA | FZ 0011 0000 | Reset R11 = 0, clear lottery counter |
| 0AB | FH 0000 0000 | Return to main program |
Screen Display: Circle + Formatted Number (0B0-0B5)โ
| Line | Instruction | Description |
|---|---|---|
| 0B0 | FZ 0028 0210 | Set drawing foreground color R28 = 0x0210 |
| 0B1 | YXTC 8080 2000 | Draw filled circle at screen coordinates (0x80, 0x80) with radius 0x2000 |
| 0B2 | FZ 0028 FFFF | Set drawing foreground color R28 = 0xFFFF (to clear/overwrite previous number) |
| 0B3 | SC 0000 0000 | Formatted output of R00 register value to screen |
| 0B4 | YS 00C8 0000 | Delay 200 ms |
| 0B5 | FH 0000 0000 | Display subroutine complete, return |
Color Light Rotation Effect (0C0-0CA)โ
| Line | Instruction | Description |
|---|---|---|
| 0C0 | CD 00FF 0000 | WS2812B LED color change: Red ON (R=FF, G=00, B=00) |
| 0C1 | YS 00C8 0000 | Delay 200 ms |
| 0C2 | CD 00FF FF00 | LED color change: Yellow ON (R=FF, G=FF, B=00) |
| 0C3 | YS 00C8 0000 | Delay 200 ms |
| 0C4 | CD 0000 FF00 | LED color change: Green ON (R=00, G=FF, B=00) |
| 0C5 | YS 00C8 0000 | Delay 200 ms |
| 0C6 | CD 00FF 00FF | LED color change: Pink ON (R=FF, G=00, B=FF) |
| 0C7 | YS 00C8 0000 | Delay 200 ms |
| 0C8 | CD 0000 00FF | LED color change: Blue ON (R=00, G=00, B=FF) |
| 0C9 | YS 00C8 0000 | Delay 200 ms |
| 0CA | FH 0000 0000 | Color light rotation subroutine complete, return |
Prize Level Judgment (0D0-0DD)โ
| Line | Instruction | Description |
|---|---|---|
| 0D0 | DYZ 0001 00D3 | If random number R00 > R01, jump to line 0D3 (not 1st prize) |
| 0D1 | CD 00FF 0000 | 1st Prize: LED Red ON (highest prize) |
| 0D2 | FH 0000 0000 | Return |
| 0D3 | DYZ 0002 00D6 | If R00 > R02, jump to line 0D6 (not 2nd prize) |
| 0D4 | CD 00FF FF00 | 2nd Prize: LED Yellow ON |
| 0D5 | FH 0000 0000 | Return |
| 0D6 | DYZ 0003 00D9 | If R00 > R03, jump to line 0D9 (not 3rd prize) |
| 0D7 | CD 0000 FF00 | 3rd Prize: LED Green ON |
| 0D8 | FH 0000 0000 | Return |
| 0D9 | DYZ 0004 00DC | If R00 > R04, jump to line 0DC (not 4th prize) |
| 0DA | CD 00FF 00FF | 4th Prize: LED Pink ON |
| 0DB | FH 0000 0000 | Return |
| 0DC | CD 0000 00FF | 5th Prize: LED Blue ON |
| 0DD | FH 0000 0000 | Return |
Joystick-Controlled Servo (PCA9685)โ
Connect the joystick to an AD channel and control servo position through the PCA9685 module. The analog value from the joystick is mapped to the servo PWM channel.
- Mnemonic Form
- Instruction Form
000 FZ 0001 000C
001 AD 0000 0000
002 RCHU 0000 0001
003 JIA 0000 0066
004 FZ 0002 0003
005 WPWM 0002 0000
006 ZY 0000 0000
000 10 0001 000C
001 AD 0000 0000
002 1D 0000 0001
003 2A 0000 0066
004 10 0002 0003
005 EC 0002 0000
006 0E 0000 0000
| Line | Instruction | Description |
|---|---|---|
| 000 | FZ 0001 000C | Set scaling coefficient for joystick-to-servo angle mapping |
| 001 | AD 0000 0000 | Read analog value from AD channel 0 (joystick X-axis) into R00 |
| 002 | RCHU 0000 0001 | Divide AD value by R01 to get reduced angle value |
| 003 | JIA 0000 0066 | Add offset 0x66 (servo midpoint angle) |
| 004 | FZ 0002 0003 | Set R02 = 3, specifying PCA9685 PWM channel 3 |
| 005 | WPWM 0002 0000 | Write R00 value to PCA9685 PWM channel specified by R02 |
| 006 | ZY 0000 0000 | Return to program start, continuously detect joystick position |
Seven-Segment Display Decimal Counterโ
Display incrementing decimal numbers from 0 on the seven-segment display through register value encoding.
- Mnemonic Form
- Instruction Form
000 FZ 0001 0001
001 BMQD 0100 0000
002 QF 0000 0000
003 SS 0000 0001
004 ZJ 0001 0001
005 YS 0001 0001
006 ZY 0000 0001
000 10 0001 0001
001 30 0100 0000
002 16 0000 0000
003 13 0000 0001
004 12 0001 0001
005 02 0001 0001
006 0E 0000 0001
| Line | Instruction | Description |
|---|---|---|
| 000 | FZ 0001 0001 | Initialize display value R01 = 1 (starting from number 1) |
| 001 | BMQD 0100 0000 | Convert low 8 bits of R01 to seven-segment encoding, result in R00 |
| 002 | QF 0000 0000 | Bitwise NOT of encoding result (for common-anode display) |
| 003 | SS 0000 0001 | Send R00 value to seven-segment display |
| 004 | ZJ 0001 0001 | R01 = R01 + 1, prepare next number to display |
| 005 | YS 0001 0001 | Delay to allow number observation |
| 006 | ZY 0000 0001 | Jump back to line 001, continue displaying next number |
๐ Small Fanโ
Individual Pin Output Level Controlโ
- Mnemonic Form
- Instruction Form
000 JT 0000 0010
001 DK 0000 0011
002 YS 0005 0001
003 DK 0000 0010
004 JT 0000 0011
005 YS 0001 0001
006 DK 0000 0011
007 JS 0000 0000
000 41 0000 0010
001 42 0000 0011
002 02 0005 0001
003 42 0000 0010
004 41 0000 0011
005 02 0001 0001
006 42 0000 0011
007 0F 0000 0000
Bitwise Pin Output Level Controlโ
- Mnemonic Form
- Instruction Form
000 JT 0000 0010
001 YS 0005 0001
002 JT 0000 0011
003 YS 0001 0001
004 DK 0000 0010
005 DK 0000 0011
006 JS 0000 0000
000 41 0000 0010
001 02 0005 0001
002 41 0000 0011
003 02 0001 0001
004 42 0000 0010
005 42 0000 0011
006 0F 0000 0000
Button-Controlled Small Fanโ
- Mnemonic Form
- Instruction Form
000 FZ 0025 0080
001 DK 0000 0010
002 TZ 0000 0005
003 DK 0000 0011
004 ZY 0000 0002
005 JT 0000 0011
006 ZY 0000 0002
000 10 0025 0080
001 42 0000 0010
002 0B 0000 0005
003 42 0000 0011
004 0E 0000 0002
005 41 0000 0011
006 0E 0000 0002
One-Button Toggle Small Fanโ
- Mnemonic Form
- Instruction Form
000 FZ 0002 0001
001 FZ 0003 0000
002 DZ 3F02 0004
003 ZY 0000 0002
004 DZ 3F03 0006
005 ZY 0000 0004
006 DZ 0102 0008
007 ZY 0000 0010
008 FZ 0001 0000
009 DK 0000 0010
00A ZY 0000 0002
010 FZ 0001 0001
011 JT 0000 0010
012 ZY 0000 0002
000 10 0002 0001
001 10 0003 0000
002 06 3F02 0004
003 0E 0000 0002
004 06 3F03 0006
005 0E 0000 0004
006 06 0102 0008
007 0E 0000 0010
008 10 0001 0000
009 42 0000 0010
00A 0E 0000 0002
010 10 0001 0001
011 41 0000 0010
012 0E 0000 0002
๐ Value Mappingโ
Control Fan Speed or LED Brightness with Analog Inputโ
- Mnemonic Form
- Instruction Form
000 FZ 0001 0005
001 AD 0000 0000
002 SKIP 0000 0000
003 SKIP 0000 0000
004 RCHU 0000 0001
005 RFZ 002A 0000
006 ZY 0000 0000
000 10 0001 0005
001 AD 0000 0000
002 00 0000 0000
003 00 0000 0000
004 1D 0000 0001
005 11 002A 0000
006 0E 0000 0000
PWM Control: Joystick-Controlled Fan Speed Using Full Rangeโ
- Mnemonic Form
- Instruction Form
000 FZ 0001 0005
001 AD 0000 0000
002 JIAN 0000 09A0
003 CHENG 0000 0002
004 RCHU 0000 0001
005 RFZ 002A 0000
006 ZY 0000 0000
000 10 0001 0005
001 AD 0000 0000
002 2B 0000 09A0
003 2C 0000 0002
004 1D 0000 0001
005 11 002A 0000
006 0E 0000 0000
๐ Instruction Setโ
Conditional Jump 0x09 Exampleโ
- Mnemonic Form
- Instruction Form
000 FZ 0000 0000
001 FZ 0005 0008
002 ZJ 0000 0001
003 DYZ 0005 0010
004 XYZ 0005 0020
005 DZ 0005 0030
006 YS 03E8 0000
007 ZY 0000 0002
010 JT 0000 0013
011 ZY 0000 0002
020 JT 0000 0012
021 ZY 0000 0002
030 JT 0000 0011
031 ZY 0000 0002
000 10 0000 0000
001 10 0005 0008
002 12 0000 0001
003 04 0005 0010
004 05 0005 0020
005 06 0005 0030
006 02 03E8 0000
007 0E 0000 0002
010 41 0000 0013
011 0E 0000 0002
020 41 0000 0012
021 0E 0000 0002
030 41 0000 0011
031 0E 0000 0002
๐ Subroutine Callโ
Indoor Noise Detection Systemโ
- Mnemonic Form
- Instruction Form
000 FZ 0001 0BB0
001 FZ 0002 1300
002 AD 0000 0000
003 DYZ 0002 0010
004 DYZ 0001 0020
005 CD 0000 FF00
006 ZY 0000 0002
010 DY 0000 0040
011 DY 0000 0040
012 ZY 0000 0002
020 DY 0000 0030
021 DY 0000 0030
022 ZY 0000 0002
030 CD 0000 FF00
031 YS 01C4 0000
032 CD 00FF FF00
033 YS 01C4 0000
034 FH 0000 0000
040 CD 00FF 0000
041 YS 0001 0001
042 CD 00FF FF00
043 YS 0001 0001
044 CD 00FF 00FF
045 YS 0001 0001
046 FH 0000 0000
000 10 0001 0BB0
001 10 0002 1300
002 AD 0000 0000
003 04 0002 0010
004 04 0001 0020
005 E4 0000 FF00
006 0E 0000 0002
010 0C 0000 0040
011 0C 0000 0040
012 0E 0000 0002
020 0C 0000 0030
021 0C 0000 0030
022 0E 0000 0002
030 E4 0000 FF00
031 02 01C4 0000
032 E4 00FF FF00
033 02 01C4 0000
034 0D 0000 0000
040 E4 00FF 0000
041 02 0001 0001
042 E4 00FF FF00
043 02 0001 0001
044 E4 00FF 00FF
045 02 0001 0001
046 0D 0000 0000
๐ Community Library Smart Access Control Systemโ
A complete smart access control system for community libraries with:
- Two-button control: Button A for entering, Button B for exiting
- Capacity limit: Max 10 people
- LED indicator: Green when space available, Red when full
- Gate control: Servo opens/closes automatically
- Digital display: Shows current person count
Register Mapโ
| Register | Purpose |
|---|---|
| R02 | Servo channel select (constant = 1) |
| R03 | Servo 0ยฐ position (constant = 0x0066) |
| R04 | Servo 90ยฐ position (constant = 0x0133) |
| R05 | Button state: not pressed (constant = 0) |
| R06 | Button A pressed (constant = 1) |
| R07 | Button B pressed (constant = 2) |
| R11 | Current person count (0-10) |
| R12 | Max capacity (constant = 10) |
| R28 | Display color configuration |
Subroutine Overviewโ
| Address | Name | Description |
|---|---|---|
| 0x080 | Init | Register initialization |
| 0x090 | EnterCount | Increment count when entering |
| 0x098 | ExitCount | Decrement count when exiting |
| 0x0A2 | EnterButton | Monitor button A (enter request) |
| 0x0A8 | ExitButton | Monitor button B (exit request) |
| 0x0B0 | Display | Show current count on screen |
| 0x0C0 | LEDControl | Set LED color based on capacity |
| 0x0D0 | GateAction | Open and close the gate |
- Mnemonic Form
- Instruction Form
================== Main Program (000-004) ==================
000 DY 0000 0080 Initialize registers
001 DY 0000 00B0 Display initial count (0)
002 DY 0000 00C0 Update LED color
003 DY 0000 00A2 Monitor button inputs
004 ZY 0000 0001 Loop back to update display
================== Register Initialization (080-088) ==================
080 FZ 0002 0001 R02 = 1 (servo channel select)
081 FZ 0003 0066 R03 = 0x0066 (servo 0ยฐ position)
082 FZ 0004 0133 R04 = 0x0133 (servo 90ยฐ position)
083 FZ 0005 0000 R05 = 0 (button not pressed)
084 FZ 0006 0001 R06 = 1 (button A pressed)
085 FZ 0007 0002 R07 = 2 (button B pressed)
086 FZ 0011 0000 R11 = 0 (initial person count)
087 FZ 0012 000A R12 = 10 (max capacity)
088 FH 0000 0000 Return
================== Person Count - Enter (090-093) ==================
090 DZ 1112 0092 If R11 == R12 (full), jump to 092
091 ZJ 0011 0001 R11 += 1 (increment person count)
092 DY 0000 00D0 Call gate action (open & close)
093 FH 0000 0000 Return
================== Person Count - Exit (098-09A) ==================
098 ZJ 1011 0001 R11 -= 1 (decrement, min = 0)
099 DY 0000 00D0 Call gate action (open & close)
09A FH 0000 0000 Return
================== Button A - Enter Request (0A2-0A7) ==================
0A2 DZ 3F06 00A4 If R3F == R06 (A pressed), jump to 0A4
0A3 ZY 0000 00A8 Else check button B
0A4 DZ 3F05 00A6 Wait for button release (R3F == R05)
0A5 ZY 0000 00A4 Loop until released
0A6 DY 0000 0090 Process enter request
0A7 FH 0000 0000 Return
================== Button B - Exit Request (0A8-0AD) ==================
0A8 DZ 3F07 00AA If R3F == R07 (B pressed), jump to 0AA
0A9 FH 0000 0000 Return (no button pressed)
0AA DZ 3F05 00AC Wait for button release (R3F == R05)
0AB ZY 0000 00AA Loop until released
0AC DY 0000 0098 Process exit request
0AD FH 0000 0000 Return
================== Display Current Count (0B0-0B5) ==================
0B0 FZ 0028 0210 R28 = 0x0210 (configure display color)
0B1 YXTC 8080 2000 Draw filled circle (background)
0B2 FZ 0028 FFFF R28 = 0xFFFF (white text color)
0B3 SC 0000 1100 Format output R11 as 2-digit number at (0,0)
0B4 YS 00C8 0000 Delay 200ms
0B5 FH 0000 0000 Return
================== LED Color Control (0C0-0C4) ==================
0C0 XYZ 1112 00C3 If R11 < R12 (not full), jump to 0C3 (green)
0C1 CD 00FF 0000 Show RED (library full)
0C2 FH 0000 0000 Return
0C3 CD 0000 FF00 Show GREEN (space available)
0C4 FH 0000 0000 Return
================== Gate Action (0D0-0D3) ==================
0D0 WPWM 0002 0003 Open gate (servo to 90ยฐ)
0D1 YS 0001 0001 Wait 1 second
0D2 WPWM 0002 0004 Close gate (servo to 0ยฐ)
0D3 FH 0000 0000 Return
000 0C 0000 0080
001 0C 0000 00B0
002 0C 0000 00C0
003 0C 0000 00A2
004 0E 0000 0001
080 10 0002 0001
081 10 0003 0066
082 10 0004 0133
083 10 0005 0000
084 10 0006 0001
085 10 0007 0002
086 10 0011 0000
087 10 0012 000A
088 0D 0000 0000
090 06 1112 0092
091 12 0011 0001
092 0C 0000 00D0
093 0D 0000 0000
098 12 1011 0001
099 0C 0000 00D0
09A 0D 0000 0000
0A2 06 3F06 00A4
0A3 0E 0000 00A8
0A4 06 3F05 00A6
0A5 0E 0000 00A4
0A6 0C 0000 0090
0A7 0D 0000 0000
0A8 06 3F07 00AA
0A9 0D 0000 0000
0AA 06 3F05 00AC
0AB 0E 0000 00AA
0AC 0C 0000 0098
0AD 0D 0000 0000
0B0 10 0028 0210
0B1 58 8080 2000
0B2 10 0028 FFFF
0B3 55 0000 1100
0B4 02 00C8 0000
0B5 0D 0000 0000
0C0 05 1112 00C3
0C1 E4 00FF 0000
0C2 0D 0000 0000
0C3 E4 0000 FF00
0C4 0D 0000 0000
0D0 EC 0002 0003
0D1 02 0001 0001
0D2 EC 0002 0004
0D3 0D 0000 0000
Operation Flowโ
Start
โ
โผ
[Initialize Registers] โ Set constants, count = 0
โ
โผ
[Main Loop]
โ
โโโบ [Display Count] โ Show current count on screen
โ
โโโบ [LED Control] โ Green (count < 10) / Red (count == 10)
โ
โโโบ [Button A Check] โ If pressed and released:
โ โโโบ Not full โ count++ โ [Gate Action] โ open/close gate
โ โโโบ Full โ [Gate Action] โ open/close gate (still allow entry?)
โ
โโโบ [Button B Check] โ If pressed and released:
โ โโโบ count-- โ [Gate Action] โ open/close gate
โ
โโโบ Loop back to display
Key Featuresโ
- Debounce Handling: Each button waits for release before processing, preventing multiple triggers
- Capacity Control: Library max capacity is 10 people (R12 = 10)
- Visual Feedback: LED shows green when space available, red when full
- Automatic Gate: Servo opens (90ยฐ) for 1 second, then closes (0ยฐ)
- Digital Display: Shows current count as 2-digit number
Testing Scenariosโ
| Action | Expected Result |
|---|---|
| Press Button A (count=0) | Count becomes 1, gate opens then closes, LED green |
| Press Button A (count=9) | Count becomes 10, gate opens then closes, LED red |
| Press Button A (count=10) | Gate opens then closes, count remains 10, LED red |
| Press Button B (count=1) | Count becomes 0, gate opens then closes, LED green |
| Press Button B (count=0) | Count remains 0, gate opens then closes, LED green |