Programming without a computer

 

What we need is a device which can be program without a computer and it should be portable, small and multipurpose. Also it should work with 5Volt.

Here is the plan, we program pic micro controller to execute instructions on external eeprom. And we program eeprom using the same circuit. To program eeprom, we use switches in the circuit. So, we can enter instructions by hand to control behavior of our circuit. That’s what I needed in my childhood… YES!!! “Programming without a computer

I used series of external eeproms(up to 8). So, I can use multiple programs on each eeprom.

Program used in PIC Micro controller is a Virtual Machine.  It reads two byte (one for operation code and one for value) from eeprom and executes it. Then move to next two byte.

Output of this circuit is 8 LED indicators which are connected to PORTB of micro controller. You can use them to do whatever you want.

When programming, write the instructions on paper, translate it to 1 and 0. Enter it using switches. And BOOM!!!

There are many embedded virtual machines for micro controllers on the internet. But they were not designed to program by hand. That’s why I used my own type of virtual machine.

Finished Circuit

Following image is the implementation of the device. It consist two eeprom which is enough for now.

circuit

Circuit Diagram

diagram

Virtual Machine Source code

Virtual machine was coded using C language to get some degree of portability. You’ll have to change device initialization code if you are using different type of micro controller.

I used “mikroC Pro for PIC” compiler to build the hex file.

You can download the source code from here. (mirror)

Instruction Set

Instruction format:  operation value

Example:  port0 255

In Binary: 0000 0001  1111 1111

Each instruction is 2 byte long. Fixed size instructions used to make programmer life easy. (Jumping is easy since each instruction size is same)

Virtual machine has 10 registers. They were indexed as 0,1,2,3…9 and named as A,B,C,D…J

Maximum address space is 256 since address size is 8 bits.

No function call support since absence of stack implementation.

Hex

Binary

Operation

Description

0x00 0000 0000 reset restarts virtual machine (ignore value)
0x01 0000 0001 port0 puts given value into port0
0x02 0000 0010 port0r puts value in register into port0
0x03 0000 0011 delay delay value in milliseconds
0x04 0000 0100 jmp jump to specific address
0x05 0000 0101 copya copy value of register A into given register
0x06 0000 0110 copyb copy value of register B into given register
0x07 0000 0111 copyc copy value of register C into given register
0x08 0000 1000 copyd copy value of register D into given register
0x09 0000 1001 copye copy value of register E into given register
0x0A 0000 1010 copyf copy value of register F into given register
0x0B 0000 1011 copyg copy value of register G into given register
0x0C 0000 1100 copyh copy value of register H into given register
0x0D 0000 1101 copyi copy value of register I into given register
0x0E 0000 1110 copyj copy value of register J into given register
0x0F 0000 1111 mova copy given value into register A
0x10 0001 0000 movb copy given value into register B
0x11 0001 0001 movc copy given value into register C
0x12 0001 0010 movd copy given value into register D
0x13 0001 0011 move copy given value into register E
0x14 0001 0100 movf copy given value into register F
0x15 0001 0101 movg copy given value into register G
0x16 0001 0110 movh copy given value into register H
0x17 0001 0111 movi copy given value into register I
0x18 0001 1000 movj copy given value into register J
0x19 0001 1001 inc increase value of given register by one
0x1A 0001 1010 dec decrease value of given register by one
0x1B 0001 1011 add add value of register A and given register and put result into register A
0x1C 0001 1100 sub subtract value of register A and given register and put result into register A
0x1D 0001 1101 mul multiply value of register A and given register and put result into register A
0x1E 0001 1110 is0 go to next instruction if given register value is zero. Else, one after next instruction
0x1F 0001 1111 equ compare register A and given value. go to next instruction if equal.Else, one after next instruction
0x20 0010 0000 equr compare register A and given register. go to next instruction if equal. Else, one after next instruction
0x21 0010 0001 lsthan compare register A and given value. go to next instruction if register A less than given value. Else, one after next instruction
0x22 0010 0010 lsthanr compare register A and given register. go to next instruction if register A less than given register. Else, one after next instruction
0x23 0010 0011 grthan compare register A and given value. go to next instruction if register A greater than given value. Else, one after next instruction
0x24 0010 0100 grthanr compare register A and given register. go to next instruction if register A greater than given register. Else, one after next instruction
0x25 0010 0101 lshift left shift register A by given value and put result into register A
0x26 0010 0110 lshiftr left shift register A by given register and put result into register A
0x27 0010 0111 rshift right shift register A by given value and put result into register A
0x28 0010 1000 rshiftr right shift register A by given register and put result into register A
0x29 0010 1001 not invert given value and put result into register A
0x2A 0010 1010 notr invert value of given register and put result into register A
0x2B 0010 1011 and do bitwise AND operation with given value and register A and put result into register A
0x2C 0010 1100 andr do bitwise AND operation with given register and register A and put result into register A
0x2D 0010 1101 or do bitwise OR operation with given value and register A and put result into register A
0x2E 0010 1110 orr do bitwise OR operation with given register and register A and put result into register A
0x2F 0010 1111 rpjmp relative positive jump by given number of instructions
0x30 0011 0000 rnjmp relative negative jump by given number of instructions

 

How To Assemble A Program

Take a paper and write down the program using operation codes with their addresses.

Example:

00           port0     255         ; set PORTB value HIGH

02           delay     200         ; delay 200ms

04           port0     0              ; set PORTB value LOW

06           delay     200         ; delay 200ms

08           jmp        0              ; jump to address 0

Translate those operation codes & values to binary using instruction set table.

0000 0001            1111 1111

0000 0011            1100 1000

0000 0001            0000 0000

0000 0011            1100 1000

0000 0100            0000 0000

Now you have assembled program. Let’s enter it to the device!

How To Enter A Program

Power on the device, hold Store button and press Reset button. LEDs will blink to indicate that you are in programming mode. Select the eeprom by using + or button and press Store button. Now LEDs will turn off and you are ready enter the program.

Use + or button to get desired binary pattern and then press Store.

Do the same for second part and press Store. LEDs will blink to indicate that data is writing to the eeprom.

Do the same procedure for all bytes in your program.

Hit Reset button.

(There is no way to correct mistakes if you accidentally press Store button. You’ll have to reprogram from the beginning.)

 

Further Improvements

You can have access to entire ports of micro controller if you use separate circuit to program eeproms.

You can speed up the virtual machine by using assembly code instead of C.

If you have any questions please mail to ruchira66@gmail.com

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: