[Translation] Virtual 4-bit microcontroller with three-button programming and four switches

[Translation] Virtual 4-bit microcontroller with three-button programming and four switches




The proposed device emulates an abstract 4-bit microcontroller with an address space of 256 bytes on the ATmega4809 microcontroller, which can be programmed with three buttons and four switches.

The address space is divided into 16 pages with 16 instructions each. The length of the instruction is 8 bits, of which four older ones are a command, and four younger ones are data:



To enter the programming mode, hold button 2, press the reset button, release it, then release button 2. In programming mode, sequential search of instructions in RAM is done by button 2. When you go to the next instruction, the LEDs show the current address for a fraction of a second. With button 1 you can make changes to the command and address as part of the current instruction. When moving to a new address, button 2, the instruction for the previous address is entered into the EPROM. When you dial a program, you need to press the reset button, and the transition from programming mode to program execution mode occurs.

List of commands:

0x0 - load a constant value to the port doutB
0x1 - same to doutA port
0x2 - pause
0x3 - relative unconditional jump back
0x4 - load a constant value in the variable A
0x5 - load something with the value of the variable A
0x6 - load the value of something into the variable A
0x7 - perform arithmetic and logical operations with variable A (and B)
0x8 - set the most significant nibble of the address for the instruction of absolute unconditional jump 0x9 - make an absolute unconditional transition to the specified address
0xA, 0xB - acts as a for loop: every time the command is executed, if the variable C (or D) is greater than zero, an absolute unconditional jump to the specified address occurs, then the value of the variable C (or D) decreases
0xC - skip the next instruction if the argument is equal to a logical one
0xD - call the function at the specified address
0xE - return from the called function
0xF - set the address for virtual 4-bit RAM, the value stored at this address can be read with instruction 0x6E and write with instruction 0x50.

Example 1 - flasher:

  Address Instruction Comment
 0 1f Turn on all LEDs on doutA port
 1 28 Pause 500 ms
 2 10 Turn off all the LEDs on the doutB port
 3 28 Pause 500 ms
 4 34 Relative unconditional switch to -4 cells  

Example 2 - binary counter:


  Address Instruction Comment
 0 5B DoutB = A
 1 59 PWM1 = A
 2 71 A ++
 3 28 Pause 500 ms
 4 34 Relative unconditional switch to -4 cells  

Example 3 - flasher with adjustable speed (with subroutine):


  Address Instruction Comment
 Main loop:
 0 10 DoutA = 0x0
 1 d5 subroutine call myWait
 2 1f DoutA = 0xf
 3 d5 subroutine call myWait
 4 34 Relative unconditional switch to -4 cells
 Subroutine myWait:
 5 64 A = Din
 6 52 C = A
 7 25 Pause 50 ms
 8 a7 for (C & gt; 0; C--) jmp 7
 9 e0 Returns  

Scheme:







All files necessary for repetition (board, firmware, etc.) - by reference to the original. The source of inspiration for the design served as a close in terms of capabilities German TPS simulator .

Source text: [Translation] Virtual 4-bit microcontroller with three-button programming and four switches