Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Let's say you had a rather simple and small microcontroller and had no interfacing, no computer, no debugger, compiler, or assembler. Could you write your code in assembly, convert it (manually) to machine code, and then apply power to the appropriate pins using a voltage source?

I understand you would need appropriate I/O and memory to really do anything, but if you were so inclined and had the time, could you do this? I guess, historically, how was this done when there was no computer/compiler/assembler to begin with? Feel free to link me to an outside resource. Thanks! :)

share|improve this question
2  
Have a look at the Altair 1. The front panel switches and manual machine programming were the only way of using it. –  pjc50 2 days ago
    
@pj50 He asked about a microcontroller, not a microprocessor. Microcontrollers run their code our flash which is not accessible without an interface of some sort. –  tcrosley 2 days ago
    
How many programmed units do you need? Many manufacturers will supply their micros pre-programmed with your code; however, this is not practical if you need less than a full reel. –  Oleg Mazurov yesterday
2  
Back in the 70s you would have built a panel of toggle switches and lights so you could enter the program. I never worked with one of the early microcontrollers, but worked with several different microprocessors, and that's how you did it, by default. And there was no fundamental difference between early microcontrollers and microprocessors other than the I/O capabilities and some of the details of how program memory was configured. –  Hot Licks yesterday
    
I'll leave this as a comment because I can't find the source for this story. I remember some time back a story of a kid who designed and built his own computer (just the CPU really) from transistors for a science fair purely based on his understanding of digital logic. He couldn't afford a computer at the time and programmed his creation via toggle switches (I think I remember the clock for the thing being just a button). One of the judges was so impressed that he bought the kid a computer. –  slebetman yesterday

11 Answers 11

up vote 28 down vote accepted

Could you write your code in assembly, convert it (manually) to machine code,

Yes!
Code can be written "out of your head" in binary, if you wish.
Long (long long) ago this is how I started using (then) microprocessors.
I and friends would write code in assembly language, compile it manually to machine code (something you can do "by inspection" after some practice) then enter it into the processor by various means. On one system we built we would set up the address on binary (on off) switches or use an auto increment feature of the processor, enter 8 data bits on binary switches and then press a "clock" switch to enter the data to memory.

The equivalent functionality could be achieved with even fewer switches on a modern microcontroller using serial SPI programming - see below.

... and then apply power to the appropriate pins using a voltage source?

Yes!
But it would be incredibly slow to do!
Many modern microcontrollers allow use of an "SPI" interface for programming.
This typically consists of input and output data lines and a "clock" line, and usually a reset line.

Many processors allow SPI clock and data to be "static" which means there is no limit on how long you can take to set up the data between bits. You could program such a processor using a data line and a clock line which were driven by manually operated switches. The clock line needs to be "bounce free" - you need to be able to set it high or low in a single transition per operation - so a minimum interface may need to include a Schmitt triggered gate. You may "get away with" just an RC delay and a push button switch, but a Schmitt triggered input is safer. The data line does not need to be bounce free as its state is only read at the clock edge.


MC6800:

From semi-fading memory (almost 40 years!)

LDI A, $7F ...... 86 7F ...... 1000 0110 0111 1111
STA, $1234...... B7 12 34 ... 1011 0111 0001 0010 0011 0100
LDI X, $2734... CE 27 34 ... 1100 1110 0010 0111 0011 0100
...

share|improve this answer
1  
+1 for mentioning the static design, allowing the clock to go all the way to DC. –  pericynthion yesterday
2  
This brings back memories. I actually learned entering Z80 code using buttons back in school. That was around 1990. My teacher insisted that learning programming the hard way is valuable. 25 years later I have to agree. –  Nils Pipenbrinck 22 hours ago
    
@NilsPipenbrinck I'm at this moment writing C code and applying lessons I first learned with Fortran :-) !!! - and which were then honed with embedded systems & assembly language. These lessons reduce the chance of errors by applying mental-typing to variable and port accesses which otherwise could do things which are allowed but not desired or useful. Assembler is the ultimate sharp weapon - a double ended sword with no hand guards. After that "higher level" languages seem less sharp :-). Z80 button entry acts similarly on your learning experiences ;-). –  Russell McMahon 20 hours ago
    
@Erbureth Thanks :-). Yes ffff for 1111 was obvious brain fade. ... was just "you get the idea" but completing line doesn't hurt. –  Russell McMahon 13 hours ago

Originally, in programmable machines, the programs were manually punched into paper tape or cards. Later they used a kind of typewriter to do the punching, and even later still the computers (as they had come to be known by then) could punch their own paper tape.

It was, literally, sitting there with a card and manually making holes in it.

enter image description here

Each column is an instruction or bit of data that is interpreted by the CPU's state machine to perform tasks.

Now if course it's all flash memory, and yes, getting the data in there in the first place normally needs a computer to do it. But that's not strictly 100% true.

After all, what does a computer and hardware programmer do but set the state of IO pins at the right times? So, if you are really masochistic enough you can build a system which allows you to send the right instructions to the microcontroller's programming pins in the right way to install some instructions into the flash memory for execution.

Maybe something involving lots of switches, some shift registers, a clock generator, etc.

I remember at college we had a new-fangled Z80 based programming system - a unit the size of a suitcase with a Z80, some small amount of RAM, a bunch of 7-segment LED displays, and a big row of switches. Program it by manually loading instructions into RAM using the switches.

share|improve this answer
    
The Z80 is not a valid example. He asked about a microcontroller, not a microprocessor. Microcontrollers run their code our flash which is not accessible without an interface of some sort. At least you did mention flash and a programming interface elsewhere in you answer. –  tcrosley 2 days ago
    
@tcrosley The Z80 was more for anecdotal purposes - illustrating how computers used to be programmed before Visual Studio took all the skills away. –  Majenko 2 days ago
    
While I'm unaware of any machines having been built to do so, it would not be difficult to add some circuitry to a card reader to program a microcontroller with code stored on a sequence of cards. Paper tape might be more practical, though. –  supercat 2 days ago
2  
I used to cut holes manually in those. It is only feasible in extreme circumstances (10pm, term papers due tomorrow, one mainframe run left, punch room lady left for the day). Programming the same mainframe from the front panel (couple years later) was actually faster. –  Oleg Mazurov yesterday
1  
@Majenko -- I've seen the reconstruction of Babbage's machine, and it definitely was not made from telephone equipment. Definitely noisy, though. –  Hot Licks 23 hours ago

You said "small microcontroller and had no interfacing, no computer, no debugger, compiler, or assembler.". Well you can get by without the computer, debugger, compiler, or assembler, but you have to have some sort of interface to connect with the microcontroller in order to load the program.

First of all, forget about any high level languages like C. Then the easiest way is to write your program in assembly language, but don't use the assembler to translate it to machine code. Instead, look up each of the assembly instructions in the programming manual, find their equivalent hex coding, and write that down.

You will have to allocate your own variables, so you can fill in the appropriate addresses in the operand portion of the instructions. Also forget about using the stack and heap, too much work. When done, you'll have a machine program that can be loaded directly into the flash memory of the microcontroller -- no linker needed either.

Because of the lack of external address and data busses on almost all microcontrollers (since they would take up too many pins which are needed by I/O ports and peripherals), virtually all microcontrollers are programmed via a special interface like this:

enter image description here

Normally the "programmer" on the left would be connected to a PC, which would download a machine file generated by a compiler/linker.

However if the programmer has a keyboard, like the one below:

enter image description here

then one can enter the hex codes for a manually generated program right into the programmer, and program the device without needing a compiler, linker, or PC which was what you were inquiring about. (The keyboard is also used for editing hex files, and generating checksums.)

Granted very few programmers have keyboards like this. This one would not be suitable for a hobbyist as it probably costs a couple thousand dollars.

This particular programmer programs parts before they are put onto a board; interfaces and sockets are available for several PICs and also Atmel AVRs among others.

share|improve this answer
4  
You have commented on various other answers re their invalidity, but this answer is arguably less valid than most you have commented on. He said " ... no interfacing, no computer, ...". At a minimum your solution is "a computer". What "no interfacing" means is moot. But, use some debounced switches on the SPI interface and you arguably have a solution. –  Russell McMahon yesterday
1  
@RussellMcMahon Who says there is a computer in the programmer? Many of them just use FPGAs (which could be replaced by discrete logic.) How are you going to program a microcontroller via an SPI interface, unless it has a bootloader? If so, how do you program the bootloader? –  tcrosley yesterday
2  
The essentially bootloader free standard low voltage serial programming interface on many (possibly most) microcontrollers uses a few lines in an essentially serial interface. MOSI MCLK (Vdd Gnd Reset) being utter minimum MISO if there is interaction. 3 switches (only one of which) needs to be bounce free) and an LED for MISO and "you are off". Very very very slowly. If an FPGA is allowed to not count as a "computer" then it would be no problem implementing many processor based systems. I suspect "no combinatorial logic" would met the spirit of his request. –  Russell McMahon yesterday

As a practical matter, something like toggling JTAG pins manually would be very error-prone. To input a program of any decent size would take thousands of toggles. But theoretically, it's possible.

If you're allowed to prepare the microcontroller in advance (or write a boot ROM for it), you could easily implement something like the external toggle switches used on early mainframes. If you allow external logic, you could even use a hex keypad to speed things up.

Finally, although it's not as common these days, you can buy a ROM-based microcontroller with custom code in it. You'd have to offer some money up front and guarantee a certain volume, but I've seen customers do it to save money on high-volume production. In that case, there would be no external signals needed to program the microcontroller at all. The code would be built into the physical layout of the chip.

Of course, you can also use a microcontroller that runs code out of an external memory interface, but that's cheating. :-)

share|improve this answer
2  
In fact, I built an Imsai 8800 "clone" in 1976/77 and would routinely program it in binary using the toggle switches. I had a boot-load sequence that was around 40- or 60-odd bytes (this was a lifetime ago!) which would read a papertape from my ASR-33 teletype and get me into a keyboard monitor. Before the teletype worked I would program the 8085 (one of the differences between my "clone" and the Imsai,) strictly in binary. But that was in parallel, with a row of switches. I've used a telegraph key to do serial encoding and it is REALLY error-prone, as Adam has stated. –  user6297 yesterday

Absolutely. In fact, the first microprocessor course I took (circa 87) used a Motorola 68000 board. We would work out the code in assembly, look up the hex for the assembly, and type the hex into a terminal to program the board. If you edited, you had to make sure the code you put in was shorter than the code you were replacing, and then buffer the rest with NOPs. If the coDE were longer, you would have to retype everything! We learned to add plenty of NOPs.

share|improve this answer
    
The 68000 was not a microcontroller. He asked about a microcontroller, not a microprocessor. Microcontrollers run their code our flash which is not accessible without an interface of some sort. –  tcrosley 2 days ago
5  
@tcrosley That's not strictly true. There are microcontrollers that require external ROM since they don't have any ROM or Flash of their own. What makes them a microcontroller isn't built in RAM or ROM, but built in peripherals (IO ports, UART, etc). –  Majenko yesterday
    
Very few though -- because of the I/O peripherals you just mentioned, very few have external address and data busses because they require two many pins. –  tcrosley yesterday

Absolutely. Once you have a binary format of the actual instructions (easy to do for well-specified instruction sets), all you need is to implement the programming protocol.

For example, take something small like an AVR Tiny 4. Section 14 details the programming interface including the protocol and physical layer. It's relatively simple and you just need a few buttons and pullup/down resistors to send/recieve a 1 or a 0. If you're feeling ambitious, add some LED's to read back the output.

The last remaining issue is if you can do it fast enough, which luckily* for the AVR Tiny 4 (section 16), it doesn't have any minimum frequency when it comes to programming it.

*note: as far as the datasheet specifies. This may differ in reality... I doubt anyone has tried programming it at mHz clock speeds.

Feel free to automate it as much/little of the process as desired. This is what most programming devices do anyways: automate the process.

share|improve this answer

By whatever means you input the program to the uC, you are "interfacing" with it, because that's what interfacing means. Even a bunch of switches you flip manually are an "interface".

So I will treat this question as "how do I interface to a uC with largely -mechanical- (as opposed to electronic) interfacing hardware, and in as cool a way as possible?"

To which my answer is, input the program as a piano roll. The piano roll "tracker bar" from a player piano basically gives you at least 65 (depending on format) bits that you can turn on and off independently based on perforations in the paper. The rest is exacting work with an exacto knife. But at least your program, once running, is (somewhat) permanently stored (unlike a flip-the-switches-manually approach).

share|improve this answer

Yes. The main issue may be interacting with the programming interface. If you have a plain address and data bus, things are a bit easier. Have you ever seen some of the really early computers? The programs are entered one instruction at a time into RAM with switches on the front.

share|improve this answer
    
He asked about a microcontroller, not a microprocessor. Microcontrollers run their code our flash which is not accessible without an interface of some sort. –  tcrosley 2 days ago
4  
@tcrosley - The early uCs didn't have flash. They either had RAM or ROM for program store. –  Hot Licks yesterday
    
@HotLicks Correct. And with just a few exceptions, these were all microprocessors, not microcontrollers. That was my point, not whether the program store was flash, or ROM, or PROM, or EPROM, or EEPROM. The point was whether the program store was on chip (microcontroller) or not (microprocessor). Even the 8048, Intel's first micvrocontroller introduced in 1977, had internal ROM. –  tcrosley yesterday
3  
@Tcrosley Who are you? And what have you done with the usually helpful and objectie tcrosley? :-) | His first observation was that you could interact with the programming interface - which will often but not always be valid. The "IF" re address and data bus is an IF. It applies to some large and borderline hybrid microcontrollers, but his original IF was fine enough (albeit hard and slow). –  Russell McMahon yesterday
2  
Trying to maintain a hard distinction between microprocessor and microcontroller is more pedantic than useful, especially when it's in a comment to every single reply. –  pjc50 yesterday

Digital Equipment's PDP-8 mincomputers of 40+ years ago had no automatic booting ability. Programs were usually loaded from punched paper tapes but the loader to load the paper tapes had to be manually entered on the front panel switches.

enter image description here

At Digital and PDP-8 customers' sites such as OEMs who used them as the embedded-controllers of the day, it wasn't uncommon for users to memorize the boot loaders and compete with one another for the fastest time taken to enter the boot loader into the machine. The machines used magnetic-core memories (hand strung in far-flung parts of the world, by ladies with tiny fingers, using needles and hair-fine wire).

enter image description here

Since magnetic memory contents is non-volatile the boot loaders survived a power-down and manual entry was only needed after initial assembly, the loader was wiped out by a program bug, or a program needed to use the loader's space.

share|improve this answer
    
Many years ago back when we had to trudge to school barefoot in the snow uphill both ways, the PDP-8 in our high school had to be booted by toggling in the bootloader from the front panel as you describe. None of the teachers knew much about the computer, including the one that was responsible for it. He thought up was 0 and 1 was down, so could never toggle in the bootloader. I'd arrange for the computer to crash when I was in english class so I'd be called out to restart the computer. I never told him about his up versus down misconception - it was much too useful to me. –  Olin Lathrop 7 hours ago

The answer is yes, you could program a micro controller without a computer,debugger, etc. What you would need would be to provide the various voltages, data, clock, and programming sequences specified by the uC manufacturer (not an easy job).

share|improve this answer

Not only is it possible to program a microcontroller without a computer, but you can actually purchase a computer today that is specifically designed to be programmed with hardware toggle switches. The kit is called a Membership Card, and it is a re-creation of the COSMAC Elf computer from the 1970's. The kit was described in a recent article in IEEE Spectrum magazine. It is also possible to program more recent versions of the Membership Card from a PC.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.