EPB
-
Upload
krishnat-pawar -
Category
Documents
-
view
11 -
download
4
description
Transcript of EPB
EPB/SLK-51
- 75 -
EPB/SLK-51
(Low cost 8051 embedded kit with in-circuit programming facility)Users Manual
Edutech Systems
304, Sarjan Complex
Pratap Road
Baroda-390 001
Tel. (0265) 438317
Email: [email protected]
Site: www.edutechonline.com
Terms and Conditions for use of the EPB/SLK-51For the purposes of this document, the term THE PRODUCT shall be used to refer to EPB/SLK-51 (Educational Practice Board/Self-Learning Card).Terms and Conditions:
1) You agree to use THE PRODUCT entirely at your own risk, and assume all responsibility for such use. The author and distributors of THE PRODUCT do not warrant it fit or suitable for any particular purpose.
2) There exists no warranty for on-board components specially the CPU chip.
CONTENTS:Chapter 1
Introduction to EPB/SLK-51
04
Chapter 2
Features of EPB/SLK-51
06
Chapter 3
Before you install
07
Chapter 4
Understanding the EPB/SLK-51
09
Chapter 5
The Virtual Programmer
15
Chapter 6
Operating Steps
16
Chapter 7
Integrated Programming Tools
18
Chapter 8
Embedded Driver Routines
23
Chapter 9
Embedded Driver Description &
38
Example Programs
Chapter 10
FAQ
81
Chapter 1
Introduction to Educational Practice Board (EPB)/Self Learning Card (SLK-51)
Edutech Systems, Welcomes you to Educational Practice Board (EPB)/Self-Learning Card (SLK-51) the first of its kind of approach to learn, test and apply microcontroller.
This board is available in two versions. The first one is Educational Practice Board (EPB) & the second version is the Self Learning Card (SLK-51). Both the versions are basically same but only differ on the basis of certain features.
The EPB is a complete learning platform designed to learn, test and apply microcontroller 8051 based activities. This board has an extra breadboard facility enabling the users to insert different components like LEDs, Switches, 7-segment LEDs, Transistors, Relays, and ICs from 8 to 40 pins etc and then interface with the 8051 controller. Also the EPB comes with a wooden box package along with component box, hook up wires and manual. This board is specially designed for institutes where large numbers of students are suppose to use the platform. The breadboard facility enables different users to test and apply number of components with microcontroller 8051 which can again be reused.
The SLK-51 is also Educational Practice Board, which is a very low price edition exclusively for students. For those working alone, its a quick platform for building a circuit and applying the logic.
The SLK-51 contains a general-purpose area instead of a breadboard. Here you can mount the component temporary or solder your circuit that is to be interfaced with the controller. Also it does not come in wooden packing.
The SLK-51 is the first of its kind of platform designed for users who are undergoing 8051 curriculum. Large number of exercises can be tried out on SLK-51 board, which will enable the users to confidently undertake their projects and application development.
Also both the EPB/SLK-51 has the capability of in-circuit programming which will eliminate the need of any external programmer or eraser. You can write and erase the chip memory (64K) for number of times.
This approach will lead you to develop your project in the way professionals do.
Generally, you should try to develop any idea or project in a modular way. You should divide the application into different modules and first try them individually. Later you can club these modules once tested into a full fledge application.
This exercises requires number of writing and erasing actions, which can be easily done on this boards. Also all the port pins are available at your dispersal and you can use them as per your requirement.
Thus unlike a conventional kit it does not restrict you to use only limited features and lets you work to derive a truly single chip solution.
Chapter 2
Features of EPB/SLK-51
The Educational Practice Board/Self Learning Card (SLK-51) consists of the following feature:
Features of EPB/SLK-51:
1) Single chip design with 89C51RD2 chip.
2) In circuit programming facility thus eliminating the need of having a separate programmer.
3) On board 64k Flash Program Memory.
4) On board power supply.
5) Serial connectivity to PC with on-board serial link.
6) General-purpose area to interface your own circuits.
7) All port pins brought to general-purpose area along with power supply to enable quick and easy circuit building.
8) Facility to interface additional board either provided by Edutech or design by third party.
9) Low cost & specially designed for students undergo 8051 curriculum & projects.
10) Large number of practice examples and softwares like assembler
bundled with the accompany CD.
Chapter 3
Before you install
Packing List:
Before installing the EPB/SLK-51 take a moment to enable your package content to make sure you received everything.
In addition to this manual, the Educational Practice Board package should include:
1) The EPB packed in a wooden box
2) Component box
3) Programming cable
4) CD ROM containing examples and utilities
5) Product Registration/Feedback card
The Self Development Kit (SDK-51) pack should include:
1) The Self-learning kit SLK-51
2) Specially Designed General-purpose Board (GPB-51)
3) Programming cable/Flat Cable
4) CD ROM
5) Feedback/Registration Card
System Requirement:
The EPB/SLK-51 card has to be connected to the PC using the programming cable provided with the pack. The programs are to be developed on the PC using the utility tools provided and then transferred to the EPB/SLK-51. Hence the PC should have the following specification:
Pentium PC with available serial port
Microsoft Windows 95/98 or above
CD drive for installation
10 MB Hard disk space
16 MB RAM (32 MB or above preferred)
Windows compatible mouse
Chapter 4
Understanding the EPB/SLK-51
The Block Diagram
Block Description:
The power supply:
The EPB/SLK-51 card works on a +5 volt supply. The power unit provided along with the package consists of an adapter, which takes 230V as input and gives 9V AC as output. This 9V AC supply is plugged into the card. The onboard power circuit rectifies and generates a regulated +5V supply.
The supply is also made available at the general-purpose area to enable easy interface. It is also made available to the expansion slot so that the same power supply can be used for powering the additional interface cards. These cards can be either third party cards or proprietary interfacing cards provided by Edutech Systems. Some of these cards include LCD/keyboard, EEPROM, RTC, 7-segment, ADC, DAC, stepper motor interfacing cards etc.
The CPU -
The EPB/SLK-51 contains 89C51RD2 controller from Philips. This controller is pin-to-pin compatible with our conventional 8051/89C51 CPU. The card has been designed to support 89C51 variants.
Due to various advantages and unique features, we have selected 89C51RD2. Though it is costly compared to 89C51, we have selected it to provide the users, the exposure of latest trend in the industry and also make the user aware of different features that eliminate certain conventional requirement.
The EPB/SLK-51 has a unique feature of In-circuit programming. Because of this feature, you can write and erase the chip without even removing it from the socket. Thus you need not require any programmer unit to program or erase the on-board chip.
Also you enjoy a full 64KB of flash program memory. Thus you can design application that requires more program memory. Also because of the facility of allowing number of write/erase operation, you can easily develop your programs in modular way. These modules can be loaded and tested individually and later they can be merged with the main program. Thus because of these features, you can easily do your R & D activity.
Moreover for those users who are new to the concept and are learning & applying controller for the first time, can find this feature useful as they can easily rectify & modify errors in their development programs.
Apart from these features, the chips have lot of other advantages. Details can be studied referring to the data sheets.
Serial Port:
Since the EPB/SLK-51 is required to be connected to the PC, there exists an on-board serial port. The program has to be developed using an IBM-PC. Different tool sets can be used to develop the programs and convert them to hex file format. The hex file is then copied to the board through the serial port. Because there is a facility of in-circuit programming, we can directly transfer the hex file to the board. The transfer is possible with the help of virtual soft-programmer. More details of this virtual soft programmer can be referred in the coming chapter.
To facilitate the downloading of the programs to the board, a programming cable is provided in the pack.
Switch:
A special switch is provided on-board to select the mode of operation. Because as discussed earlier, there is a facility of downloading a program to the board and also to erase this program. Hence there are two modes of operations i.e., the RUN mode and the Programming mode. In the RUN mode, the program downloaded to the board executes. In the program mode, you can either erase the on-board program or download a new program.
So to select the above mentioned option, a selector switch is provided. You can press the switch to one position so that it selects the program made. The release of the switch will again make the board into RUN mode. Two LEDs are also provided to visually make sure that proper selection of the option/mode is selected. The red LED will glow if the program mode is selected and the green LED will glow if the RUN option is selected. This visual indication makes it easy to confirm the mode selection.
It is important to note that while changing the mode from PROGRAM to RUN or vice versa, the power supply to the board should be made OFF. The ON/OFF button provided on the power unit can be used to ON/OFF the supply to the board. If this precaution is not taken, it is likely to damage the chip.
General purpose Area:The EPB/SLK-51 provides a general-purpose area for the user to practice and interface number of components to the CPU. The EPB contains a breadboard arrangement where the components can be inserted temporarily and the interface can be studied. This arrangement is generally suitable at an institute lab, where the components are to be reused and a large number of users are supposed to try the interface. In case of SLK-51, there exits a general purpose area where components can be temporary placed or directly mounted. The general-purpose space becomes very useful for the user doing some project around the SLK-51. Looking to the card keeping the CPU on the topside, we see the following picture.
P3.7 P0.0
G G
N N
D D
+5 V
+5 V
The availability of +5 volts and ground on to the general-purpose area makes the interfacing more easy and simple. The breadboard has many strips.
The first block contains all the port line from P0.0 to P3.7. Remaining 4 block consists of general-purpose area. Ground and +5v are also available. The arrangement hole is such that vertically the holes are short. This makes the insertion of the component easy and more number of components can be connected easily. Thus in the first block, 3 holes vertically are shorted while in remaining block 4 holes are shorted vertically.
Expansion Slots:
Connecting other cards provided by Edutech Systems or any other third party can further expand the EPB/SLK-51 card. The expansion slots have got all the port-pins along with supply signal. These exist, two such slots (JP1 and JP2) whose details are given below. JP1A and JP2A replicates JP1 & JP2 for further use.
We provide different cards like LCD/keyboard interface, 7-segment/keyboard interfaces, E2PROM/RTC interface, ADC/DAC interface etc. These different cards can be directly plugged with the EPB/SLK-51 and can be used to study and perform exercises using particular cards.
For more details you can contact us on [email protected] or visit our site: www.edutechonline.comChapter 5
Virtual Programmer
The EPB/SLK-51 has to be connected to the PC using the serial cable. The program that is developed using the development tools is to be downloaded to the board.
Since this board has the facility of in-system programming, we can download or erase the program on board without using any programmer device or even without removing the chip from the socket. This will avoid the damage to the chip as well as it will be very easy to keep on experiment without bothering about the programmer device.
To enable you to download the programs to the board, we provide a virtual program utility (WINISP) bundled with the package. This utility is from Philip and supports the onboard chip.
To start using the virtual program first you have to install the utility from the CD provided with the pack. You can click the WINISP.exe to install the program. Follow the instructions on the screen and complete the installation. You can restart the computer if required. The program then can be accessed from the start menu and program option you can even create a shortcut on the desktop. Now let us see the virtual programmer screen layout. The screen shows the layout of the WINISP utility.
Chapter 6
Operating Steps
Instructions to use the
Educational Practice Board (EPB) / Self Learning Card (SLC)
The Educational Practice Board/ SLC is a general-purpose experiment board designed to interface any relevant circuit and check the program execution. This board is accompanied with different accessories like the power unit, the programming cable and a CD-ROM. To use this board, follow the following procedure:
1) From the CD provided, install the WINISP program to your computer. This is a virtual programmer used to program the on-board CPU. You can also use the Integrated Programming Tool (ITP) provided on the CD ROM for accessing the virtual programmer utility. The CPU provided on the board is having a unique In-System Programming facility so that you can write and erase number of your test programs without removing the chip from the circuit.
2) Now connect the board to the serial port of your PC using the Programming cable provided.
3) From the Start option on your PC, run the WINISP program. You can also use the IPT utility to execute the WINISP program. Select the proper chip: 89C51RD2 from the chip select option. Select the communication port and the crystal frequency (6 MHz in our case).
4) You will find a switch (Blue in color) called as the mode switch. This switch when pressed enables the card in either (a) Run mode ( green LED ON or (b) Program mode ( Red LED ON. To erase the memory, the chip should be in the program mode and to execute the program, the chip should be in the RUN mode.
Note that the power supply should be made OFF when the mode is changed from RUN to PROGRAM or vice-versa.
5) After selecting the PROGRAM option, on the board click on the Erase Block option and select the first block sing the WINISP program.
Note: Do not select the Full Chip Erase option. Erase the selected block by choosing the Erase block option. This will indicate the block erasure. If there is any communication error, check the port connection and selection. Switch the power supply OFF and then make it ON again and retry.
6) Now click on LOAD FILE & load the required hex file. Status displays File loaded. This HEX file can be generated by using the Assembler tool or the IDE provided with the package. Now click the Program Part and wait till the status displays Programming Successful.
Caution: DO NOT TOUCH THE MISC BLOCK.
7) Now switch OFF the power & change the mode to execution mode (green LED ON) by pressing the mode switch once. Now switch ON the power supply and you can see the green LED ON. Also observe the execution of the program.
Chapter 7
Integrated Programming Tool
By this time, you must be conversant with the EPB/SLK-51 card. Now let us try to understand how write a program, assemble it and transfer it to the EPB/SLK-51.
There exists various tools like Assembler, Text editor, C-cross compiler, Simulator/Debugger, Terminal software etc. which can be used to develop 8051 program on PC.
The CD enclosed in the package for EPB/SLK-51 consists of a utility - the Integrated Programming Tool. This tool is an interface, which allows you to write a program in note pad assemble the programs to generate .bin, .prn and .hex files and further allows you to transfer the hex file to the EPB.
The utility is available on the CD (IPT folder). You have to copy this folder to the windows directory of your systems. The ipt.exe file can be copied to the folder of your choice or you can create a shortcut for easy access. The IPT folder consists of different tools like notepad, winisp, assembler and bin2hex converter utility. The assembler and the bin2hex converter utility are DOS based utilities and hence it requires you to go to the DOS prompt. T
The IPT-utility software allows the user to edit and assemble .asm programs and than convert into HEX file on just one click!. This software is developed to reduce the time needed to assemble the ASM program and then converting that assembled program to HEX file. Generally, we have to do this from DOS Prompt, since assembler and hex converters are DOS based program. But using this software, you need not have to go to DOS prompt every time you want to generate .bin and then .hex file from your .asm files. For more details about the IPT, refer the help file provided with the IPT.
The IPT-Utility screen is shown below:
Writing the first program using the assembler utility:
To start with, we will use the assembler provided with the pack to write our first program.
In this case, we try to write a program to interface a simple LED to the port pin P1.0 of the EPB/SLK-51. The LED is provided along with the package. You can connect to the LED to the port pin P1.0 as shown.
To momentary check the program, you can connect the LED to the port directly. Now we write a program such that the LED connected to the port pin P1.0 blinks continuous at the rate of 1 second.
Follow the following procedure to develop the first program.
1. Copy the IPT folder to windows directory and then run the ipt.exe file.
2. Give the program name and then type the following program in the notepad window, which will be automatically invoked.
Program:
pin bit p1.0
org 0000h
sjmp main
org 0060h
main:clr pin
mov a,#4
acall delay
setb pin
mov a,#4
acall delay
sjmp main
delay:
again:mov r5,#250
sec:mov r7,#0a6h
onemil:nop
nop
nop
nop
djnz r7,onemil
djnz r5,sec
dec a
jnz again
ret
sjmp $
3. Click the respective buttons on the screen to generate the required output. Once the hex file is generated, we transfer it to the EPB/SLK-51 card. Select the program mode option (Red LED ON) and power on the board. Using the WinISP button the virtual programmer is invoked. Proper selection of chip, crystal frequency (6 MHz in our case), communication port is made. The file generated is opened using the menu. The block 0 is first erased and run the program is loaded into the board using program port option. The screen indicates successful completion of the task. If not recheck the cable connection, switch off the EPB/SLK-51 power and resect the above procedure. Note that the selection has to be in Program mode.
4. Now switch off the power and change the mode to RUN mode and make the power ON again. The Green LED should glow.
5. Observe the LED. It should be blinking so that, if you can now try more exercises and use the EPB/SLK-51 to learn more programming concepts, interface number of component and finally carry out your project work using the EPB/SLC.
Note: If you are using the IDE tool, type the program in the editor & then save it as .asm file. From the compile menu, select Assembler a file option. This will generate a hex file, which can be further downloaded in the EPB/SLK-51.
If you have any difficulty, please contact us.
You can write number of programs using the Educational Practice Board and interfaced number of interface devices using the general-purpose board. You can also refer to the Curriculum Workbook for more practice examples.
Also the EPB/SLK-51 is an embedded study kit with number of embedded routines for interfacing different components like the LCD, keyboard, ADC, Serial EEPROM, RTC etc. You can use these embedded routines to develop project based application or some real time applications using the EPB. These routines will enable you to develop applications and appreciate the strength of Microcontroller.
These routines can also be best used for testing the hardware developed by you. You can interface the interface hardware to the EPB and write the program using the embedded routines and assure that the hardware developed by you is working properly.
Let us try to understand the embedded routines and see how to write the interface related programs using these routines. Note that you have to define the hardware port pin allocation in the program itself as the embedded routines are generalized routines. Thus you can use these routines to test and develop programs for your own hardware.
Following chapter discusses more on these embedded routines and demonstrates some interface program examples. You can refer the curriculum workbooks for more practice examples or write to us at [email protected] for any assistance needed for developing your project-based applications using the embedded routines.
Chapter 8
Embedded Driver Routines
Introduction
The Educational Practice Board/SLK-51 optionally contains embedded driver routines. These routines can be used to study different concepts of 8051 programming. They can also be used to directly interface devices like LCD and Keyboard etc.
The EPB/SLK-51 has a 64KB of on-chip flash memory. These drivers are embedded into the chip memory. Thus part of the flash memory is used in embedding these drivers. As a result, the first 32KB of flash program memory can be used for writing your programs.
You have to note that the last 32KB of program memory should not be erased. This memory space contains the driver routines as well as the serial-communication routines need to upload or download the programs from the PC. Erasing the last 32KB of memory content will result in the erasure of the embedded programs and the chip will function as normal 89C51 chip. You then will require external programmer since the WINISP will not communicate with the chip.
To be more precise, the last 32KB of space is divided into two parts of 16KB each (last two memory blocks as seen from the WINISP). The first 16KB i.e. the 3rd block contains the drivers and the last block contains the communication routines. If the 3rd block is erased, the driver routines will be lost. You can still use this space to save your programs.
Thus, its better to avoid using/erasing the last 32KB of memory space.
Memory map:
0
8K
16K
32K
48K
64K
Description of Embedded Drivers:
The Embedded Driver routines on the chip can be referred using their direct address. To simplify the addressing of these routines, the locations are mapped to some variable names. These names can be directly mentioned in the programs. To make the programming still simpler, separate header files are provided which can be included in the main program.
The first header file is location.h. This file is to be included in the main program. It defines the location of various embedded drivers incorporated in the chip. With this feature you can access the driver routine using a specific name instead of numeric value of the location. There are two advantages of using this header file. Firstly you need not remember the numeric locations while using the embedded routines and secondly in case of upgradation of these embedded routines, your main programs need not to be modified.
The second header file is the embedded.h defines the hardware interface in terms of pin allocation w.r.t different components. The Embedded Driver routines are so designed that you can define your own pin assignments for interfacing different components.
The Embedded.h file links the embedded routines and the pin assignments. You have to mention the allocation of port pins in the main program written by you. Thus you must include this header file when you use the embedded driver features while interfacing the components.
The following lines describe how to use the header files for writing a application program.
MOV R0, # Variable ; Variable name as per the embedded.h definition.
MOV @R0, #Port/Port-pin ; connected port/port-pin
Let us understand the use of header files with some example:
Suppose we interface a LCD to microcontroller such that 8 data lines of LCD are connected to say port 0. The controls lines like LCD enable EN pin is connected to port pin P1.0 and the LCD register select RS pin is connected to port pin P1.1. The declaration of the above assignment is as follows:
MOV R0, #lcd8d ; Variable for LCD Data Lines as per embedded.h
MOV @R0, #00h ; 00h defines port - 0
MOV R0, #lcd8en ; Variable for LCD Enable Line as per embedded.h
MOV @R0, #10h ; 10h defines port pin P1.0
MOV R0, #lcd8rs; Variable for LCD Register Select Line as per
;embedded.h
MOV @R0, #11h ; 11h defines port pin P1.1
The following table enlists different drivers embedded into the chip. The table consists of Component/Function name, description of the embedded routine, variable name used in location.h file and program location.
With the help of these standard routines, it becomes easy to interface number of devices like LCD, keyboard, ADCs, RTC, EEPROM etc as per your own pin assignments and develop an application around it.
Table1:
Component / FunctionDescription Of Embedded RoutineVariable UsedProgram Location
DelayDelay in milliseconddelay_ms80ffh
LCD
(4 bit data bus)LCD Initialization
LCD command
LCD datalcd4_init
lcd4_cmd
lcd4_dat
812ch
81b0h
8217h
LCD
(8 bit data bus)LCD Initialization
LCD command
LCD datalcd8_init
lcd8_cmd
lcd8_dat0
8289h
82eeh
8334h
Matrix Keyboard (5x5)Key detectkeybrd_5837ah
Matrix Keyboard (4x4)Key detectkeybrd_4846bh
Matrix Keyboard (3x3)Key detectkeybrd_3853fh
Matrix Keyboard (2x2)Key detectkeybrd_285feh
7 segment7 segment initialization
7 segment interruptseg_init
seg_int86b9h
86e9h
RTC (connected at p3.6 & p3.7)RTC write
RTC readrtc_write
rtc_read87a0h
8727h
EEPROM (connected at p3.6 & p3.7)EEPROM write
EEPROM readwrite_srom
read_srom8669h
88b0h
Parallel ADC (8 bit)ADC readadc_read8980h
Serial ADC (connected at p3.6 & p3.7)Serial ADC readssadc_read8a3bh
Component / FunctionDescription Of Embedded RoutineVariable UsedProgram Location
Graphic LCDGraphic LCD initialization
Graphic LCD display on
Graphic LCD display off
Graphic LCD start line (cs1)
Graphic LCD start line (cs2)
Graphic LCD page (cs1)
Graphic LCD y-Address (cs1)
Graphic LCD page (cs2)
Graphic LCD y-address (cs2)
Graphic LCD Data (cs1)
Graphic LCD Data (cs2)
Graphic LCD clear screen (cs1)
Graphic LCD clear screen (cs2)
glcd_init
glcd_dispon
glcd_dispoff
glcd_srtlin1
glcd_srtlin2
glcd_page1
glcd_yadd1
glcd_page2
glcd_yadd2
glcd_send1
glcd_send2
glcd_clr1
glcd_clr28a7ah
8ae6h
8b43h
8ba0h
8beah
8c34h
8c7eh
8cc8h
8d12h
8d5ch
8da0h
95f5h
9629h
PrinterPrinter initialization
Print characterpri_init
print8e8fh
8eaah
CounterCounter initializationcounter8ee1h
Serial Communication (Mode 1)Serial communication initialization
Transmit character
Receive characterser1_init
transmit1
receive18f08h
8f19h
8f23h
Serial Communication (Mode 2)Serial communication initialization
Transmit character
Receive characterser2_init
transmit2
receive28f2eh
8f3fh
8f42h
Serial ADC (connected at p0.1 & p0.2)Serial ADC readsadc_read949fh
EEPROM (connected at p0.6 & p0.7)EEPROM write
EEPROM readwrite_rom
read_rom94deh
9525h
The following table enlists the register or location that must be used to pass / receive the parameter in order to access the embedded drive routine. Further note that we should not use the particular associated location in your main program elsewhere.
Table2:
Component / FunctionRelated Register / LocationParameter
LCD
70h
Command / Data write
Keyboard (All types)71h
Returns key code
7 Segment60h
61h
62h
63h
64h
65h
66h
67h
Data for Digit 1
Data for Digit 2
Data for Digit 3
Data for Digit 4
Data for Digit 5
Data for Digit 6
Data for Digit 7
Data for Digit 8
RTC68h
69h
6ah
6bh
6ch
6dh
6eh Second (write/read)
Minute (write/read)
Hour (write/read)
Day (write/read)
Date (write/read)
Month(write/read)
Year (write/read)
EEPROM
(All types)7bh
7ch
7dh
7ehData 1
Data 2
Data 3
Data 4
Parallel ADC79h
7ahChannel selection
Data (read)
Serial ADC
(All types)5eh
5fh
Data(lower byte)
Data(higher byte)
Component / FunctionRelated Register / LocationParameter
Graphic LCD72h
73h
74h
75h
76h
77h
78h
Data (CS1/CS2)
Startline (CS1)
Page (CS1)
Y-address (CS1)
Startline (CS2)
Page (CS2)
Y-address (CS2)
Printer6fhData (write)
Counter 5ch
5dhLower byte
Higher byte
Serial Communication
(All types)5bhTransmit/Receive
The following table enlists the variable name that must be used to defined the port or port pin at which the desired component is required to be connected. Reference to the programs given in Project Essentials workbook will make it clear how to use these variable names.
Table3:
ComponentVariable UsedDescription
LCD
(4 bit data bus)Lcd4d
Lcd4en
Lcd4rslcd4 data(port) first four pins will get configured
lcd4 enable(port pin)
lcd4 register select(port pin)
LCD
(8 bit data bus)Lcd8d
Lcd8en
Lcd8rslcd8 data(port)
lcd8 enable(port pin)
lcd8 register select(port pin)
Matrix Keyboard (5x5)kbrd5c1
kbrd5c2
kbrd5c3
kbrd5c4
kbrd5c5
kbrd5r1
kbrd5r2
kbrd5r3
kbrd5r4
kbrd5r5
keyboard column 1(port pin)
keyboard column 2(port pin)
keyboard column 3(port pin)
keyboard column 4(port pin)
keyboard column 5(port pin)
keyboard row 1(port pin)
keyboard row 2(port pin)
keyboard row 3(port pin)
keyboard row 4(port pin)
keyboard row 5(port pin)
Matrix Keyboard (4x4)kbrd4c1
kbrd4c2
kbrd4c3
kbrd4c4
kbrd4r1
kbrd4r2
kbrd4r3
kbrd4r4
keyboard column 1(port pin)
keyboard column 2(port pin)
keyboard column 3(port pin)
keyboard column 4(port pin)
keyboard row 1(port pin)
keyboard row 2(port pin)
keyboard row 3(port pin)
keyboard row 4(port pin)
ComponentVariable UsedDescription
Matrix Keyboard (3x3)kbrd3c1
kbrd3c2
kbrd3c3
kbrd3r1
kbrd3r2
kbrd3r3keyboard column 1(port pin)
keyboard column 2(port pin)
keyboard column 3(port pin)
keyboard row 1(port pin)
keyboard row 2(port pin)
keyboard row 3(port pin)
Matrix Keyboard (2x2)kbrd2c1
kbrd2c2
kbrd2r1
kbrd2r2keyboard column 1(port pin)
keyboard column 2(port pin)
keyboard row 1(port pin)
keyboard row 2(port pin)
7 segmentsegdat
seldig7 segment data
Selects Digit in which data is to be displayed(port)
Parallel ADC (8 bit)padcadr
padcsoc
padceoc
padcale
padcdatADC address line(port) first three pins will get configured
ADC start of conversion line(port pin)
ADC end of conversion line(port pin)
ADC ALE line(port pin)
ADC data(port)
Graphic LCDGlcddat
Glcddi
glcden
glcdcs1
glcdcs2
glcdrst
glcdrw
Graphic lcd data(port)
Graphic lcd D/I(port pin)
Graphic lcd enable pin(port pin)
Graphic lcd cs1 pin(port pin)
Graphic lcd cs2 pin(port pin)
Graphic lcd rst pin(port pin)
Graphic lcd rw pin(port pin)
Printerprdat
pbusy
pinit
pstrobPrinter data(port)
Printer busy(port pin)
Printer initialization(port pin)
Printer strobe(port pin)
The following is the listing of the header files that is required during the assembly of the program. You may refer to the 'Project Essentials' workbook where more than 100 program examples are discussed demonstrating the usage of the embedded driver routines. We are sure that the reference of the Project Essentials workbook you will acquaint yourself with the strength of the embedded routine and start developing practical applications.
HEADER FILES:
Location.h:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DELAY
delay_ms
equ
80ffh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCD4
lcd4_init
equ
812ch
lcd4_cmd
equ
81b0h
lcd4_dat
equ
8217h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LCD8
lcd8_init
equ
8289h
lcd8_cmd
equ
82eeh
lcd8_dat
equ
8334h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; KEYBOARD 5*5
keybrd_5
equ
837ah
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; KEYBOARD 4*4
keybrd_4
equ
846bh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; KEYBOARD 3*3
keybrd_3
equ
853fh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; KEYBOARD 2*2
keybrd_2
equ
85feh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7-SEGMENT
seg_init
equ
86b9h
seg_int
equ
86e9h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RTC
rtc_write
equ
87a0h
rtc_read
equ
8727h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEPROM SAME LINE
write_srom
equ
8669h
read_srom
equ
88b0h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; P_ADC
adc_read
equ
8980h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; S_ADC SAME LINE
ssadc_read equ
8a3bh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GRAPHIC LCD
glcd_init
equ
8a7ah
glcd_dispon
equ
8ae6h
glcd_dispoff
equ
8b43h
glcd_srtlin1
equ
8ba0h
glcd_srtlin2
equ
8beah
glcd_page1
equ
8c34h
glcd_yadd1
equ
8c7eh
glcd_page2
equ
8cc8h
glcd_yadd2
equ
8d12h
glcd_send1
equ
8d5ch
glcd_send2
equ
8da0h
glcd_clr1
equ
95f5h
glcd_clr2
equ
9629h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PRINTER
pri_init
equ
8e8fh
equ 8eaah
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; COUNTER
counter equ
8ee1h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SERIAL TRANSMISSION MODE1
ser1_init
equ
8F08h
transmit1
equ
8F19h
receive1
equ
8F23h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SERIAL TRANSMISSION MODE2
ser2_init
equ
8F2Eh
transmit2
equ
8F3Fh
receive2
equ
8F42h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; S_ADC
sadc_read equ
949fh
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EEPROM
write_rom
equ
94deh
read_rom
equ
9525h
Embedded.h:
;;;;;;;;;;;;;;;;;;;LCD 4 bit;;;;;;;;;;;;;;;;;
lcd4d
equ a0h;lcd4 data(port) first four pins will get configured
lcd4en
equ a1h;lcd4 enable(port pin)
lcd4rs
equ a2h;lcd4 register select(port pin)
;;;;;;;;;;;;;;;;;;;LCD 8 bit;;;;;;;;;;;;;;;;;
lcd8d
equ a3h;lcd8 data(port)
lcd8en
equ a4h;lcd8 enable(port pin)
lcd8rs
equ a5h;lcd8 register select(port pin)
;;;;;;;;;;;;;;;;;;;Keyboard 5x5;;;;;;;;;;;;;;;;;
kbrd5c1equ a6h;keyboard column 1(port pin)
kbrd5c2equ a7h;keyboard column 2(port pin)
kbrd5c3equ a8h;keyboard column 3(port pin)
kbrd5c4equ a9h;keyboard column 4(port pin)
kbrd5c5equ aah;keyboard column 5(port pin)
kbrd5r1equ abh;keyboard row 1(port pin)
kbrd5r2equ ach;keyboard row 2(port pin)
kbrd5r3equ adh;keyboard row 3(port pin)
kbrd5r4equ aeh;keyboard row 4(port pin)
kbrd5r5equ afh;keyboard row 5(port pin)
;;;;;;;;;;;;;;;;;;;Keyboard 4x4;;;;;;;;;;;;;;;;;
kbrd4c1equ b0h;keyboard column 1(port pin)
kbrd4c2equ b1h;keyboard column 2(port pin)
kbrd4c3equ b2h;keyboard column 3(port pin)
kbrd4c4equ b3h;keyboard column 4(port pin)
kbrd4r1equ b4h;keyboard row 1(port pin)
kbrd4r2equ b5h;keyboard row 2(port pin)
kbrd4r3equ b6h;keyboard row 3(port pin)
kbrd4r4equ b7h;keyboard row 4(port pin)
;;;;;;;;;;;;;;;;;;;Keyboard 3x3;;;;;;;;;;;;;;;;;
kbrd3c1equ b8h
;keyboard column 1(port pin)
kbrd3c2equ b9h
;keyboard column 2(port pin)
kbrd3c3equ bah
;keyboard column 3(port pin)
kbrd3r1equ bbh
;keyboard row 1(port pin)
kbrd3r2equ bch
;keyboard row 2(port pin)
kbrd3r3equ bdh
;keyboard row 3(port pin)
;;;;;;;;;;;;;;;;;;;Keyboard 2x2;;;;;;;;;;;;;;;;;
kbrd2c1equ beh
;keyboard column 1(port pin)
kbrd2c2equ bfh
;keyboard column 2(port pin)
kbrd2r1equ c0h
;keyboard row 1(port pin)
kbrd2r2equ c1h
;keyboard row 2(port pin)
;;;;;;;;;;;;;;;;;;;7segment;;;;;;;;;;;;;;;;;
segdatequ c2h
;7 segment data
seldig
equ c3h
;Selects Digit in which data is to be
;displayed(port)
;;;;;;;;;;;;;;;;;;;ADC 8-bit;;;;;;;;;;;;;;;;;
padcadrequ c4h
;ADC address line(port) first three pins
;will get configured
padcsocequ c5h
;ADC start of conversion line(port pin)
padceocequ c6h
;ADC end of conversion line(port pin)
padcaleequ c7h
;ADC ALE line(port pin)
padcdatequ c8h
;ADC data(port)
;;;;;;;;;;;;;;;;;;;Graphic LCD;;;;;;;;;;;;;;;;;
glcddatequ c9h
;Graphic lcd data(port)
glcddi
equ cah
;Graphic lcd D/I(port pin)
glcden
equ cbh
;Graphic lcd enable pin(port pin)
glcdcs1equ cch
;Graphic lcd cs1 pin(port pin)
glcdcs2equ cdh
;Graphic lcd cs2 pin(port pin)
glcdrst
equ ceh
;Graphic lcd rst pin(port pin)
glcdrw
equ cfh
;Graphic lcd rw pin(port pin)
;;;;;;;;;;;;;;;;;;;Printer;;;;;;;;;;;;;;;;;
prdat
equ d0h
;Printer data(port)
pbusy
equ d1h
;Printer busy(port pin)
pinit
equ d2h
;Printer initialization(port pin)
pstrob
equ d3h
;Printer strobe(port pin)
;;;;;;;;;;;;;;;;;;;I2C RTC;;;;;;;;;;;;;;;;;
irtcdat
equ d4h
;i2c RTC data(port pin)
irtcscl
equ d5h ;i2c RTC clock(port pin)
;;;;;;;;;;;;;;;;;;;I2C ADC;;;;;;;;;;;;;;;;;
iadcadr equ d6h
;i2c ADC address line(port) first three
;pins must be configured
iadcdatequ d7h
;i2c ADC data(port pin)
iadcsclequ d8h
;i2c ADC clock(port pin)
Chapter 9
Embedded Driver Description & Example Programs
1. Delay:
This driver routine is a general-purpose routine to generate delay. This routine is embedded into the memory to enable the easy use of delay routine. The delay routine is many times required to interface the devices and develop an application. The user can thus call the delay routine and pass appropriate parameter to the routine. Depending on the delay requirement, the parameter value can be decided. This value can be 16-bit value from 0000h to FFFFH. The lower byte is to be stored in the accumulator and the higher byte in the B register. The delay routine embedded in the chip is for generating a basic delay of 1 milli second. Depending on the count parameter, you can thus get a delay from 1 ms (for 0001H count) to 65.535 seconds (FFFFH)
Program location: 80ffh
Location name: delay_ms
Count parameter location: Lower byte in Accumulator and higher byte
in B register.
2. The LCD driver for 4 Bit Interface:
The LCD embedded driver consists of three subroutines: (i) LCD initialization, (ii) LCD command and (iii) LCD data. These routines are to be called from the main program by using the appropriate variable name. The details of these routines are as follows:
The LCD Initialization Routine:
This routine can be used to initialize the LCD connected at port as defined by the user.
Program location: 812ch
Location name: lcd4_init
The LCD Command routine:
This routine can be used to send different commands to the LCD such as position of the cursor, shift cursor/screen, font size, etc.
Program location: 81b0h
Location name: lcd4_cmd
Command parameter location: 70h
LCD data routine:
This routine passes the data that is to be displayed on the LCD module.
Program location: 8217h
Location name: lcd4_dat
Data parameter location: 70h
Let us make clear how to use these routines by considering following program.
Suppose LCD is connected in 4-bit interface mode as per the following connections.
8051 Port PinsLCD Module (16 X 2)
P2.0D4 LCD Data Pin
P2.1D5 LCD Data Pin
P2.2D6 LCD Data Pin
P2.3D7 LCD Data Pin
P2.4EN Enable LCD
P2.5RS Register Select
The following must be incorporated in your program to make the above connections working:
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
Now let us write a program to display 'A' on default position:
Test Program:
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
;LCD initialization routine
mov 70h,#'A'
;31h is LCD data location
lcall lcd4_dat
;LCD data display routine
sjmp $
3. The LCD driver for 8 Bit Interface:
This LCD embedded driver is meant for 8-bit data bus interface. As mentioned above it also consists of three subroutines: (i) LCD initialization, (ii) LCD command and (iii) LCD data. These routines are to be called from the main program by using the appropriate variable name. The details of these routines are as follows:
The LCD Initialization Routine:
This routine can be used to initialize the LCD connected at port as defined by the user.
Program location: 8289h
Location name: lcd8_init
The LCD Command routine:
This routine can be used to send different commands to the LCD such as position of the cursor, shift cursor/screen, font size, etc.
Program location: 82eeh
Location name: lcd8_cmd
Command parameter location: 70h
LCD data routine:
This routine passes the data that is to be displayed on the LCD module.
Program location: 8334h
Location name: lcd8_dat
Data parameter location: 70h
Let us make clear how to use these routines by considering following program.
Suppose LCD is connected in 8-bit interface mode as per the following connections.
8051 Port PinsLCD Module (16 X 2)
P0LCD Data Pin
P2.1EN Enable LCD
P2.0RS Register Select
P2.6RD/WR Read/Write Pin
The following must be incorporated in your program to make the above connections working:
clr p2.6;make RD/WR pin of LCD low to make ;LCD write enable
mov r0, #lcd8d
mov @r0, #00h
mov r0, #lcd8en
mov @r0, #21h
mov r0, #lcd8rs
mov @r0, #20h
Now let us write a program to display 'VARUN' at centre position:
Test Program:
include embedded.h
include location.h
org 00h
mov sp, #7fh
clr p2.6;make RD/WR pin of LCD low to make ;LCD write enable
mov r0, #lcd8d
mov @r0, #00h
mov r0, #lcd8en
mov @r0, #21h
mov r0, #lcd8rs
mov @r0, #20h
lcall lcd8_init
;LCD initialization for 8-bit mode
mov 70h, #85h
lcall lcd8_cmd
;LCD command for 8-bit mode
mov 70h, #'V'
lcall lcd8_dat
;LCD data for 8-bit mode
mov 70h, #'A'
lcall lcd8_dat
mov 70h, #'R'
lcall lcd8_dat
mov 70h, #'U'
lcall lcd8_dat
mov 70h, #'N'
lcall lcd8_dat
sjmp $
4. The 5 x 5 Matrix Keyboard driver:
This routine is meant to detect the pressed key. The main routine checks if the flag bit 2f.7h is high. In the embedded routine the flag bit 2f.7h is made high if a valid key is pressed. If you are using loop means you want to consecutively check the pressed key, make sure that flag 2f.7h is cleared before entering in to the loop. If you want to check the pressed key only once, no need to clear the flag 2f.7h. After the key pressed, the key code is available at RAM location 71h. Here key code means row/column combination is moved to 71h.
For eg.
If you press F1 key then 22h is moved to 71h,here 22h means 2nd row and 2nd column.
Program location: 837ah
Location name: keybrd_5
Key code location: 71hLet us make clear how to use this routine by considering following program.
Suppose 5 x 5 matrix keyboard is connected as per the following connections.
8051 Port Pins5 X 5 Matrix Keyboard
P1.0Column1 of Keyboard
P1.1Column2 of Keyboard
P1.2Column3 of Keyboard
P1.3Column4 of Keyboard
P1.4Column5 of Keyboard
P1.5Row 1 of Keyboard
P1.6Row 2 of Keyboard
P1.7Row 3 of Keyboard
P3.6Row 4of Keyboard
P3.7Row 5 of keyboard
The following must be incorporated in your program to make the above connections working:
mov r0, #kbrd5c1
mov @r0, #10h
mov r0, #kbrd5c2
mov @r0, #11h
mov r0, #kbrd5c3
mov @r0, #12h
mov r0, #kbrd5c4
mov @r0, #13h
mov r0, #kbrd5c5
mov @r0, #14h
mov r0, #kbrd5r1
mov @r0, #15h
mov r0, #kbrd5r2
mov @r0, #16h
mov r0, #kbrd5r3
mov @r0, #17h
mov r0, #kbrd5r4
mov @r0, #36h
mov r0, #kbrd5r5
mov @r0, #37h
Let us write a program to display keycode of pressed key
Test Program:
include embedded.h
include location.h
org 0
mov sp,#7fh
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
mov r0, #kbrd5c1
mov @r0, #10h
mov r0, #kbrd5c2
mov @r0, #11h
mov r0, #kbrd5c3
mov @r0, #12h
mov r0, #kbrd5c4
mov @r0, #13h
mov r0, #kbrd5c5
mov @r0, #14h
mov r0, #kbrd5r1
mov @r0, #15h
mov r0, #kbrd5r2
mov @r0, #16h
mov r0, #kbrd5r3
mov @r0, #17h
mov r0, #kbrd5r4
mov @r0, #36h
mov r0, #kbrd5r5
mov @r0, #37h
lcall lcd4_init
;LCD initialization routine
again:mov 70h,#80h
lcall lcd4_cmd;lcd cmd
mov 70h,#'K'
lcall lcd4_dat
mov 70h,#'e'
lcall lcd4_dat
mov 70h,#'y'
lcall lcd4_dat
mov 70h,#'='
lcall lcd4_dat
wait:lcall keybrd_5
jb 2fh.7, kb
sjmp wait
kb:mov a,71h
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,71h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
ljmp again
5. The 4 x 4 Matrix Keyboard driver:
This routine is for 4 x 4 matrix keyboard. All the concepts similar to that of 5 x 5 matrix keyboard driver routine. Here also flag 2f.7h becomes high when a key is pressed. After the key pressed, the key code is available at RAM location 71h.
Program location: 846bh
Location name: keybrd_4
Key code location: 71hLet us make clear how to use this routine by considering following program.
Suppose 4 x 4 matrix keyboard is connected as per the following connections.
8051 Port Pins4 X 4 Matrix Keyboard
P0.0Column1 of Keyboard
P0.1Column2 of Keyboard
P0.2Column3 of Keyboard
P0.3Column4 of Keyboard
P0.5Row 1 of Keyboard
P0.6Row 2 of Keyboard
P0.7Row 3 of Keyboard
P2.6Row 4 of Keyboard
The following must be incorporated in your program to make the above connections working:
mov r0, #kbrd4c1
mov @r0, #00h
;p0.0
mov r0, #kbrd4c2
mov @r0, #01h
;p0.1
mov r0, #kbrd4c3
mov @r0, #02h
;p0.2
mov r0, #kbrd4c4
mov @r0, #03h
;p0.3
mov r0, #kbrd4r1
mov @r0, #05h
;p0.5
mov r0, #kbrd4r2
mov @r0, #06h
;p0.6
mov r0, #kbrd4r3
mov @r0, #07h
;p0.7
mov r0, #kbrd4r4
mov @r0, #26h
;p2.6
Let us write a program to display keycode of pressed key
Test Program:
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
mov r0, #kbrd4c1
mov @r0, #00h
;p0.0
mov r0, #kbrd4c2
mov @r0, #01h
;p0.1
mov r0, #kbrd4c3
mov @r0, #02h
;p0.2
mov r0, #kbrd4c4
mov @r0, #03h
;p0.3
mov r0, #kbrd4r1
mov @r0, #05h
;p0.5
mov r0, #kbrd4r2
mov @r0, #06h
;p0.6
mov r0, #kbrd4r3
mov @r0, #07h
;p0.7
mov r0, #kbrd4r4
mov @r0, #26h
;p2.6
lcall lcd4_init
agn:
lcall keybrd_4
jb 2fh.7,ok
sjmp agn
ok:mov 70h,#01h
lcall lcd4_cmd
;lcd cmd
mov a,71h
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat;lcd dat
mov a,71h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
sjmp agn
6. The 3 x 3 Matrix Keyboard driver:
This routine is for 3 x 3 matrix keyboard. All the concepts similar to that of 5 x 5 matrix keyboard driver routine. Here also flag 2f.7h becomes high when a key is pressed. After the key pressed, the key code is available at RAM location 71h.
Program location: 853fh
Location name: keybrd_3
Key code location: 71hLet us make clear how to use this routine by considering following program.
Suppose 3 x 3 matrix keyboard is connected as per the following connections.
8051 Port Pins3 X 3 Matrix Keyboard
P0.0Column1 of Keyboard
P0.1Column2 of Keyboard
P0.2Column3 of Keyboard
P0.5Row 1 of Keyboard
P0.6Row 2 of Keyboard
P0.7Row 3 of Keyboard
The following must be incorporated in your program to make the above connections working:
mov r0, #kbrd3c1
mov @r0, #00h
;p0.0
mov r0, #kbrd3c2
mov @r0, #01h
;p0.1
mov r0, #kbrd3c3
mov @r0, #02h
;p0.2
mov r0, #kbrd3r1
mov @r0, #05h
;p0.5
mov r0, #kbrd3r2
mov @r0, #06h
;p0.6
mov r0, #kbrd3r3
mov @r0, #07h
;p0.7
Let us write a program to display key code of pressed key
Test Program:
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
mov r0, #kbrd3c1
mov @r0, #00h
;p0.0
mov r0, #kbrd3c2
mov @r0, #01h
;p0.1
mov r0, #kbrd3c3
mov @r0, #02h
;p0.2
mov r0, #kbrd3r1
mov @r0, #05h
;p0.5
mov r0, #kbrd3r2
mov @r0, #06h
;p0.6
mov r0, #kbrd3r3
mov @r0, #07h
;p0.7
lcall lcd4_init
agn:
lcall keybrd_3
jb 2fh.7,ok
sjmp agn
ok:mov 70h,#01h
lcall lcd4_cmd;lcd cmd
mov a,71h
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat;lcd dat
mov a,71h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
sjmp agn
7. The 2 x 2 Matrix Keyboard driver:
This routine is for 2 x 2 matrix keyboard. All the concepts similar to that of 5 x 5 matrix keyboard driver routine. Here also flag 2f.7h becomes high when a key is pressed. After the key pressed, the key code is available at RAM location 71h.
Program location: 85feh
Location name: keybrd_2
Key code location: 71hLet us make clear how to use this routine by considering following program.
Suppose 2 x 2 matrix keyboard is connected as per the following connections.
8051 Port Pins2 X 2 Matrix Keyboard
P0.0Column1 of Keyboard
P0.1Column2 of Keyboard
P0.5Row 1 of Keyboard
P0.6Row 2 of Keyboard
The following must be incorporated in your program to make the above connections working:
mov r0, #kbrd2c1
mov @r0, #00h
;p0.0
mov r0, #kbrd2c2
mov @r0, #01h
;p0.1
mov r0, #kbrd2r1
mov @r0, #05h
;p0.5
mov r0, #kbrd2r2
mov @r0, #06h
;p0.6
Let us write a program to display key code of pressed key
Test Program:
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
mov r0, #kbrd2c1
mov @r0, #00h
;p0.0
mov r0, #kbrd2c2
mov @r0, #01h
;p0.1
mov r0, #kbrd2r1
mov @r0, #05h
;p0.5
mov r0, #kbrd2r2
mov @r0, #06h
;p0.6
lcall lcd4_init
agn:
lcall keybrd_2
jb 2fh.7,ok
sjmp agn
ok:mov 70h,#01h
lcall lcd4_cmd;lcd cmd
mov a,71h
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat;lcd dat
mov a,71h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
sjmp agn
8. The 7-segment LED Interface Driver:
This routine can be used to interface the 7-segment LED to the controller. Here there are two routines viz. the segment initialization routine and the interrupt routine for refreshing the 7-segment LEDs. The Timer 0 is used to generate the interrupt. Hence whenever the interrupt is generated, the refreshing action takes place. This can be written as:
org 000bh
ljmp seg_int
reti
Program location for initialization: 86b9h
Location name for initialization:
seg_init
Program location for interrupt:
86e9h
Location name for interrupt routine: seg_int
Location for data in respective digit: 60h, 61h, 62h, 63h, 64h, 65h,
66h, 67h
Let us make clear how to use this routine by considering following program.
Suppose four 7-segment LEDs are connected as per the following connections.
8051 Port Pins4 nos. of 7-segment LED
P0.0Segment a
P0.1Segment b
P0.2Segment c
P0.3Segment d
P0.4Segment e
P0.5Segment f
P0.6Segment g
P0.7Segment dp
P3.0Digit 1
P3.1Digit 2
P3.2Digit 3
P3.3Digit 4
The following must be incorporated in your program to make the above connections working:
mov r0, #segdat
mov @r0, #00h
mov r0, #seldig
mov @r0, #03h
Now let us write a program to display 0123 in the four segments respectively.
Test Program:
include embedded.h
include location.h
org 0000h
ljmp main
org 000bh
lcall seg_int
;interrupt routine
reti
main:
mov sp, #7fh
mov r0, #segdat
mov @r0, #00h
mov r0, #seldig
mov @r0, #03h
lcall seg_init
;segment initialization routine
mov 60h,#3fh
lcall delay
mov 61h,#06h
lcall delay
mov 62h,#5bh
lcall delay
mov 63h,#4fh
sjmp $
;delay routine
delay:
push 03h
push 06h
push 07h
mov r3,#9
d3:
mov r6,#0ffh
d2:
mov r7,#0ffh
d1:
nop
djnz r7,d1
djnz r6,d2
djnz r3,d3
pop 07h
pop 06h
pop 03h
ret
9. Real Time Clock:
This driver routine can be used to interface the RTC chip to the microcontroller. It consists of two different routines: (i) to write the RTC timekeeper registers and (ii) to read value of these registers. The RTC timekeeper registers include seconds, minutes, hours, day, date, month and year. During initialization the parameters are to be mentioned at the given address. When the RTC is read, the parameters are returned at the same locations as mentioned.
Program location for write operation: 87a0h
Location name for write operation: rtc_write
Program location for read operation: 8727h
Location name for read operation: rtc_read
Parameter location: 68h-seconds, 69h-minutes, 6ah-hours, 6bh-day,
6ch-date, 6dh-month
NOTE:
To use this Embedded Routine, the following interface connection must be carried out between the Controller and the RTC chip:
8051 Port PinsRTC (DS 1307)
P3.6SDA of RTC
P3.7SCLD of RTC
Let us understand with a test program that first loads all the parameters to the RTC and then displays the clock and other parameters on LCD.
Test Program:
include location.h
include embedded.h
org 0000h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
mov 68h,#00h;sec data
mov 69h,#60h;minute data
mov 6ah,#11h;hour data
mov 6bh,#07h;day
mov 6ch,#15h;date
mov 6dh,#06h;month
lcall rtc_write
;rtc write
loop:
lcall rtc_read;rtc read
mov 70h,#80h
lcall lcd4_cmd;lcd cmd
mov a,68h;sec
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,68h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,69h;min
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,69h
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,6ah;hour
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,6ah
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
mov 70h,#020h
lcall lcd4_dat
mov a,6bh;day
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,6bh
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,6ch;date
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,6ch
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
mov 70h,#0c0h
lcall lcd4_cmd
mov a,6dh;month
anl a,#0f0h
swap a
add a,#30h
mov 70h,a
lcall lcd4_dat
mov a,6dh
anl a,#0fh
add a,#30h
mov 70h,a
lcall lcd4_dat
ljmp loop
end:sjmp end
10. Serial EEPROM (same lines):
This routine can be used to interface the serial EEPROM to the microcontroller.
There are two operations to interface the serial EEPROM: (i) to write EEPROM and (ii) to read EEPROM. The data to be written to the memory is stored at fixed location. The write routine is used to store the data at fixed location in the memory.
In the Read operation also, the routine is called from the main program. This routine reads the data stored in the EEPROM and sends it at fixed locations, which then can be read.
Location for Write operation: 8669hLocation Name for Write operation: write_srom
Location for Read operation: 88b0h
Location Name for Read operation: read_srom
Data location (Read/Write): 7bh, 7ch, 7dh, 7eh
NOTE:
To use this Embedded Routine, the following interface connection must be carried out between the Controller and the EEPROM chip:
8051 Port PinsSerial EEPROM (24C16)
P3.6SDA of E2PROM
P3.7SCLK of E2PROM
Let us make clear how to use this routine by considering a program to store the data in eeprom and read it back.
Test Program
include location.h
include embedded.h
org 0000h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
mov 7bh,#30h
mov 7ch,#32h
mov 7dh,#35h
mov 7eh,#37h
lcall write_rom;write ROM
mov 7bh,#0h
mov 7ch,#0h
mov 7dh,#0h
mov 7eh,#0h
lcall read_rom;read ROM
mov a,7bh
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,7ch
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,7dh
mov 70h,a
lcall lcd4_dat
mov 70h,#20h
lcall lcd4_dat
mov a,7eh
mov 70h,a
lcall lcd4_dat
sjmp $
11. Serial EEPROM (as per ASK):
The description for this routine is per the previous one. However this driver routine is provided to make ASK card compatible with embedded routines.
Location for Write operation: 94dehLocation Name for Write operation: write_rom
Location for Read operation: 9525h
Location Name for Read operation: read_rom
Data location (Read/Write): 7bh, 7ch, 7dh, 7eh
NOTE:
To use this Embedded Routine, the following interface connection must be carried out between the Controller and the EEPROM chip, while using ASK:
8051 Port PinsSerial EEPROM (24C16)
P0.6SDA of E2PROM
P0.7SCLK of E2PROM
Following is given a program to store the data in EEPROM and read it back.
Test Program
include location.h
include embedded.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
mov 7bh,#'s'
lcall write_rom
lcall read_rom
mov 70h,7bh
lcall lcd4_dat
sjmp $
12. Parallel ADC
This driver routine is designed to interface the 8-bit ADC to the microcontroller.
Here the channel has to be first selected and then the ADC routine has to be called. This ADC routine will store the ADC output data to a fixed location, which can be accessed in the main program.
Location for ADC routine: 8980H
Location Name for ADC routine: adc_readChannel Select Address (00H to 07H) location: 79HADC output location: 7aHLet us make clear how to use this routine by considering following program.
Suppose ADC - 0809 is connected as per the following connections.
8051 Port Pins8-bit ADC 0809
P0.0A0 Address lines of ADC
P0.1A1 Address lines of ADC
P0.2A2 Address lines of ADC
P0.3Start Address lines of ADC
P0.4ALE Address lines of ADC
P0.5EOC Address lines of ADC
P1.1D1
P1.2D2
P1.3D3
P1.4D4
P1.5D5
P1.6D6
P1.7D7
The following must be incorporated in your program to make the above connections working:
mov r0,#padcadr
mov @r0,#00h
mov r0,#padcsoc
mov @r0,#03h
mov r0,#padcale
mov @r0,#04h
mov r0,#padceoc
mov @r0,#05h
mov r0,#padcdat
mov @r0,#01h
Now let us write a program to read the digital data from ADC and display it on LCD.
Test Program include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
;LCD initialization routine
mov r0,#padcadr
mov @r0,#00h
mov r0,#padcsoc
mov @r0,#03h
mov r0,#padcale
mov @r0,#04h
mov r0,#padceoc
mov @r0,#05h
mov r0,#padcdat
mov @r0,#01h
mov 79h, #07h;ADC channel
again:mov 70h,#80h
lcall lcd4_cmd
mov 70h,#31h
lcall lcd4_dat
;lcd dat
lcall adc_read;ADC read
mov 70h,#87h
lcall lcd4_cmd
mov a, 7ah
;ADC data
anl a,#0f0h
swap a
mov dptr,#table
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
mov a, 7ah
anl a,#0fh
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
ljmp again
table:
db 30h;0
db 31h;1
db 32h;2
db 33h;3
db 34h;4
db 35h;5
db 36h;6
db 37h;7
db 38h;8
db 39h;9
db 41h;a
db 42h;b
db 43h;c
db 44h;d
db 45h;e
db 46h;f
13. SERIAL ADC
This driver routine can be used to interface the serial ADC (ADS 1286) with microcontroller.
Since this ADC is 12-bit serial ADC, we have to the received digital data from serial ADC in two fixed locations.
Location for Serial ADC read: 8a3bhLocation name:
ssadc_readData location:
5eh, 5fhNOTE:
To use this Embedded Routine, the following interface connection must be carried out between the Controller and the ADC chip:
8051 Port PinsSERIAL ADC(ADS 1286)
P0.0CS of SERIAL ADC
P3.6SDA of SERIAL ADC
P3.7SCLD of SERIAL ADC
Let us make clear how to use this routine by writing a program to display digital data from serial ADC.
Test Program
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
;LCD initialization routine
again:mov 70h,#80h
lcall lcd4_cmd
lcall ssadc_read
;ADC read
mov a,5eh
anl a,#0f0h
swap a
mov dptr,#table
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
mov a,5eh
anl a,#0fh
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
mov a,5fh
anl a,#0fh
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
ljmp again
table:
db 30h;0
db 31h;1
db 32h;2
db 33h;3
db 34h;4
db 35h;5
db 36h;6
db 37h;7
db 38h;8
db 39h;9
db 41h;a
db 42h;b
db 43h;c
db 44h;d
db 45h;e
db 46h;f
14. SERIAL ADC (as per ASK):
The description for this routine is per the previous one. However this driver routine is provided to make ASK card compatible with embedded routines.
Location for Serial ADC read: 949fhLocation name:
sadc_readData location:
5eh, 5fhNOTE:
To use this Embedded Routine, the following interface connection must be carried out between the Controller and the EEPROM chip, while using ASK:
8051 Port PinsSERIAL ADC(ADS 1286)
P0.0CS of SERIAL ADC
P0.1SDA of SERIAL ADC
P0.2SCLD of SERIAL ADC
Let us make clear how to use this routine by writing a program to display digital data from serial ADC.
Test Program
include embedded.h
include location.h
org 00h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall lcd4_init
;LCD initialization routine
again:mov 70h,#80h
lcall lcd4_cmd
lcall sadc_read
;ADC read
mov a,5eh
anl a,#0f0h
swap a
mov dptr,#table
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
mov a,5eh
anl a,#0fh
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
mov a,5fh
anl a,#0fh
movc a,@a+dptr
mov 70h,a
lcall lcd4_dat
ljmp again
table:
db 30h;0
db 31h;1
db 32h;2
db 33h;3
db 34h;4
db 35h;5
db 36h;6
db 37h;7
db 38h;8
db 39h;9
db 41h;a
db 42h;b
db 43h;c
db 44h;d
db 45h;e
db 46h;f
15. GRAPHIC LCD
This driver routine consists of 11 subroutines. Since Graphic LCD is basically divided into two sections, these routines are made so flexible such that they make it possible for the user to use either one or both chip sections to work with. The details of these routines is as follows:
Graphic LCD Initialization: This routine is used to initialize the Graphic LCD.
Program location: 8a7ah
Location name: glcd_init
Graphic LCD Display On routine: This routine can be used to make the Graphic LCD screen on.
Program location: 8ae6h
Location name: glcd_dispon
Graphic LCD Display Off routine: This routine can be used to turn off the Graphic LCD screen.
Program location: 8b43h
Location name: glcd_dispoff
Graphic LCD Startline routine for Chip Section 1:This routine can be used to assign the startline value in chip section 1 of the Graphic LCD.
Program location: 8ba0h
Location name: glcd_srtlin1
Startline command location: 73h
Graphic LCD Page Address routine for Chip Section 1:This routine can be used to assign the starting page adddress value for chip section 1 of the Graphic LCD.
Program location: 8c34h
Location name: glcd_page1
Page Address command location: 74hGraphic LCD Y-Address routine for Chip Section 1: This routine can be used to assign the Y-address value for chip section 1 of the Graphic LCD. Hence the starting column where the first data is to written, can be defined by using this routine.
Program location: 8c7eh
Location name: glcd_yadd1
Y-Address command location: 75hGraphic LCD Clear screen routine for Chip Section 1:This routine can be used to clear the chip section 1 of the Graphic LCD.
Program location: 95f5h
Location name: glcd_clr1
Graphic LCD Data routine for Chip Section 1:This routine can be used to send data at the defined location in chip section 1 of the Graphic LCD.
Program location: 8d5ch
Location name: glcd_send1
Data location: 72hGraphic LCD Startline routine for Chip Section 2:This routine can be used to assign the startline value in chip section 2 of the Graphic LCD.
Program location: 8beah
Location name: glcd_srtlin2
Startline command location: 76hGraphic LCD Page Address routine for Chip Section 2:This routine can be used to assign the starting page adddress value for chip section 2 of the Graphic LCD.
Program location: 8cc8h
Location name: glcd_page2
Page Address command location: 77hGraphic LCD Y-Address routine for Chip Section 2: This routine can be used to assign the Y-address value for chip section 2 of the Graphic LCD. Hence the starting column where the first data is to written, can be defined by using this routine.
Program location: 8d12h
Location name: glcd_yadd2
Y-Address command location: 78hGraphic LCD Clear screen routine for Chip Section 2:This routine can be used to clear the chip section 2 of the Graphic LCD.
Program location: 9629h
Location name: glcd_clr2
Graphic LCD Data routine for Chip Section 2:This routine can be used to send data at the defined location in chip section 2 of the Graphic LCD.
Program location: 8da0h
Location name: glcd_send2
Startline command location: 72hTo make all this stuff clear, let us look at a sample program. Suppose the Graphic LCD is connected as per following connections
8051 Port PinsGraphic LCD
P0GLCD Data Lines
P2.0GLCD D/I pin
P2.1GLCD EN pin
P2.2GLCD CS1 pin
P2.3GLCD CS2 pin
P2.4GLCD RST pin
P2.6GLCD RW pin
The following statements must be incorporated in your program to make the above connections working:
mov r0, #glcddat
mov @r0, #00h
mov r0, #glcddi
mov @r0, #20h
mov r0, #glcden
mov @r0, #21h
mov r0, #glcdcs1
mov @r0, #22h
mov r0, #glcdcs2
mov @r0, #23h
mov r0, #glcdrst
mov @r0, #24h
mov r0, #glcdrw
mov @r0, #26h
Let us write a program to display the logo of "EDUTECH SYSTEMS" on Graphic LCD.
Test Program
include embedded.h
include location.h
eom equ 0fdh
org 00h
mov sp, #7fh
mov r0, #glcddat
mov @r0, #00h
mov r0, #glcddi
mov @r0, #20h
mov r0, #glcden
mov @r0, #21h
mov r0, #glcdcs1
mov @r0, #22h
mov r0, #glcdcs2
mov @r0, #23h
mov r0, #glcdrst
mov @r0, #24h
mov r0, #glcdrw
mov @r0, #26h
lcall glcd_init
;glcd initialization
lcall glcd_dispon;glcd display on
lcall glcd_clr1
lcall glcd_clr2
sec1:
mov 73h, #00h
lcall glcd_srtlin1;cs1 startline
mov 75h,#00h
lcall glcd_yadd1;cs1 yadr
mov dptr, #msg
mov r0, #00h
nxt1:mov r1, #00h
mov 74h, r0
lcall glcd_page1;cs1 page
agn1:clr a
movc a, @a+dptr
inc dptr
cjne a, #eom, cont1
sjmp nxt
cont1:mov 72h, a
lcall glcd_send1;cs1 data
inc r1
cjne r1, #64, agn1
inc r0
cjne r0, #03h, nxt1
sjmp agn1
nxt:mov 75h,#14
lcall glcd_yadd1;cs1 yadr
mov 74h, #03h
lcall glcd_page1;cs1 page
mov dptr, #msg1
agn2:clr a
movc a, @a+dptr
inc dptr
cjne a, #eom, cont2
sjmp $
cont2:mov 72h, a
lcall glcd_send1
sjmp agn2
msg: db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,80h,80h,c0h
db c0h,e0h,f0h,f0h,f8h,f8h,f8h,fch,fch,feh,feh,feh,feh,ffh,ffh,ffh,ffh,ffh,ffh,ffh,ffh
db ffh,ffh,ffh,ffh,ffh,ffh,ffh,ffh,feh,feh,feh,fch,fch,fch,f8h,f0h,e0h,80h,00h,00h,00h
db 00h,00h
db 00h,00h,00h,00h,00h,00h,00h,80h,c0h,e0h,f0h,f0h,f0h,04h,06h,e7h,e7h,e7h,e7h,e7h,e7h
db 67h,67h,e7h,e7h,e7h,e7h,e7h,e7h,e7h,e7h,cfh,8fh,1fh,1fh,7fh,f7h,07h,07h,f7h,ffh,ffh
db ffh,ffh,ffh,f7h,07h,07h,f7h,ffh,ffh,ffh,ffh,ffh,ffh,ffh,ffh,3fh,1fh,00h,00h,00h,00h
db 00h
db 40h,60h,70h,78h,7ch,7eh,7fh,7fh,7fh,7fh,7fh,7fh,3fh,00h,00h,1fh,1ch,1ch,1ch,1ch,1ch
db 18h,18h,1fh,1fh,1fh,1fh,1fh,1fh,1fh,1fh,0fh,47h,40h,40h,70h,78h,40h,00h,3fh,7fh,7fh
db 7fh,7fh,7fh,3fh,00h,00h,3fh,1fh,0fh,07h,07h,07h,03h,01h,00h,00h,00h,00h,00h,00h,00h
db 00h,eom
msg1:db 01h,01h,ffh,01h,01h
db ffh,99h,99h,81h,81h
db 7eh,81h,81h,81h,42h
db ffh,18h,18h,18h,ffh,eom16. PRINTER
This routine can be used to interface the printer to the microcontroller. There are two routines viz. (i) printer initialization and (ii) print routine. In the printer initialization routine necessary communication protocol is being set. By using the second driver routine i.e. print routine, you can print the message on paper without engaging your PC for printing purpose. The data is stored to a fixed location and the printer routine is called.
Location for printer initialization:
8e8fh
Location Name for printer initialization:
pri_init
Location for print routine:
8eaahLocation Name for printer initialization:
printData location (Write):
6fh 8051 Port PinsPRINTER
P0Printer data port
P2.4Printer strobe pin
P2.6Printer initialization pin
P2.7Printer busy pin
The following must be incorporated in your program to make the above connections working:
mov r0, #prdat
mov @r0, #00h
mov r0, #pbusy
mov @r0, #27h
mov r0, #pinit
mov @r0, #26h
mov r0, #pstrob
mov @r0, #24h
Lets now see an example program for printer.
Test Program:
include location.h
include embedded.h
eom equ 0ffh
org 00h
mov r0, #prdat
mov @r0, #00h
mov r0, #pbusy
mov @r0, #27h
mov r0, #pinit
mov @r0, #26h
mov r0, #pstrob
mov @r0, #24h
lcall pri_init
mov dptr, #msg
agn:mov a, #00h
movc a, @a+dptr
inc dptr
cjne a, #eom, go
sjmp exit
go:mov 6fh, a
;;;;;data to print
lcall print
sjmp agn
exit:sjmp $
msg:db 'Dear Students,',0ah,0ah,09h,' Welcome to Microcontroller
Seminar. ',0ah
db
'For more details log on to www.edutechonline.com ',0ah
17. SERIAL COMMUNICATION USING MODE 1
This routine can be used to communicate controllers in mode 1. There are three routines viz. (i) Serial communication initialization, (ii) Transmission routine and (iii) Reception routine. In the Serial communication initialization routine necessary communication protocol is being set. By using the second driver routine i.e. Transmission routine, you can transmit the data to another controller. By using the third driver routine i.e. Reception routine, you can receive data, which is transmitted by another controller. To transmit, the data is first stored to a fixed location and then serial transmission routine is called. Similarly the received data is stored data is stored in the same location from where the user can read the received value. Here internally timer 1 is being used in auto reload mode to set the baud rate, so be careful not to use timer 1 for other uses, when using this embedded driver routine.
Location for Serial Communication Initialization:
8f08hLocation Name for Serial Communication Initialization: ser1_init
Location for Transmission routine:
8f19h
Location Name for Transmission initialization:
transmit1
Location for Reception routine:
8f23h
Location Name for Reception initialization:
receive1
Data location (Write/Read):
5bh
Lets now see a simple example program for Serial communication in mode 1.
Test Program:
include embedded.h
include location.h
org 0000h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall ser1_init
lcall lcd4_init
mov 70h,#01h
lcall lcd4_cmd
again:
mov 5bh, #x
lcall transmit1
lcall receive1
mov 70h,#80h
lcall lcd4_cmd
mov a,5bh
mov 70h,a
lcall lcd4_dat
sjmp again
18. SERIAL COMMUNICATION USING MODE 2
This routine can be used to communicate controllers in mode 2. Here also there are three routines viz. (i) Serial communication initialization, (ii) Transmission routine and (iii) Reception routine. All the concepts are then as per the previous one. The only benefit is that you need not to engage your timer to set baud rate for serial communication.
Location for Serial Communication Initialization:
8f2ehLocation Name for Serial Communication Initialization: ser2_init
Location for Transmission routine:
8f3fh
Location Name for Transmission initialization:
transmit2
Location for Reception routine:
8f42h
Location Name for Reception initialization:
receive2
Data location (Write):
5bh
Lets now see an example program for Serial communication in mode 2.
Test Program:
include embedded.h
include location.h
org 0000h
mov sp, #7fh
mov r0, #lcd4d
mov @r0, #02h
mov r0, #lcd4en
mov @r0, #24h
mov r0, #lcd4rs
mov @r0, #25h
lcall ser2_init
lcall lcd4_init
mov 70h,#01h
lcall lcd4_cmd
again:
mov 5bh, #x
lcall transmit2
lcall receive2
mov 70h,#80h
lcall lcd4_cmd
mov a,5bh
mov 70h,a
lcall lcd4_dat
sjmp againChapter 10
FAQ
1) What is SLK-51?
The SLK-51 is a self-learning card specially designed for students who are studying 8051 as their curricular subject. This card is designed to make you confident enough to learn, test & apply 8051.
2) What is the difference between EPB & SLK-51?
Both the cards are same. Only the difference is the bread-board which is available with the EPB. Also it is in a kit from packed in a wooden box. The EPB is generally designed for institute labs where the components are required to be inserted & not soldered so as to reuse them. However, SLC is having a general-purpose area, where soldering of components is possible and user can do project related activities.
3) Does the EPB/SLC loose its program when powered off?
No, the program does not loose even if the power is OFF. The program is stored in the flash program memory and not in the RAM.
4) How many times can I write and erase program using the EPB/SLC board?
The CPU chip manufacturer specifies that the Write/Erase operations can be carried out for about 10,000 times which can be considered as pretty high.
5) What precaution should I take while using the EPB/SLK-51?
First of all, try to read the user manual thoroughly before starting the kit. Also do not remove the chip from the socket if possible. It is likely that the static charge might damage the chip. Also make the power supply OFF while change from program and Run mode.
6) What is the Program & Run mode?
The chip provided on board has the facility of in-circuit programming. Hence it can be programmed and erased without removing from the socket and without using any external programmer. So to erase or load the program, we have the program mode and to run the loaded program, we have to RUN option. A program mode switch provided on board can select these options.
7) What is WINISP?
WINISP is a virtual programmer utility provided by the chip manufacture. This utility can be installed and program can be transferred to the chip and erased while the chip is in circuit.
8) What items do I need to get started with the EPB/SLK-51?
The items you need are:
1) The programming software
2) The programming cable
3) The manual
4) The EPB/SLK-51 Module itself and optionally the available additional interfacing kits.
You also need same basic components like the LEDs, Resistors, hook up wires, Keys etc, to interface to the CPU. If you are interested to use the SLK-51 in your project and you need more interfacing devices, you can purchase different available options separately. It is best to purchase various other available self learning cards (which include manual, software and cables) that suit your requirements.
We however, recommended to purchase the LCD/key SLC-02 interface kit along with the SLK-51, so that you can do lot of practice exercise, learn how LCD is interface & do almost any project assignment.
9) What are the different optional SLC modules available?
The basic module i.e., the EPB/SLK-51 can be interfaced with number of modules. There exist two different types of modules for institutes & individual user. However, there is no much differ in this construction.
As an individual user, you can select from the following module.
1. SLC-02LCD/4-key interface module
2. SLC-03LCD/4-key e2prom interface module
3. SLC-04LCD/4-key RTC module
4. SLC-05LCD/4 key e2prom, rtc module
5. SLC-06LCD/4 key/e2prom/adc module
10) Is the EPB/SLK-51 module sensitive to static electricity?
While many electronic devices, including the EPB/SLK-51 can be damaged by static electricity; the SLK-51 is less sensitive to static electricity.
But we do, however recommend that the CPU chip should not be removed from the socket since it is likely to get damaged by static electricity.
11) How many I/O pins does the EPB/SLK-51 have?
The EPB/SLK-51 has 32 i/o lines. All the ports pins are made available to the user.
12) How does EPB/SLK-51 differ from a conventional kit?
The EPB/SLK-51 is totally different from the conventional kit. It is a true single chip design, which is develop to provide you a real feel of working with microcontroller. All the routines, interfaces are to be done by you and nothing is made available ready made. However the document provide with the EPB/SLK-51 will help you to build you own system that demonstrate application developed by you.
13) Why should I go for EPB/SLK-51?
The 8051 controller comes as a subject in the University curriculum. As you know that 8051 controller can be applied to large variety of interfaces to develop application.
These days, the use of controller has increased a lot and they are applied in different consumer item, industrial equipments and even toys. Also these days, industry is also not doing well. Hence if you are really through in the concepts you have learnt in your curriculum and if you can apply those concepts learnt, you will survive. Also if you plan to start on your own and develop applications that are required by the society or try to have some maintenance related job that involves controllers (areas like consumer electronics, Medical electronics, Automobile etc) you need to be through in the concept.
SLK-51 is the product designed for you to make you a complete engineer who can interface and apply controller to solve problems.
We are sure that with this faith & dedication, you should be successful in your life. SLK-51 is meant for that.
14) What can I use I/O pins for?
The EPB/SLK-51 pins are perfectly suited for digital input and output with TTL/CMOS level (0 to 5 V) signals. You can use it to generate PWM signals and apply them. More details of applications can be studied by referring the data sheet of the CPU.
15) Can I use the I/O pins to control relays, solenoids and other
similar devices?
Yes, however, due to the demanding current and voltage requirements of some of these components, driver circuits will need to be used to properly isolate the i/o pin from harmful effect.
16) Can I control LEDs with the I/O pin?
Yes, simply use a 470 ohm resistor in series with the LED to limit the current drawn through the i/o pin. Also keep in mind that most LED, require a lot of current in relation to what the EPB/SLK-51 can provide. If you attach more LEDs at one time from and power the i/o pins of EPB/SLK-51, you all likely to see flaky and unpredictable results caused by voltage sag, i/o pin damage and/or hardware resets. Either driver circuitry or low curre