John Crisp - Introduction to Microprocessors and Microcontrollers
Здесь есть возможность читать онлайн «John Crisp - Introduction to Microprocessors and Microcontrollers» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Год выпуска: 2004, ISBN: 2004, Издательство: Elsevier, Жанр: Компьютерное железо, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Introduction to Microprocessors and Microcontrollers
- Автор:
- Издательство:Elsevier
- Жанр:
- Год:2004
- ISBN:0-7506-5989-0
- Рейтинг книги:3 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 60
- 1
- 2
- 3
- 4
- 5
Introduction to Microprocessors and Microcontrollers: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Introduction to Microprocessors and Microcontrollers»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Introduction to Microprocessors and Microcontrollers — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Introduction to Microprocessors and Microcontrollers», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
; the PortB data direction register
3 Now we have sorted out the direction of the data flow and we can input the actual data. This time we are going to clear bit 5 of register 3 to allow us to access Bank0. We can now load our data into the W register. But what is the data? If we assume the LED is going to be connected between the port output and the zero volt connection, the voltages corresponding to the light sequence off, on, off, on, off, on, off, on will be 0V, +5 V, 0 V, +5 V, 0 V, +5 V, 0 V, +5 V and the data will be 0,1,0,1, 0,1,0,1. We could enter this as a binary number written as B’01010101’ or as the hex number 55 which is a little easier to read.
Once the 55H is in the W register, we can use the code MOVWF to copy it into register 06 which in Figure 15.8, we can see is the PortB data register.
The program is now:
BSF 3,5 ; Sets bit 5 of register 3 to select Bank1
CLRW ; puts a zero into register W
MOVWF 86; copies the zero into register 86 which is
; the PortB data direction register
BCF 3,5 ; clears bit 5 of register 3
MOVLW 55; this is the output data to give the on, off
; sequence
MOVWF 06; this copies the data into PortB
4 As it stands, the micro will perform each of these steps once and then stop. We have a problem here because it will take only a few microseconds to complete these instructions – certainly too fast for us to see if the correct sequence of LEDs are illuminated. We need to give the micro something to do which will keep the LEDs operational and our choice here is to reload the output port continuously. Have a look at our new program:
BSF 3,5 ; Sets bit 5 of register 3 to select Bank1
CLRW ; puts a zero into register W
MOVWF 86 ; copies the zero into register 86 which
; is the PortB data direction register
BCF 3,5 ; clears bit 5 of register 3
MOVLW 55 ; this is the output data to give the on,
; off sequence
again MOVWF 06 ; this copies the data into PortB
GOTO again; this line forces the micro to return to
; the previous line
The words ‘again’ are called labels and the assembler program notices that the two are identical and replaces them by the correct address. The fact that we have used ‘again’, a word that makes sense in the context is just to help us to understand the program, the assembler would accept ‘asdf’ or anything else just as happily. Some assemblers put restrictions on the names chosen. It may, for example, not allow it to start with a number, or use certain words or symbols.
5 At the end of the program, we have to put the instruction END to tell the assembler to stop. It is called an ‘assembler directive’ and is there to tell the assembler program that it has reached the end of our program. Directives are not instructions to the microcontroller and are not converted to machine code.
6 At the start of the program we can use the directive ORG which means ‘origin’ and gives the starting address for the assembled program. This has been added to our final program. If we had not done this, the assembler will assume the address to be zero so, in this case it would make no difference whether we added this directive or left it out. When the PIC is reset, it always goes to address 000 so if we wanted the program to start elsewhere we would have to leave a GOTO instruction at address 000 to tell the microcontroller where it is to start. Remember that the ORG is only an instruction to the assembler telling it where to start loading the program – the PIC doesn’t know anything about this because directives are not converted to the program code.
So our final program is:
ORG 000 ; Program starts at address 000
BSF 3,5 ; Sets bit 5 of register 3 to select Bank1
CLRW ; puts a zero into register W
MOVWF 86 ; copies the zero into register 86 which
; is the PortB data direction register
BCF 3,5 ; clears bit 5 of register 3 to select
; Bank0
MOVLW 55 ; this is the output data to give the on,
; off sequence
again MOVWF 06 ; this copies the data into PortB
GOTO again; this line forces the micro to return to
; the previous line
END ; the end of our code to be assembled
Notice how the program is written in columns or ‘fields’. It is necessary to use the correct fields as this tells the assembler what the items are. Remember to use the semicolon to start notes that we wish the assembler to ignore.
For clarity, only one LED is shown but an LED and resistor should be joined to all the pins 7–13 to show the full output.
LEDs come in different colours and sizes and the cathode must be connected to a less positive voltage than the anode. The cathode is generally recognized either by a shorter connector wire or a flat moulded onto the body.
Component values
Looking at the data for a standard red LED, the typical voltage ( V f) across them when lit is 2 volts with a maximum current of ( I f) 20 mA. The small ‘f’ stands for ‘forward’. The light lost by reducing the current for a real project below its maximum value is not very great and it would be quite reasonable to operate the LED on, say, 10 mA.
To limit the current flow, a resistor is connected in series. Now, if the supply voltage for the microcontroller is 5 volts and about 0.7 volts are ‘lost’ inside the PIC and the LED is using 2 volts, the series resistor must be ‘using up’ the other 2.3 volts. The value of the resistor is given by R = V/I =2.3/(10×10 –3)=230 Ω. If in doubt start with 470 ohms and see how it goes – this is a generally safe value for all situations.
More labels
The use of labels not only makes the program more readable but it allows modifications to be accommodated. For example, if we put in the actual address instead of the label and then modified the program by adding an extra instruction, the actual addresses would all shuffle along a bit to make room for the new instruction, making our old address inappropriate. The program would not work and it might take us hours before we see what we have done whereas a label would be sorted out by running it through the assembler with the new instruction added.
There is another useful assembler directive, EQU, which is an abbreviation for equates or ‘is equal to’. This can be used to make programs more readable by replacing some of the numbers with words. For example, register 86 is the PortB Data Direction register but the program would be easier to read if we replaced the number by the name. This would be done adding the line: PortBDDR EQU 86 before the program listing so as soon as the assembler spots the name PortBDDR it would replace it with 86. This has no affect on the final program but it makes life easier for us – which has got to be a ‘good thing’.
If we add some other labels, the final program can now be written as:
;EQUATES
PortBDDR EQU 86 ; PortB data direction reg.
; is register 86
PortB EQU 06 ; PortB data register is
; register 06
Status EQU 03 ; Status register is register
; 03
RP0 EQU 05 ; Bank1 is selected by bit 5
Data EQU 55 ; Data used is 55H
BSF Status,RP0; Sets bit 5 of register 3 to
Интервал:
Закладка:
Похожие книги на «Introduction to Microprocessors and Microcontrollers»
Представляем Вашему вниманию похожие книги на «Introduction to Microprocessors and Microcontrollers» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Introduction to Microprocessors and Microcontrollers» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.