Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Lesson 1: The Language of Microprocessors pps
MIỄN PHÍ
Số trang
137
Kích thước
400.2 KB
Định dạng
PDF
Lượt xem
1435

Lesson 1: The Language of Microprocessors pps

Nội dung xem thử

Mô tả chi tiết

Lesson 1: The Language of

Microprocessors

Most people think that computers are some kind of complicated device that is impossible

to learn and infinitely intelligent, able to think better than a person. The truth is much less

glamorous. A computer can only do what the programmer has told it to do, in the form of

a program. A program is just a sequence of very simple commands that lead the

computer to solve some problem. Once the program is written and debugged (you hardly

ever get it right the first time), the computer can execute the instructions very fast, and

always do it the same, every time, without a mistake.

And herein lies the power of a computer. Even though the program consists of very

simple instructions, the overall result can be very impressive, due mostly to the speed at

which the computer can process the instructions. Even though each step in the program is

very simple, the sequence of instructions, executing at millions of steps per second, can

appear to be very complicated, when taken as a whole. The trick is not to think of it as a

whole, but as a series of very simple steps, or commands.

Most microprocessors, or very small computers, (here after referred to simply as micro's)

have much the same commands or instructions that they can perform. They vary mostly

in the names used to describe each command. In a typical micro, there are commands to

move data around, do simple math (add, subtract, multiply, and divide), bring data into

the micro from the outside world, and send data out of the micro to the outside world.

Sounds too simple....it is.

A typical micro has three basic parts inside. They are the Program Counter, Memory, and

Input / Output. The Program Counter keeps track of which command is to be executed.

The Memory contains the commands to be executed. The Input / Output handles the

transfer of data to and from the outside world (outside the micro's physical package). The

micro we'll be using is housed inside a 40 pin package, or chip. There are many other

actual parts inside our micro, but too much, too soon, would be too confusing right now.

We will, however, learn about each and every single one.

A Simple Program

As stated before, a program is a sequence or series of very simple commands or

instructions. A real world example program might be the problem of crossing a busy

street.

Step 1: Walk up to the corner of the street and stop.

Step 2: Look at the traffic light.

Step 3: Is the light green for your direction of travel?

Step 4: If the light is red, goto step 2. (otherwise continue to step 5)

Step 5: Look to the left.

Step 6: Are there cars still passing by?

Step 7: If yes, goto step 5. (otherwise continue to step 8).

Step 8: Look to the right.

Step 9: Are there cars still passing by? (there shouldn't be any by now, but, you never

know!)

Step 10: If yes, goto step 8. (otherwise continue to step 11)

Step 11: Proceed across the street, carefully!!

Now this may seem childish at first glance, but this is exactly what you do every time you

cross a busy street, that has a traffic light (at least, I hope you do). This is also exactly

how you would tell a micro to cross the street, if one could. This is what I mean by a

sequence or series of very simple steps. Taken as a whole, the steps lead you across a

busy intersection, which, if a computer did it, would seem very intelligent. It is

intelligence, people are intelligent. A programmer that programmed these steps into a

micro, would impart that intelligence to the micro.

The micro would not, however, in this case, know what to do when it got to the other

side, since we didn't tell it. A person, on the other hand, could decide what to do next, at a

moments notice, without any apparent programming. In the case of a person, though,

there has been some programming, it's called past experiences.

Another program might be to fill a glass with water from a faucet.

Step 1: Turn on the water.

Step 2: Put the glass under the faucet.

Step 3: Look at the glass.

Step 4: Is it full?

Step 5: If no, goto step 3.(otherwise, continue to step 6)

Step 6: Remove the glass from under the faucet.

Step 7: Turn off the water.

This is a simpler program, with fewer steps, but it solves a problem, to fill a glass with

water. In a micro, the problems are different (they could be the same if you've made some

kind of servant robot), but the logical steps to solve the problem are similar, that is, a

series of very simple steps, leading to the solution of a larger problem.

Also notice that since the steps are numbered, 1 through 7, that is the order in which

they're executed. The Program Counter, in this case, is you, reading each line, starting

with 1 and ending with 7, doing what each one says. In a micro, the Program Counter

automatically advances to the next step, after doing what the current step says, unless a

branch, or jump, is encountered. A branch is an instruction that directs the Program

Counter to go to a specific step, other than the next in the sequence. The branch in this

example is step 5. Not only is this a branch, but it is a conditional branch. In other words,

based on whether the glass is full or not, the branch is taken, or not. A micro has both

branch and conditional branch instructions. Without this ability to reuse instructions, in a

sort of looping action, a solution would take many more steps, if it would be possible at

all.

The point of this lesson is to show how a simple set of instructions can solve a bigger

problem. Taken as a whole, the solution could appear to be more complicated than any of

the separate steps it took to solve it. Well that wasn't so tough, was it?

The most difficult problem to be solved in programming a micro is to define the problem

you are trying to solve. Sounds like some kind of play on words, but I assure you, it's not.

This is the Logical Thought Process I mentioned earlier. The mark of a good programmer

is one who has this ability. It is, in my humble opinion, a developed skill, coupled with

some talent, and a good understanding of the problem you're trying to solve. In most

cases, God has endowed you with the talent and the ability to reason, all you need do is

develop the skill of Problem Solving.

My email address is here and I would welcome your questions or comments as you

proceed through this course. Depending on the volume of mail I get, it may take a couple

of days or so for me to get back to you, but be assured, I will get back to you. I really do

want you to understand the information I'm presenting, and not being a professional

teacher, I might not always explain things to the satisfaction of everyone, but with your

patience, I'll do my best. My home page is http://www.hkrmicro.com/personal/index.html

Decimal Vs. Binary (and Hex)

Most people have learned to use the Decimal numbering system for counting and

calculations. But micros use a different system. It's called Binary. All numbering systems

follow the same rules. Decimal is Base 10 and Binary is Base 2. The base of a system

refers to how many possible numbers can be in each digit position. In decimal, a single

digit number is 0 through 9. In binary a single digit number is 0 or 1. In decimal, as you

count up from 0, when you reach 9 and add 1 more, you have to add another digit

position to the left and carry a 1 into it to get 10 (ten). Ten is a two digit decimal number.

In binary, as you count up from 0, when you reach 1 and add 1 more, you have to add

another digit position to the left and carry a 1 into it to get 10 (two decimal). While this is

exactly what you do in decimal, the result looks like ten. What you have to do is get past

seeing all numbers as decimal. While decimal 10 (ten) looks like binary 10 (two decimal)

they represent different decimal values. It is still useful to think in decimal, since that's

what we're used to, but we have to get used to seeing numbers represented in binary.

Another small difference between decimal terminology and binary is that in binary a digit

is called a bit. It gets even more confusing by the fact that 4 bits make a nibble. Two

nibbles make a byte. Two bytes make a word. Most numbers used in a micro don't go

beyond this, although there are others. Using what I've just said, if two nibbles make a

byte, you could also say that a byte is eight bits.

To represent a binary number larger than 4 bits, or a nibble, a different numbering system

is normally used. It is called hexadecimal, or Base 16. A shorter name for hexadecimal is

simply hex, and that's what we'll use here after. In this system there are 16 possible

numbers for each digit. For the first 10, 0 through 9, it looks like decimal. Unlike

decimal, when you add 1 more to 9, you get A. I know that having a letter to represent a

number is really confusing, but they had to call it something, and A is what they chose.

So a hex A is a decimal 10 (ten). The numbers count up from A through F. Just to clarify

this here is the sequence of counting in hex from 0 to where you have to add another digit

position to the left... 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (no G). This represents a

decimal count of 0 through 15. At a count of F (15 decimal), if you add 1 more you get

10 (oh no! .. not another 10 that means something else!!). Sad but true.

Let's regroup here. A binary 10 (one zero) is decimal 2, a decimal 10 is ten, and a hex 10

is decimal 16. If you can get this concept, you will have conquered the most difficult part

of learning micros.

I need to get past one more obstacle, the idea of significance. In a decimal number like

123, 3 is the least significant digit position (the right most digit) and 1 is the most

significant digit position (the left most digit). Significance means the relative value of one

digit to the next. In the number 123 (one hundred twenty three) , each number in the right

hand most digit position (3) is worth 1. The value of each number in the next most

significant digit position (2) is worth ten and in the most significant digit position (1)

each is worth a hundred. I'm not trying to insult your intelligence here, but rather to point

out the rule behind this. The rule is that no matter what base you're working in, as you

start adding digits to the left, each one is worth the base times (multiplied) the digit to the

right. In the decimal number 123 (base 10), the 2 digit position is worth 10 times the 3

digit position and the 1 digit position is worth 10 times the 2 digit position. Hence the

familiar units, tens, hundreds, and so on. For some reason, for most people, this makes

sense for decimal (base 10) but not for any other base numbering system.

The very same is true for binary. The only difference is the base. Binary is base 2. So in

binary the least significant bit (remember bits?) is worth 1 ( this happens to be the same

for all bases). The next most significant bit is worth 2, the next worth 4, the next worth 8,

and so on. Each is 2 times (base 2) the previous one. So in an 8 bit binary number (or

byte, remember bytes?), starting from the right and moving left, the values for each of the

8 bit positions are 1, 2, 4, 8, 16, 32, 64 , and 128. If you've got this, you have passed a

major milestone, you should go celebrate your passage. If you haven't, I would re-read

the above until you do, and then go celebrate!! ( By the way, if you didn't get this the first

time through, join the crowd. I didn't either!!)

In hex (base 16) the same rule applies. In a 4 digit hex number, starting at the right and

working left, the first digit is worth 1 ( hey that's just like decimal and binary!!), the next

is worth 16 (base times the previous digit), the next is worth 256 (16 X 16), and the most

significant is worth 4096 (256 X 16). One last note, hex is just binary described another

way. A hex digit is a binary nibble ( remember nibbles?). Both are 4 bit binary values.

Trying to wrap all this confusion up in review, 4 bits is a nibble or a hex digit. Two hex

digits is a byte or 8 bit binary. A 4 digit hex number is a word, or 16 bit binary or 4

nibbles, or 2 bytes. You may have to review the previous paragraphs a few times (I did!!)

to get all the relationships down pat, but it is crucial that you are comfortable with all I've

said, so that what follows will make more sense.

Let's take a few example numbers and find the decimal equivalent of each. Let's start

with the binary number 1011, a nibble. Starting at the right and moving left, the first digit

is worth one, because there is a 1 there. The next is worth two, because there is a 1 in it.

The next would be worth 4, but since there is a 0, it's worth zero. The last or most

significant is worth eight, since there is a 1 in it. Add all these up and you get eleven. So

a binary 1011 is decimal 11. Also, since this could be a hex digit, the hex value would be

B.

Let's take a longer binary number 10100101. Starting at the right moving left, the first is

worth 1, the next is worth 0, the next is worth 4, the next is 0, the next is 0, the next is

worth 32, the next is 0, and the last is 128. Adding all these up you get decimal 165.

Dividing this number up into two hex digits, you get A5. So binary 10100101, decimal

165, and hex A5 are all the same value. Using hex, the rightmost digit is worth 5, and the

most significant digit is worth 160 (10 X 16), resulting in decimal 165. If you understand

this, your ready to move on, leaving the different systems behind. If you don't, keep

reviewing and studying until you do. If you don't understand and still continue, you will

be confused by what follows. I promise that once you get this, the rest is easier.

This ends the second lesson. I hope this wasn't too daunting or difficult, but there was a

lot to get through. The rest of the course should be a little easier. Learning a new

numbering system is like learning a new language. It's a little cumbersome at first, but it

gets easier.

My email address is here and I would welcome your questions or comments as you

proceed through this course. Depending on the volume of mail I get, it may take a couple

of days or so for me to get back to you, but be assured, I will get back to you. I really do

want you to understand the information I'm presenting, and not being a professional

teacher, I might not always explain things to the satisfaction of everyone, but with your

patience, I'll do my best. My home page is http://www.hkrmicro.com/personal/index.html

A Micro's Commands (or Instructions).

I would like to take a moment and address a few things that will make it easier for me to

describe things to you later. In a micro we refer to a binary number like 1111 as 1111b, a

decimal number like 123 as 123, and a hex number like A5 as A5h. So don't be confused

by the letters following numbers, it is easier than having to say the whole words binary,

decimal, or hexadecimal, but still indicate it. By doing this, there is no doubt what base a

multidigit, or multibit, number is in.

Also there is another kind of memory, called flags. Flags are single bit numbers used to

indicate different conditions. They are called flags because they flag the program of

events or conditions. If a flag is raised, or has a 1 in it, it is said to be SET. If it is a 0, it is

said to be CLEARED.

One other thing, in an 8 bit byte the 8 bits are referred to as bits 0 through 7, with bit 0

being the right most, or least significant, and bit 7 as the left most or most significant. In

micros, a 0 is just as real a number as 1 or 8, and it should not be thought of as "nothing".

Lastly, there are various Registers inside a micro. These vary from micro to micro, but all

contain a register called the Accumulator. It is also referred to in some as the a register. I

will be using the accumulator in the following discussion. It is a type of memory for

storing temporary results and is 8 bits wide, or a byte, as are most places that data can be

put inside the micro.

In the micro we will be using, there are 5 different types of instructions and several

variations of each, resulting in 110 different instructions. These 5 types are

ARITHMETIC, LOGICAL, BOOLEAN, BRANCHING, and DATA TRANSFER.

ARITHMETIC

The arithmetic instructions include addition, subtraction, division, multiplication,

incrementing, and decrementing. There are two flags used with arithmetic that tell the

program what the outcome of the instruction was. One is the Carry (C) flag. The other is

the Zero (Z) flag. The C flag will be explained in the following example of addition. The

Z flag, if set, says that the result of the instruction left a value of 0 in the accumulator. We

will see the Z flag used in a later lesson.

Addition

This is straight forward and is simply to add two numbers together and get the result.

However there is one more thing. If, in the addition, the result was too big to fit into the

accumulator, part of it might be lost. There is a safeguard against this. Take the case of

11111111b (255) and 11111111b (255). These are the largest numbers that can fit into an

8 bit register or memory location.You can add these as decimal numbers, since I gave

you their values in decimal also, and you would get 510. The binary value for 510 is

111111110b (9 bits). The accumulator is only 8 bits wide, it is a byte. How do you fit a 9

bit number into 8 bits of space? The answer is, you can't, and its called an OVERFLOW

condition. So how do we get around this dilemma? We do it with the CARRY (C) flag. If

the result of the addition is greater than 8 bits, the CARRY (C) flag will hold the 9 th bit.

In this case the accumulator would have a 11111110b (254) and the C flag would be a 1,

or set. This 1 has the value of 256 because this is the 9th bit. We haven't covered a 9 bit

number, but they come up all the time as overflows in addition. Since we are using base

2, and we found out in lesson 2 that the 8th bit (bit 7) in a byte is worth 128, then the 9th

bit is worth 2 times that, or 256. Adding 254 and 256, we get 510, the answer, and we

didn't loose anything, because of the C flag. Had the result of the addition not caused an

overflow, the C flag would be 0, or cleared.

Subtraction

In the case of subtraction, the process is more difficult to explain, and as such, I'm not

going to cover it here. It involves 1's compliment and 2's compliment representation. But

I will tell you this, you can subtract two numbers and if there is an under flow, the C flag

will be a 1, otherwise it will be a 0. An under flow is where you subtract a larger number

from a smaller number.

Multiplication and Division

In the micro we will be using, are multiply and divide instructions, but I will wait till later

to talk about them. They do, however, just what the names suggest.

Two other instructions are included in the arithmetic group. They are increment and

decrement. These instructions are used to count events or loops in a program. Each time

an increment is executed, the value is incremented by 1. A decrement, decrements the

value by 1. These can be used with conditional jumps to loop a section of program, a

certain number of times. We will see these used later.

LOGICAL

In micros there are other mathematical instructions called logical instructions. These are

OR , AND, XOR, ROTATE, COMPLEMENT and CLEAR. These commands are

usually not concerned with the value of the data they work with, but, instead, the value,

or state, of each bit in the data.

OR

The OR function can be demonstrate by taking two binary numbers, 1010b and 0110b.

When OR'ing two numbers, it doesn't matter at which end you start, right or left. Let's

start from the left. In the first bit position there is a 1 in the first number and a 0 in the

second number. This would result in a 1. The next bit has a 0 in the first number and a 1

in the second number. The result would be 1. The next bit has a 1 in the first number and

a 1 in the second number. The result would be a 1. The last bit has a 0 in the first number

and a 0 in the second number, resulting in a 0. So the answer would be 1110b. The rule

that gives this answer says that with an OR, a 1 in either number results in a 1, or said

another way, any 1 in, gives a 1 out.

AND

AND'ing uses a different rule. The rule here is a 0 in either number will result in a 0 , for

each corresponding bit position. Using the same two numbers 1010b and 0110b the result

would be 0010b. You can see that every bit position except the third has a zero in one or

the other number. Another way of defining an AND is to say that a 1 AND a 1 results in a

1.

XOR (eXclusive OR)

XOR'ing is similar to OR'ing with one exception. An OR can also be called an inclusive

OR. This means that a 1 in either number or both will result in a 1. An eXclusive OR says

that if either number has a 1 in it, but not both, a 1 will result. A seemingly small

difference, but crucial. Using the same two numbers, the result would be 1100b. The first

two bits have a 1 in either the first or the second number but not both. The third bit has a

1 in both numbers which results in a 0. The fourth has no 1's at all, so the result is 0. The

difference may seem small, even though the OR and XOR result in different answers.

The main use of an XOR is to test two numbers against each other. If they are the same,

the result will be all 0's, otherwise the answer will have 1's where there are differences.

Compliment

Complimenting a number results in the opposite state of all the 1's and 0's. Take the

number 1111b. Complimenting results in 0000b. This is the simplest operator of all and

the easiest to understand. It's uses are varied, but necessary, as you'll see later.

Rotate

These instructions rotate bits in a byte. The rotation can be left or right, and is done one

bit each instruction. An example might be where the accumulator has a 11000011b in it.

If we rotate left, the result will be 10000111b. You can see that bit 7 has now been moved

into bit 0 and all the other bits have move 1 bit position in, the left direction.

Clear

This instruction clears, or zero's out the accumulator. This is the same as moving a 0 into

the accumulator. This also clears the C flag and sets the Z flag.

BOOLEAN

There are other commands that deal with single bit values. In a program, an 8 bit byte

location may be used as 8 separate flags or indicators, defined by the programmer, and

used to signal events or conditions between separate parts of a program. This might be a

bit that indicates whether a door is open or closed, or whether a key has been pressed or a

switch is closed or open. These bits or flags are usually the mechanism that keeps law

and order in the program, and insures that the program does not get "lost" or misdirected.

We'll see how this works later.

There are instructions to do the same things with bits that are done with bytes by other

instructions. You can AND, OR, SET, CLEAR, or MOVE bits. You will see in a later

lesson how these are used.

BRANCHING

There are also program flow commands. These are branches or jumps. They have several

different names reflecting the way they do the jump or on what condition causes the

jump, like an overflow or under flow, or the results being zero or not zero. But all stop

the normal sequential execution of the program, and jump to another location, other than

the next instruction in sequence.

Jump on Bit

These instructions let you make a jump based on whether a certain bit is set (a 1) or

cleared (a 0). This bit can be the CY (carry) flag, the Z (zero) flag, or any other bit.

Compare and jump

These instructions compare two values and jump based on the result. In lesson 1 we

looked at a glass filling with water and compared it to a full one in our mind, and if it

wasn't full we looked at it some more. This caused that program to loop, or wait, until the

glass was full before continuing on.

Call

There is also a variation on a jump that is referred to as a CALL. A CALL does a jump,

but then eventually comes back to the place where the CALL instruction was executed

and continues with the next instruction after the CALL. This allows the programmer to

create little sub-programs, or subroutines, that do repetitive tasks needed by the main

program. This saves programming time because once the subroutine is written, it can be

used by the main program when ever it needs it, a kind of way to create your own

instructions.

DATA TRANSFER

Moving

These instructions do exactly what you would think. They move data around between the

various registers and memory.

Exchanging

Exchanging is a variation on the move instruction. Here data is exchanged between two

places.

Exchange Digit

This is a variation on the exchange instruction. Here the lower nibble, or digit, is

exchanged with the lower nibble of the other location. The upper nibble is the left 4 bits

(bits 4 through 7) and the lower nibble is the right 4 bits (bits 0 through 3).

Swapping

This is another variation on the exchange instruction, but here the data exchange occurs

between the upper nibble and the lower nibble in the accumulator.

This is the end of lesson 3. I've tried to show all the possible instructions without actually

showing each. I will, in a later lesson, go into each of the 110 different instructions and

explain each one. In the next lesson we will learn more about memory and all the

possible ways to get to a memory location.

My email address is here and I would welcome your questions or comments as you

proceed through this course. Depending on the volume of mail I get, it may take a couple

of days or so for me to get back to you, but be assured, I will get back to you. I really do

want you to understand the information I'm presenting, and not being a professional

teacher, I might not always explain things to the satisfaction of everyone, but with your

patience, I'll do my best. My home page is http://www.hkrmicro.com/personal/index.html

The DS5000 Micro controller.

Well, finally, this is what all the previous lessons have been getting you ready for. To

start looking at the micro we will be using in this course. All the previous lessons have

been laying the ground work and basic concepts common to most micros. The one we

will be using is the Dallas Semiconductor DS5000 micro controller. This chip, in my

mind, is one of the neatest ones ever made. Dallas Semiconductor knew what to put in a

chip. There are a few external parts needed along with the DS5000, but they are few, and

cheap to buy. I will give you a schematic and a parts list, along with the places to get all

the parts later.

I would recommend that you get the Secure Micro controller Data Book (in PDF format)

from Dallas Semiconductor, as soon as you can. The paperback version is out of print

now. The telephone number is 972 - 371 - 4448. They are located in Dallas Texas at 4401

South Beltwood Parkway, zip 752444-3292. It's loaded with information and is

absolutely crucial for a good understanding of the DS5000. The book actually covers

several versions of the 5000 series of microcontroller chips.

My hope is that you will buy one of the DS5000 parts and really start building things

with it. I think it costs about $75. Cheap, considering what you can do with it. But don't

buy it yet, I'll tell you when. There is still lots to learn before you will be able to start

building something with it.

The DS5000 is a microcontroller based on the Intel 8051 microprocessor. It looks like an

8051 as far as programming and the general pinout of the package. The pinout refers to

the physical package and what each pin on the package is used for. But the DS5000 is

much more. There are 40 pins on the package. Of these pins, 32 are connections to the

outside world that information can be brought into or out of the DS5000. There are a few

other pins, but more on them later.

These 32 pins show up inside the package as 4 ports. Each port is 8 bits wide and have

the names p0, p1, p2, and p3. Each port can be inputs or outputs to or from the outside.

Besides being inputs and outputs, p0, p2, and p3 have special functions assigned to them.

P0 and p2 are used for external memory interface, which we will not use since there is

plenty of memory inside the DS5000. These 16 pins will be used for input / output. But if

we were talking about an 8051, this is where memory would connect. Half of the pins of

port 3 will be used for their special functionality. The other four pins of p3 will be used

as regular inputs and outputs, not using their special functions. These functions will be

discussed later, however.

Two pins of p3 are for serial communications with the DS5000. Through these pins,

serial data can be sent or received with another computer. This is how we will load a

program into the DS5000 from a PC.

Two more pins are for a different kind of input called interrupts. In our example in lesson

1 of the program where we are standing at the street corner, watching the light and the

traffic, if a person walked up and tapped us on the shoulder and asked what time it is, this

would be an example of an interrupt. It doesn't alter the program we are doing, it just

temporarily stops us while we tell the time to the person. As soon as we tell the time, we

go back to watching the lights and traffic as before. This describes the action of an

interrupt.

The interrupt has a program associated with it to guide the micro through a problem. In

the case of the above example, this program would be to look at our watch, read the time,

and then tell it to the person. This is called an interrupt service routine. Each time an

interrupt occurs, the current program is temporarily stopped and the service routine is

executed and when complete, returns to the current program. We will spend a lot more

time later describing interrupts and how we'll use them.

Inside the DS5000 is a 128 byte memory area called internal ram (random access

memory). The first 32 bytes are used for 4 banks of registers. They are called bank 0,

bank 1, bank 2, and bank 3. When the micro is first powered up, bank 0 is the selected

bank. Afterwards there is a command which allows switching to another bank, but we

won't do that right now. Inside each bank there are 8 seperate registers. They are called

r0, r1, r2, r3, r4, r5, r6, and r7. These registers are used for temporary storage of whatever

is needed by the program. There is also a register that is the accumulator called a. This

register is different from the other 8 registers. It is used to accumulate the results of

various instructions like add or sub (subtract).

The next 16 bytes of internal ram are for bit storage and retrieval. This allows for 128

different bits that can be used by the program. Most early micros didn't have this very

useful feature.

The last 80 bytes of internal ram are for general storage and is used for many different

things.

There is another 128 byte area of memory called the special function registers. This is

where p0, p1, p2, and p3 are located. The accumulator and program counter are also in

this area along with other registers that control various aspects of the operation of the

DS5000. More on these as they come up later.

Lastly there is one more area of memory that is divided into two parts. The program

memory and the data memory. This is in reality a block of 32K (32768) bytes of ram that,

through the programming of one of the special function registers, can be divided into the

two sections. In most of our work we will divide this up into 16K (16384) bytes of

program and 16K (16384) bytes of data. The program memory is write protected so that

an errant program can't change itself accidently and really make a mess out of things. The

data memory can be written to or read from as needed by the program.

There is a lithium battery inside the DS5000 that keeps all the memory alive when power

is turned off. This is one of the neatest features of the DS5000, and I don't know of

another micro that has this. In most micros there is PROM ( programmable read only

memory) or EPROM (erasable programmable read only memory), as the program

memory. PROM can be programmed once and that's it. EPROM can be programmed and

then erased with ultra violet light through a glass window in the micro's package. But this

requires a special programmer and an ultra violet light source for erasure (over $125

worth of stuff!!).

But in the DS5000, 2 of the pins can be placed in a special state, and the program

downloaded to the chip through the serial port from a PC. There is a special program

inside the DS5000 that allows all this to happen, that goes away when these 2 pins are

returned to their normal state. This special program can be accessed anytime to change

the user program by, in our case, flipping a switch, downloading the program, and then

returning the switch to its normal position. Neat, huh? It takes just a few seconds to do

this, where it used to take a half hour to go through the erase / program cycle of an

EPROM based micro. And no special hardware is needed, other than the serial port.

This speeds up program development and allows a change to be made to the program,

downloaded to the micro, and executed, in under a minute. Slick!!! It will still take plenty

of time to develope and debug a program, but very little time or effort to get the program

into the DS5000, ready to run.

I have also located a free 8051 simulator for your use that will allow you to test small

programs out on your PC without downloading them to the DS5000. You can see all the

registers change as the program is stepped through each instruction. This greatly speeds

up the debugging process, and is an educational tool that shows how each instruction

affects the various parts of the DS5000. We will use this in later lessons to illustrate the

different instructions and programs that we will write.

There are other features to be covered later, as they come up. In the next lesson we will

start looking at assembly language, the method we will use to write a program.

My email address is here and I would welcome your questions or comments as you

proceed through this course. Depending on the volume of mail I get, it may take a couple

of days or so for me to get back to you, but be assured, I will get back to you. I really do

want you to understand the information I'm presenting, and not being a professional

teacher, I might not always explain things to the satisfaction of everyone, but with your

patience, I'll do my best. My home page is http://www.hkrmicro.net/personal/index.html .

What is Assembly Language?

Inside the DS5000, instructions are really stored as hex numbers, not a very good way to

look at them and extremely difficult to decipher. An assembler is a program that allows

you to write instructions in, more or less, english form, much more easily read and

understood, and then converted or assembled into hex numbers.

The program is written with a text editor ( I'll furnish you with one), saved, and then

assembled by the assembler (I'll furnish you with one). The result is the file you

download to the DS5000. Here is an example of the problem of adding 2 plus 2: [This file

will be called prob01.asm]

mov r0,#2 mov a,#2 add a,r0

The first line moves a 2 into register r0. The second moves a 2 into the accumulator. This

is all the data we need for the program. The third line adds the accumulator with r0 and

Tải ngay đi em, còn do dự, trời tối mất!