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

Original author: GClown25 (MIT License)
  • Transfer
  • Tutorial

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

The address space is divided into 16 pages with 16 instructions each. The instruction length is 8 bits, of which the four most significant are the command, and the four lower are the data:

To enter the programming mode, hold down the button 2, press the reset button, release it, then release the button 2. In the programming mode, sequentially sort the instructions in RAM by button 2. When moving to the next instruction, the LEDs for a split second show the current address. Button 1 allows you to make changes to the command and address as part of the current instruction. When moving to a new address with button 2, the instruction for the previous address is entered in the EEPROM. Having typed the program, you need to press the reset button, and there will be a transition from the programming mode to the program execution mode.

The list of commands:

0x0 - load a constant value into the doutB port
0x1 - the same, into the doutA port
0x2 - pause
0x3 - a relative unconditional jump back
0x4 - load a constant value into 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 the variable A (and B)
0x8 - set the highest nibble of the address for the instruction absolute unconditional jump
0x9 - produce absolute unconditional jump to a specified address
0xA, 0xB - acts as a cycle for: each time a command is executed, if the variable C (or D) is greater than zero, there is an absolute unconditional jump to a specified address, puff m the value of variable C (or D) decreases
0xC - skip the next instruction if the argument is a logical unit
0xD - function call to 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 written with instruction 0x50.

Example 1 - flasher:

Адрес Инструкция Комментарий
0     1f         Включить все светодиоды на порту doutA
1     28         Пауза 500 мс
2     10         Выключить все светодиоды на порту doutB
3     28         Пауза 500 мс
4     34         Относительный безусловный переход на -4 ячейки

Example 2 - binary counter:

Адрес Инструкция Комментарий
0     5B         DoutB = A
1     59         PWM1 = A
2     71         A++
3     28         Пауза 500 мс
4     34         Относительный безусловный переход на -4 ячейки

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

Адрес Инструкция Комментарий
Основной цикл:
0     10         DoutA = 0x0
1     d5         Вызов подпрограммы myWait
2     1f         DoutA = 0xf
3     d5         Вызов подпрограммы myWait
4     34         Относительный безусловный переход на -4 ячейки
Подпрограмма myWait:
5     64         A = Din
6     52         C = A
7     25         Пауза 50 мс
8     a7         for(C > 0; C--) jmp 7
9     e0         Возврат


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

Also popular now: