Introduction to COSMAC 1802 I/O Operations
COSMAC 1802 I/O Operations allow us to get data from an input port, and write data to an output port. In this case, I’m using the 1802 membership card. On the 1802 Membership Card, we use Port 4 for both the switches and the lights. In this section, we’ll cover how to read these switches and write them to the outputs (LED’s).
There are several ways that we can do this. First, we’ll take a look at how to do this in Assembly Language using the actual processor instructions. After that, we’ll explore how to do this in BASIC3 that comes with the most popular ROM for the Elf Membership Card.
I/O Operations in Assembly
Write the Code
Let’s take a look at how we would read the switches, and write these switches to the output. In this case, we’ll do this in Assembly. I have the ELF Membership Card with the ROM at 8000H. My RAM begins at 0000H. You can simply change the ORG statement in the code if your RAM is set to HIGH. I’m using the A18 Assembler to produce the Intel Hex file that we’ll upload. Another way to enter the code is through the front panel switches.
Let’s take a look at the code:
R4: EQU 4 ; Register 4 ORG 0100H ;Program Starts at 0100H START: LDI 03 ; These four lines set up PHI R4 ; The storage Location LDI 00 ; to 0300H. We must do this PLO R4 ; Each scan, or R4 will Increment SEX R4 ; Set X to Register 4 INP 4 ; Get Switches, store to R4 OUT 4 ; Get Output from R4 BR START ; Restart END
I like to start off by setting R4 Equal to 4. That way, I can use R4 to clarify when I’m using a register in the code. After that, we’ll set the ORG to 0100H. I’m doing this for two reasons. First, my RAM is in LOW memory. Secondly, I’m not overwriting my jump statement at 0000H that allows me to get back into the ROM.
At the start of the logic, we set up our storage location for Register 4. We simply load 03 into the high address, and 00 into the low address. Our storage location will be 0300 in memory.
Next, we set X to point to Register 4. Keep in mind, this in turn, points to memory cell 0300. With the INPut statement, we get our switches from port 4, and store them to the memory cell pointed to by the register that X points to. Likewise, our OUTput instruction will get data from the memory cell pointed to by the register pointed to by X (0300), and send this data to our lights. The output register is also on Port 4.
After that, we start our program over in a continuous loop.
Assemble the Code
Assemble the code (be sure you have output in Intel Hex format) Boot to our ROM Monitor on the COSMAC. Press “L” to Load your code.
Paste the Intel Hex file into your terminal. Be sure you have character, and linefeed delays set up. Mine are at 250 each, which is slow, but reliable.
Here is my output from the Intel Hex file for ORG 0100H:
After that, we’ll type “R0100” to run the program at 0100H.
COSMAC 1802 I/O Operations in BASIC
The ROM Chip I purchased also has BASIC3 on it. To get into BASIC, I simply boot to the monitor at 8000H. Next, press B to get into BASIC, and we’ll do a Cold boot.
Let’s type in the program as follows:
In Line #10, we set A equal to the value of our switches, which is on port 4. The first operand is 0, and the second operand is the port number. If the first operand is a value other than zero, then it will send that value to port 1. Since we are not using port 1, we’ll leave this first value at zero.
In line 20, we send the value of A to port 4. Again the first operand sends a value to port 1, and since we are not using that, we’ll leave this at zero. The second operand is the port number, which is 4 for the MC. The third operand is the value that we are sending to port 4. Remember that A is equal to the value of our switches. So basically, we are just sending the value of the switches to our LED’s.
Line 30 gives us a way to exit the program. If all switches are on at the same time, then the decimal value is 255. The program ends.
Summary of COSMAC 1802 I/O Operations
In short, the IN and OUT commands give us a way to interface with the real world. We can load the switches into memory for user input, and our logic can take action based on this user input. The OUT instruction allows us to inform the operator of what is going on in the processor’s memory. Additionally, we can use the OUT instruction to control things in the real world such as a pump or motor.
For more information, visit the COSMAC Category Page!
— Ricky Bryce