One of the SITCOM training computer prototypes
 SITCOM 85 Training Computer
 
  Let's get started

Lesson 1

Let's start our exploration of microprocessor programming with a simple program. We're going to flash some LEDs that are connected to ports A and B. We have seen this example on the programs page, but there we used the program to explain what an assembler will do for you. Now we are going to explain how the program actually works, and why it works the way it does.

But before we begin, let me explain two basic instruments of the Sitcom computer that we're going to use.

 
 

Software dashboard

Every microprocessor has a certain internal architecture. Our 8085 has a number of internal registers to work with. You can consider these registers to be the software dashboard, the controls and dials of the microprocessor. All programs use these, or at least some of these registers.

The 8085 dashboard
The 8058 software dashboard

The most important registers are the Accumulator (Short A or Accu), and the program counter (PC). Let me start with explaining the program counter:

The program counter is a 16-bit register, and holds a pointer to the memory location of the next instruction that will be executed. During reset this program counter is reset to a value of 0, which means that all our programs will start at address 0000H. After execution of an instruction the program counter will be incremented to point to the next instruction in memory. This incrementing will continue indefinitely, unless a special instruction alters the PC. Jump and Call instructions are typical instructions that can alter the program counter's value, and cause the program to continue from a totally different location in memory. We'll see lots of examples of these Jump and Call instructions in this and subsequent lessons.

The Accumulator is the most important working register in the 8085. All calculations are done with the Accumulator as origin and destination of the data. Being an 8-bit processor, the 8085's Accumulator can hold only 8 bits of data, restricting its math capabilities to numbers ranging from 0 to 255. Special tricks are required to perform more complex arithmetic.
We'll see excessive use of the Accumulator register in most of our programs.

Apart from the Accu and PC the 8085 has some more registers. The registers B, C, D, E, H and L are typically used as scratch pad registers. They are all 8 bits wide, and each of them can thus hold the same kind of values as the Accu. Typically one of these registers hold the second operand during dual operand operations, like addition and subtraction. The registers H and L can be concatenated to a 16-bit register to hold a pointer to point to some data in memory.
The SP register is the stack pointer. A stack is used to hold return addresses during subroutines or interrupt processing. It can also hold temporary data or can be used to pass parameters. The operation of the stack will be covered in one of the next lessons.
Finally there is the Flag register, which holds some important processor states. Flags are one-bit properties which are grouped into a normal 8-bit byte. The operation of flags is also covered in other lessons.

 
 

Input & Output

Every computer needs some form of Input and Output (in short I/O). Input signals affect the behaviour of the program, while output signals are used to indicate the internal status of your program or control some actions based on the input status.

The basic form of Sitcom has one device for input and output, the 8255 chip (not counting the optional DL1414 displays). This chip has a total of 24 lines, that can be used as digital input or output. All of these lines are at our disposal on the I/O connector.
The 8255 is a very simple chip, which makes it easy to understand. It has 3 so called I/O ports of 8 bits each, port A, B and C.
Ports A and B are identical and can each be used either as an 8-bit input or an 8-bit output port. Unfortunately it is not possible to use a mix of inputs and outputs on these two ports.
Port C is a bit different. It also has 8 bits to play with, but this time we can split it to be half input and half output if we want. So port C can be an 8-bit input port, an 8-bit output port, or a 4-bit input and a 4-bit output port.

All 3 ports can be written to and read from using the 8085 I/O instructions. Each port has its own I/O address. Port A has I/O address 000H, port B has I/O address 001H, and port C has I/O address 002H.
Writing to an I/O address will store the 8-bit data in the output latch. These data will only be presented on the output lines of the particular port if it was selected to be an output. Writing to an input port has no effect.
Reading from an I/O address will give you an 8-bit byte of data. It depends of the port's direction what data you read from the port. Reading from an input port will give you an exact copy of the data present at the inputs at the moment of the read instruction. Reading from an output port will give you the current status of the output latch.

A 4th I/O address on the 8255 is reserved as control register. This register mainly determines the direction of each of the I/O ports. It is also used to select special tricks, but these will not be covered (yet). You can consult the 8255 data sheet to learn about the special features of the 8255 if you like.

8255 Control Register
8255 Control register

The table above shows you the 8255 control register, which is addressed by the I/O address 003H on the basic Sitcom.

  • Bit 7 must be "1" to select the programming mode of the 8255. Only in this mode we can change the direction of the I/O ports.
  • Bits 6 and 5 are both set to "0", which selects mode 0 for port A and the upper half of port C. Other modes are beyond the scope of this lesson.
  • Bits 4 and 3 select the data direction for port A and the upper half of port C respectively. A "1" will change the port to input mode, while a "0" will make it an output.
  • Bit 2 is set to "0", which selects mode 0 for port B and the lower half of port C. Mode 1 is beyond the scope of this lessen.
  • Bits 1 and 0 select the data direction for port B and the lower half of port C respectively. A "1" will change the port to input mode, while a "0" will make it an output.

Please note that after reset all ports are switched to input mode.

Warning:
No document I have seen describing the 8255 mentions the fact that all outputs are initialized to "0" when the mode register is written to. So no matter what the output latches contained previously, their contents are cleared to "0" once the control port is written to.
I had to learn the hard way, when smoke came out of my EPROM programmer because a low signal shorted the 25V programming voltage each time the direction of one of the I/O ports was changed.

 
  Continue Lesson 1 - A first attempt to flash some LEDs
 
  [Home] [Latest News] [Essentials] [Hardware] [The Build] [Programs] [Projects] [Downloads] [Submissions]
 
  Made in the UK