ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 3141
Скачиваний: 0
A.13 Programming the Internal Memory of 8051 |
239 |
The signature bytes are two to four data bytes, read from addresses specific for each device. For example, AT89C51 reports three signature bytes, read from the addresses 30h, 31h, 32h. The first signature byte indicates the manufacturer (1Eh for Atmel Corporation), the second byte identifies the device (51h for AT89C51), and the third signature byte indicates the value of the programming voltage Vpp (FFh for 12 V, 05h for 5 V).
The lock bits are non-volatile control bits, accessible only in programming mode, similar to those described in Appendix A9 for AVR microcontrollers. The effect of programming the lock bits of AT89C51 is described in Table A13.2.
Table A13.2. The effect of the lock bits for AT89C51
Lock bits status |
Protection type |
||
LB1 |
LB2 |
LB3 |
|
U |
U |
U |
No program lock features |
P |
U |
U |
The EA line is sampled and latched on reset, and further |
programming of the Flash is disabled. |
|||
MOVC instructions executed from external program |
|||
memory are disabled. |
|||
P |
P |
U |
Same as above, but verify operations are also disabled |
P |
P |
P |
Same as above, but program execution from external |
memory is also disabled. |
|||
Legend
U – Unprogrammed bit (1)
P – Programmed bit (0)
See the accompanying CD for details on how to build a programmer for 8051 microcontrollers.
A.14 SPI Seven-Segment Display Units
This section presents schematics and suggestions on how to use two types of sevensegment display units, both designed to be connected to the SPI interface of a microcontroller.
The first implementation, presented in Fig. A14.1, is multiplexed, i. e. at a certain time moment only one digit is displayed. The software must refresh the data permanently, by switching the active digit fast enough so that the human eye integrates the successive images into a single, complete perception.
The SPI interface of the MCU is brought to the connector SV1. An additional connector SV2 has been provided so that the ISP interface can be used without the need to remove the display unit.
VCC |
IC1 |
||||||||||||||||||
4 |
D1 |
D2 |
|||||||||||||||||
LD |
1 |
Q1 |
A |
f |
F |
A |
f |
F |
|||||||||||
2 |
1 |
STR |
IC2 |
RN |
a |
a |
|||||||||||||
MOSI |
2 |
D |
Q2 |
5 |
b |
g |
b |
g |
|||||||||||
4 |
3 |
SCK |
3 |
CLK |
Q3 |
6 |
7 |
D0 |
A |
13 |
A |
c |
P |
c |
P |
||||
6 |
5 |
RST 15 |
OE |
Q4 |
7 |
1 |
D1 |
B |
12 |
B |
d |
A |
d |
A |
|||||
8 |
7 |
Q5 |
14 |
2 |
D2 |
C |
11 |
C |
e |
A |
e |
A |
|||||||
10 |
9 |
Q6 |
13 |
6 |
D3 |
D |
10 |
D |
|||||||||||
Q7 |
12 |
E |
9 |
E |
|||||||||||||||
SV1 |
Q7 |
11 |
3 |
LT |
F |
15 |
F |
CA2 |
|||||||||||
9 |
4 |
BI/RBO |
G |
14 |
G |
E |
CA1 |
E |
|||||||||||
GND |
QS |
5 |
RBI |
||||||||||||||||
VCC |
4094 |
VCC |
SN7447 |
||||||||||||||||
CA3 |
E |
CA4 |
E |
||||||||||||||||
2 |
1 |
1 |
IC3 |
15 |
1 |
IC4 |
18 |
CA1 |
A |
e |
A |
e |
|||||||
A |
Y0 |
I1 |
O1 |
A |
d |
A |
d |
||||||||||||
4 |
3 |
2 |
B |
Y1 |
14 |
2 |
I2 |
O2 |
17 |
CA2 |
P |
c |
P |
c |
|||||
6 |
5 |
3 |
C |
Y2 |
13 |
3 |
I3 |
O3 |
16 |
CA3 |
g |
b |
g |
b |
|||||
8 |
7 |
VCC |
Y3 |
12 |
4 |
I4 |
O4 |
15 |
CA4 |
f |
a |
f |
a |
||||||
10 |
9 |
6 |
P |
F |
A |
F |
A |
||||||||||||
MISO |
G1 |
D3 |
D4 |
||||||||||||||||
SV2 |
4 |
VCC |
|||||||||||||||||
G2A |
|||||||||||||||||||
5 |
RN |
||||||||||||||||||
G2B |
10 GND |
VS 9 |
|||||||||||||||||
GND |
|||||||||||||||||||
74HC138 |
|||||||||||||||||||
GND |
GND |
UDN2585 |
R1 |
T1 |
|||||||||||||||
GND |
|||||||||||||||||||
Fig. A14.1. Schematic of a multiplexed seven-segment display
Data from the SPI is received in the shift register 4094 (IC1) and must be prepared by the software as follows:
•The least significant four bits of each byte contain the BCD value of the digit to be displayed.
•The next three bits contain the address of the active digit.
•The most significant bit, if set to 1, activates the decimal point of the corresponding display digit.
4094 receives the serial data sent by the MCU through the MOSI line and shifts it into the internal shift register with the clock SCK. When the serial transfer completes, the software must generate a positive pulse on the LD line so that the data received this way is presented on the output lines Q1–Q8. The SPI must be programmed to send data with the most significant bit first.
A.14 SPI Seven-Segment Display Units |
241 |
SV1 |
IC3 |
C1 |
IC4 |
SV2 |
|
D1 |
D2 |
D3 |
D4 |
||
IC1 |
IC2 |
||||
R1 |
RN |
||||
T1 |
Fig. A14.2. PCB layout for the circuit presented in Fig. 14.1
BCD data is directly applied to the input of the 7447 decoder IC2, while the digit address is decoded by the 74138 circuit IC3 and activates one of the four common anodes of the display, by means of the inverting driver UDN2585 (IC4). The transistor T1 activates the decimal point of the active digit if the most significant bit of the byte in IC1 is set to 1.
Figure A14.2 shows the component layout of the PCB for this display unit. Another approach for displaying four seven-segment digits with a SPI display is
presented in Fig. A14.3.
This time, two data bytes are received in two 4094 registers. The contents of the 4094 registers are interpreted as four BCD digits and applied to 4×7447 circuits, which directly drive the display units.
D1 |
||
a |
f |
|
b |
g |
|
c |
P |
|
d |
A |
|
VCC |
e |
A |
SV2 |
LD(SS) |
VCC
D2 |
|
a |
f |
b |
g |
c |
P |
d |
A |
e |
A |
D3 |
D4 |
||||
a |
f |
a |
f |
||
b |
g |
||||
b |
g |
||||
c |
P |
||||
c |
P |
||||
d |
A |
||||
d |
A |
||||
e |
A |
||||
e |
A |
||||
2 |
1 |
MOSI |
|||
4 |
3 |
SCK |
|||
6 |
5 |
RST |
|||
87
10 9
GND
C1
VCC
2 |
1 |
|
4 |
3 |
|
6 |
5 |
|
8 |
7 |
MISO |
10 |
9 |
SV1
GND
RN3
|
13 12 11 10 9 15 14 |
IC5 |
||
|
D0 D1 D2 D3 E |
LT BI/RBOG RBI |
SN7447 |
|
|
A B C D |
F |
||
|
7 1 2 6 |
3 4 5 |
VCC |
RN1 |
|||||||||||||||||
|
13 12 11 10 9 15 14 |
IC2 |
||||||||||||||||
|
D0 D1 D2 D3 E LT BI/RBOG RBI |
SN7447 |
||||||||||||||||
|
A B C D |
F |
||||||||||||||||
|
7 1 2 6 |
3 4 |
5 |
VCC |
||||||||||||||
RN2 |
|||||||||||||||||
|
13 12 11 10 9 15 14 |
IC3 |
||||||||||||||||
|
D0 D1 D2 D3 |
E LT BI/RBOG RBI |
SN7447 |
|||||||||||||||
|
A B C D |
F |
||||||||||||||||
|
7 1 2 6 |
3 4 |
5 |
VCC |
||||||||||||||
RN4
|
13 12 11 10 9 15 14 |
IC6 |
||
|
D0 D1 D2 D3 E |
LT BI/RBOG RBI |
SN7447 |
|
|
A B C D |
F |
||
|
7 1 2 6 |
3 4 5 |
VCC |
|
14 |
13 |
||||||||||||||||||||||||||||||||||||||
|
4 |
5 |
6 |
7 |
12 |
11 |
9 |
4 |
5 |
6 |
7 |
14 |
13 |
12 |
11 |
9 |
||||||||||||||||||||||||
|
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 |
QS |
4094N |
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 |
QS |
4094N |
||||||||||||||||||||||||||||||||||
IC1 |
STR D CLK OE |
IC4 |
STR D CLK OE |
||||||||||||||||||||||||||||||||||||
|
1 |
2 |
3 |
15 |
1 |
2 |
3 |
15 |
||||||||||||||||||||||||||||||||
Fig. A14.3. Non-multiplexed seven-segment display unit
242 Appendices
D1 |
D2 |
D3 |
D4 |
|||
SV2 |
IC5 |
RN3 |
RN4 |
IC6 |
||
SV1 |
||||||
C1 |
RN1 |
RN2 |
||||
IC1 |
IC2 |
IC3 |
IC4 |
Fig. A14.4. PCB layout for the circuit presented in Fig. A14.3
Note that in this case the two 4094 registers are concatenated, which means that the software must send two bytes of data over the SPI interface. The two bytes must contain four BCD digits (the least significant digit is sent first), followed by a single pulse on LD, which is common for both registers.
This display unit maintains the data indefinitely and there is no need to refresh the information displayed.
The non-multiplexed display requires simpler software, but, for a larger number of digits, the cost of the hardware is higher. Besides that, this solution has the disadvantage that it cannot dynamically change by software the position of the decimal point.
T he PCB layout for this circuit is shown in Fig. A14.4. For all the projects that require a display unit, use the cable described in Fig. A14.5 between the development board and the display, regardless of the type of display (multiplexed or non-multiplexed) used.
1 |
2 |
9 |
10 |
1 |
2 |
9 |
10 |
Fig. A14.5. Layout of the cable for connecting the display unit
A.15 Description of the Software Utility ASMEDIT
Some users, familiar with the Windows™ environment, might find it difficult to work with MS-DOS™ type applications, which must be invoked from the command line in a DOS window. Since most freeware assemblers available, including those recommended in this book for HC11 and 8051, are DOS applications, we wrote a small utility program called ASMEDIT.EXE with the following features:
•It contains a simple built-in text editor, which allows the user to create assembler source files, save them to disk, or open existing files for editing.
•The user can choose an assembler, define command line options and switches, if required, then invoke the assembler and run it on the selected source file. When the assembly process completes, ASMEDIT brings the list file generated by the assembler in the main window for viewing.
•ASMEDIT also contains a built-in terminal program capable of using one of the computer’s COM ports to communicate with the development boards described in this book through the RS232 interface.
The main window presented by ASMEDIT when launched is shown in Fig. A15.1. The following pull-down menus are available:
Fig. A15.1. Snapshot of the main window of ASMEDIT
File. This menu presents options for Open, Save, Save as, and Create New source file. If you select the option Open file, ASMEDIT filters only files with the extensions
.ASM and .A51.
View. This menu allows the user to select the active window between the source file and the list file. It is also possible to adjust the font size.
Assembler. This pull down menu has only two menu options: Assemble, which runs the assembler for the selected source file, and Select assembler. The dialog window presented in this case is shown in Fig. A15.2. Select the desired executable
244 Appendices
file by clicking the Browse button, then fill in the command line options, and switches, according to the syntax required by the assembler. Make sure that the assembler is set to generate a list file. For example, the case of the assembler ASHC11 by Peter Gargano, referred in Chap. 9, requires the switch ––LIST to generate the list file.
Terminal. This pull-down menu displays a list of options concerning the builtin terminal of ASMEDIT. The user can select the communication port (default is COM2), set the communication speed and clear the terminal window. In addition to this, the terminal menu contains two options that are useful when using the 8051 development board described in Chap. 11. If the option Send is activated, ASMEDIT looks in the folder where the active source file is located for a file with the same name and the extension .HEX, loads the file and sends it to the development board. The option Send&Go automatically launches a G
Fig. A15.2. Snapshot of the menu option Select Assembler
The output files generated by the assembler are placed in the same folder as the specified source file. If the source file uses the INCLUDE directive, the include files must be present in the same folder, or the full path where they are located must be indicated in the source file, e. g.
INCLUDE C:\ASHC11\INCLUDE\68HC11F1.DEF
B.1 Contents of the Accompanying CD
The main purpose of the accompanying CD is to allow the reader to save the time needed for typing the many software examples and exercises presented in the book. In addition to this, the fact that a freeware version of the Eagle layout editor is available for download at the CadSoft web site encouraged us to include on the CD the schematics and the PCB design for all the projects presented.
On several occasions, testing the projects in the book required special software utilities, which are also included on the CD.
The CD follows the structure of the book, each chapter in the book has a corresponding folder on the CD, and the subfolders Examples, Exercises, Schematics, and Utils. See Fig. B1.1 for an image of how the CD is organized.
To assemble and test the examples, copy the source files (.ASM) from the CD into the working directory for the selected microcontroller, e. g. C:\ASHC11\WORKor C:\ASM51\WORK, remove the read-only attributes so that they can be edited, then run the appropriate assembler.
If the Eagle layout editor is installed, the schematic files (.SCH) and the PCB design files (.BRD) can be opened simply by clicking on the file name. In case you choose not to install Eagle, the CD also contains a high-resolution bitmap version of the schematics presented in the book.
The software utilities included on the CD are described in the book. They do not require any installation procedure; just copy the files into a folder on your hard
Fig. B1.1. Structure of the accompanying CD
246 Appendices
drive and click on the program’s name to run it. All the utilities included need VB40032.DLL. This file is not included. If you don’t have it already, try a search on Google with this keyword to locate and download it, then copy it into your WINDOWS\SYSTEMdirectory.
All the software included or recommended in this book has been tested on several computers under Windows98™ and Windows XP™. We don’t know whether or not it works on other operating systems.
B.2 Recommended Readings and Web References
The information in this book is not intended to replace the data sheets for the microcontrollers presented herein. It is strongly recommended that you consult the data sheets and the application notes referred to in the book, and to download and install the software applications and utilities referred to for each microcontroller discussed, in order to be able to test the software examples presented.
Below is a list of the internet web sites that offer technical documentation and software for the study of the microcontrollers discussed in this book.
The best source for documentation about Motorola 68HC11 microcontrollers is the official web site of the manufacturer at www.freescale.com. For in-depth understanding of the information in this book, download and consult the data sheets for 68HC11E9, 68HC11F1 and the application note AN1060 that contains information about the special bootstrap operating mode.
The freeware assembler recommended for HC11 can be downloaded from http://www.techedge.com.au/utils/ashc11.htm . It is called ASHC11 and was created by Peter Gargano.
For other HC11 related internet resources, visit the web page of Roger Schaefer, at http://www.ezl.com/~rsch/.
Atmel Corporation has an excellent web site at www.atmel.com, offering technical data and software applications to support their products. Download the data sheets for the AVR microcontrollers AT90S8515/8535, and the software applications AVRStudio, and AVR ISP.
Also visit www.avrfreaks.com for further information about AVR microcontrollers.
Good-quality 8051 documentation can be found on the Atmel web site that offers information about their series of microcontrollers with the 8051 architecture.
The freeware 8051 assembler referred to in Chap. 11 can be found at http://plit.de/ asem-51/ and was created by W. Heinz.
Technical information about all types of memory devices is available at www.atmel
.com. For other peripheral devices such as A/D and D/A converters visit www.maximic.com.
All the schematics and printed circuit boards presented in this book were drawn with the CAD software Eagle™ layout editor, from CadSoft. A freeware version of this software is available for download at www.cadsoft.de. The CD accompanying this book contains the schematics and the PCB design for all the projects described in the book, therefore it is important to download and install the Eagle layout editor in order to be able to edit the existing projects, and use them as starting points for new projects.