of 75
7/31/2019 Shiva ES Experiments
1/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 1
LCD INTERFACE TO 8051
Aim: To interface the LCD display with the 8051-SDK and display the requiredmessage on the LCD.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
LIQUID CRYSTAL DISPLAY (LCD)
LCD data pins are connected to Port 0, and the control pins RS (Data/Command)
pin is connected to Port3.4, RW pin is grounded and EN(Enable) pin is connected to
Port3.5.
Diagram: LCD
Department of Electronics & Communications 1Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
2/75
7/31/2019 Shiva ES Experiments
3/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
EN (Enable LCD):
EN bit is to ENABLE or DISABLE the LCD. When ever controller wants to write
some thing into LCD or READ acknowledgment from LCD it needs to enable the LCD.
EN = 0 => High Impedance
EN = 1 => Low Impedance
ACK (LCD Ready):
ACK bit is to acknowledge the MCU that LCD is free so that it can send new
command or data to be stored in its internal Ram locations
ACK = 1 => Not ACK
ACK = 0 => ACK
Hardware Explanation
LCD Diagram:
Diagram: LCD
Department of Electronics & Communications 3Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
4/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Block Diagram:
Hardware Connections :
Department of Electronics & Communications 4Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
5/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
LCD ALGORITHM:
STEP1: Configure port pins for all hardware connections
STEP2: Initialize the LCD by passing the proper set of COMMANDS
STEP3: Display the DATA in LCD
STEPS FOR WRITING COMMAND TO LCD
STEP4: Write each COMMAND to LCD COMMAND WRITE ADDRESS of LCD
STEP5: Repeat STEP4 and STEP5 until writing all COMMANDS
STEPS FOR WRITING DATA TO LCD
STEP6: Write each Character to LCD DATA WRITE ADRESS of LCD
STEP7: Repeat STEP7 and STEP8 until writing total data.
STEP8: End
Department of Electronics & Communications 5Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
6/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Flow Chart for LCD Module:
Department of Electronics & Communications 6Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
7/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/************************************************************//* PROJECT NAME: LCD */
/************************************************************/
/* Filename: LCD.c *//* Language: C *//* Compiler: Keil uV2 *//* Assembler: */
#include #define LCD P0#define RS P3_4#define EN P3_5
void lcdInit(void);void putComL(unsigned char);void putCharL(unsigned char);
void putStrL(unsigned char *,unsigned char);void delay(unsigned int d);
int main(void){
lcdInit();delay(1000);putStrL("LCD TEST",0x01);putStrL("OK",0xC0);
while(1);
}
void lcdInit(void){
putComL(0x38);putComL(0x0c);putComL(0x06);putComL(0x01);putComL(0x80);
}
void putComL(unsigned char cmd)
{RS=0;
}
Results: As per programmed application LCD is interface to the microcontrollerAT89s51 with neat schematic . Hence LCD application is verified on embedded 8051 kitby displaying data.
Department of Electronics & Communications 7Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
8/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 2
KEYPAD INTERFACING
Aim: To interface the keypad with the 8051 SDK microcontroller Development Kit andobserve the encryption and decryption of data.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software6. AC Power Supply
4 x 4 Keypad
A membrane keypad is provided as an add on module, the 4 Rows and 4 Column
signal lines are connected to Port1. The keypad can be unplugged from the board if required.
Schematic
Schematic of 4x4 Keypad:
Department of Electronics & Communications 8Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
9/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/**********************************************************************//*KEYPAD INTERFACING*/
/**********************************************************************/
;KEYCOUNT EQU 20H.0
ORG 00H
MOV P2, #0FFH ;P2 AS COLUMNSMOV R1, #40HMOV R2, #0
MOV TMOD, #20HMOV SCON, #50HMOV TH1, #0FDH
MOV DPTR, #CMDCONTINUE: CLR A
MOVC A, @A+DPTRJZ STARTPROCESSACALL COMMAND
INC DPTRSJMP CONTINUESTARTPROCESS: MOV DPTR, #STARTMSGACALL DISPLAY
MOV A, #0C0HACALL COMMAND
MOV DPTR, #STARTMSG1ACALL DISPLAYACALL DELAYACALL DELAY
MOV A, #01HACALL COMMAND
MOV DPTR, #MSGACALL DISPLAY
MOV A, #0C0HACALL COMMAND
MOV DPTR, #MSG1ACALL DISPLAYACALL DELAYACALL DELAYACALL DELAY
MOV A, #01H
Department of Electronics & Communications 9Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
10/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
ACALL COMMANDKEYPAD:
MOV P0, #0 ;P1 AS ROWSMOV A, P2ANL A, #00000111B; CHECKING FOR ALL KEYS OFF CONDITION
CJNE A, #00000111B, KEYPAD
BACK1: MOV A, P2ANL A, #00000111B ;CHECK IF ANY KEY IS PRESSED DUE TO NOISE
CJNE A, #00000111B, CHECKSJMP BACK1
CHECK: ACALL DELAY ;DELAY FOR 20MSECMOV A, P2
ANL A, #00000111BCJNE A, #00000111B, STARTSJMP BACK1
START: MOV P0, #11111110B ;GROUND ROW 0MOV A, P2ANL A, #00000111BCJNE A, #00000111B, ROW_0
MOV P0, #11111101B ;GROUND ROW 1MOV A, P2ANL A, #00000111BCJNE A, #00000111B, ROW_1
MOV P0, #11111011B ;GROUND ROW 2MOV A, P2ANL A, #00000111BCJNE A, #00000111B, ROW_2
MOV P0, #11110111B ;GROUND ROW 3MOV A, P2ANL A, #00000111BCJNE A, #00000111B, ROW_3
JMP BACK1
ROW_0: MOV DPTR, #ROW0JMP XX
ROW_1: MOV DPTR, #ROW1
Department of Electronics & Communications 10Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
11/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
JMP XX
ROW_2: MOV DPTR, #ROW2JMP XX
ROW_3: MOV DPTR, #ROW3JMP XX
XX:RRC AJNC KEYFOUNDINC DPTR
JMP XX
KEYFOUND: CLR AMOVC A, @A+DPTR
; MOV R1, #40HMOV @R1, ACJNE A, #23H, CNTINUE
JMP LOOP
CNTINUE: ACALL DATA1;MOV @R1, AINC R1INC R2
JMP KEYPAD
LOOP: MOV R1,#40HMOV A, #0C0H
ACALL COMMANDMOV R0, #60H;MOV B, #2
MOV A, #0C0HACALL COMMAND
MOV DPTR, #MSG2ACALL DISPLAYACALL DELAYACALL DELAYACALL DELAY
MOV A, #01HACALL COMMAND
MOV DPTR, #MSG2AACALL DISPLAY
MOV A, #0C0H
Department of Electronics & Communications 11Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
12/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
ACALL COMMANDLOOP1: MOV A, @R1
ADD A, #3H
SUBB A, #9H
MOV @R0, AACALL TRANSMITACALL DATA1ACALL DELAYACALL DELAY
INC R1INC R0DJNZ R2, LOOP1
JMP $ ;STARTPROCESS2
/*STARTPROCESS2: MOV A, #01HACALL COMMANDACALL DELAYACALL DELAYACALL DELAYJMP STARTPROCESS */
;STARTPROCESS1: JMP STARTPROCESS
TRANSMIT: SETB TR1MOV SBUF, AJNB TI, $CLR TI
RET
RECEPTION: JNB RI, $CLR RIMOV A, SBUF
RET
DISPLAY: CLR AMOVC A, @A+DPTR
JZ XXXACALL DATA1
INC DPTRSJMP DISPLAYXXX: RET
Department of Electronics & Communications 12Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
13/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
COMMAND: MOV P1, ACLR P3.5CLR P3.6SETB P3.7
ACALL DELAY CLR P3.7RET
DATA1: MOV P1, ASETB P3.5CLR P3.6SETB P3.7
ACALL DELAYCLR P3.7
RET
DELAY: MOV R6, #255HERE: MOV R7, #255
DJNZ R7, $DJNZ R6, HERE
RET
CMD: DB 38H, 0EH, 01H, 06H, 80H, 0
ROW0: DB '1','2','3'ROW1: DB '4','5','6'ROW2: DB '7','8','9'ROW3: DB '*','0','#'
STARTMSG: DB "------------------------------------------------------------------", 0STARTMSG1: DB " ENCRYPTION ", 0STARTMSG2: DB "------------------------------------------------------------------", 0
MSG: DB "ENCRYPTED DATA: ", 0MSG1: DB "ENTER THE PASSWORD: ", 0
STARTMSG3: DB "------------------------------------------------------------------", 0STARTMSG4: DB " DECRYPTION ", 0STARTMSG5: DB "------------------------------------------------------------------", 0MSG2: DB " DECRYPTED DATA: , 0END
Department of Electronics & Communications 13Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
14/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Output of the Program:
Results:
As per programmed application Data Encryption and Decryption, is that which is
possible with the help of microcontroller AT89s51, LCD with keypad, and PC. Hence
application is verified LCD on embedded 8051 kit as well as in PC Communication
terminal window.
Department of Electronics & Communications 14Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
15/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 3
SQUARE WAVE DEVICE DRIVER DEVELOPMENT
Aim: Linux is a clone of UNIX.AS in all version of UNIX, hardware devices are
presented to normal programs as special files. Therefore, devices implement file
semantics within ihe kernel.Because of this, it is worth taking a short look at how files in
general are treated in linux before attempting to understand how device drivers are
written.
Files
The generic filesystems header file, , defines several structuresfor accessing files, super_block holds basic information about each filesystemm,and
super_oeratoins is a structure of pointers to fuynctions which are associated with a
filesystems superblock.Through that structure are reached inode_operations, the last
defing functions that can be used to access files.In normal filesystems, there is one set of
file operations on device special files.insted, those devices define their own file
operations and register their own file_operations structure with the VFS.
The VFSThe VFS is the common abbreviaton for the Virtual Filesystem Switch.
Generic filesystem operations are handled by generic filesystem code, and only when
filesystem dependent or device dependent operations need to be done is the code for that
specific filesystem or device actually called. The function needed is looked up in the
proper instance of one of the *_operations structures and called.The VFS code is kept in
the fs/ subdirectory of the Linux kernel source, and the code to the individual filesystems
is kept in subdirectories of the fs/ subdirectory.
OperationsWhat I mean by operations may not be very clear at this point.An operation
is something that needs to be done as a result of a system call or buffer cache activity, or
beacauseof hardware irregularities.Nearly all operatons are caused directly or indirectly
Department of Electronics & Communications 15Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
16/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
by system calls, and so you can think of the VFS as code that translates raw system calls
into filesystem operations.
Special files and file systems
All versions of Unix have device special files. The concept has even beenpicked up by such primitive operating systems as Microsofts DOS. However, the VFS is
so flexible that not only can special files be created, special filesstems can to.Linux has a
filesystems called the proc filesystem ,or profs, which is essentially a special
filesystems. The file in this filesystem are not stored on disk;they are instead generated
on-the fly from kernel data structures.they are,you could say,virtual devices designed to
report on the state of the kernel.
/************************************************************//* PROJECT NAME: SQUARE WAVE */
/************************************************************/
#include#include#include#include#include
#define PORT 0x378
#define NSEC_PER_SEC 1000000000 /*using clock_nanosleep of librt*/extern int clock_nanosleep(clockid_t_clock_id, int_flags,_const structtimespec*_req,struct timespec*_rem);static inline void tsnorm(stuct timespec *ts){While(ts->tv_nsec>= NSEC_PER_SEC){ts->tv_nsec -=NSEC_PER_SEC;ts->tv_sec++;}} /*increment counter and write to parallelport*/
void out()Static unsigned char state=0;Outb(state++,PORT);}int main(int argc,char** argv){struct timespec t;struct sched_param param; /*defaultinterval=50000ns=50us;*cycle duration=100us*/
Department of Electronics & Communications 16Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
17/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
int interval=50000; /*set permissions of parallelport*/ioperm(PORT,1,1);if(argc>=2&&atoi(argv[1])>0){printf(using realtime,priority:%d/n,atoi(argv[1]));
param.sched_priority =atoi(arvg[1]); /*enable realtime fifo scheduling*/if(sched_setscheduler(0.SCED_FIFO,¶m)==-1){perror(sched_setscheduler failed);exit(-1);}}if(argc>=3)interval=atoi(avgv[2]);clock_gettime(0,&t);t.tv_sec++;
while(1){clock_nanosleep(0,TIMER_ABSTIME,&t,NULL);out();t.tv_nsec+=interval;tsnorm(&t);}Return 0;}
Compilation:
gcc_0 square square_wave.c-lrt-wall
Execution:
./square
./square 8 20000
Explanation:
By default, this driver program will generate the square wave on the system
parallel port with a timer interval of 50us.At this point of time, the default system
resources are used. If we give the priority less than the default, this driver uses more no.
of system resources so all other processes get less priority.
The parallel pin color notations and respective PRI of generating square waveare,
2ndpin - Blue (2*x)3rd pin - White (4*x)4th pin - Yellow (8*x)5th pin - Orange (16*x)
Department of Electronics & Communications 17Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
18/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
6th pin Black (32*x)10th pin Navy Blue (64*x)25th pin Green(GND)
RESULTHence the Square wave Device Driver, the default system resources are used.
If we give the priority less than the default, this driver uses more no. of system resources
so all other processes get less priority.
Department of Electronics & Communications 18Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
19/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 4
LED INTERFACE TO 8051
Aim: To read inputs from switches and produce different dancing patterns for LEDs by
interfacing the 8051-SDK kit with the computer.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
Theory:
It is a semiconductor diode having radiative recombination. It requires a definite
amount of energy to generate an electron-hole pair. The same energy is released when an
electron recombines with a hole. This released energy may result in the emission of
photon. Here the amount of energy released when the electro reverts from the conduction
band to the valence band appears in the form of radiation. Alternatively the released
energy may result in a series of photons causing lattice vibration. Finally the released
energy may be transferred to another electron. The recombination radiation may lie in the
infra-red and visible light spectrum. In forward biased region the radiation is peaked
around the band gap energy and the phenomenon is called injection luminescence. In a
junction biased in the avalanche break down region, there results a spectrum of photons
carrying much higher energies. Almost White light then gets emitted from micro-plasma
breakdown region in silicon junction. Diodes having radiative recombination are termed
as Light Emitting Diodes, abbreviated as LEDs.
Department of Electronics & Communications 19Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
20/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
In gallium arsenide diode, recombination is predominantly a radiation
recombination and the probability of this radiative recombination far exceeds that in
either germanium or silicon. Hence GaAs LED has much higher efficiency in terms of
photons emitted per carrier. The internal efficiency of GaAs LED may be very close to
100% but because of high index of refraction, only a small fraction of the internal
radiation can usually come out of the device surface. In spite of this low efficiency of
actually radiated light, these LEDs are efficiently used as light emitters in visual display
units and in optically coupled circuits. The efficiency of light generation increases with
the increase of injected current and with decrease in temperature. The light so generated
is concentrated near the junction since most of the charge carriers are obtained within one
diffusion length of the diode junction.
The following are the merits of LEDs over conventional incandescent
and other types of lamps
1. Low working voltages and currents
2. Less power consumption
3. Very fast action
4. Emission of monochromatic light
5. Small size and weight
6. No effect of mechanical vibrations
7. Extremely long life
Typical LED uses a forward voltage of about 2V and current of 5 to 10mA.GaAs
LED produces infra-red light while red, green and orange lights are produced by gallium
arsenide phosphide (GaAs) and gallium phosphide(Gap) .
Eight leds connected on Port-2 through a latch. All the 8-leds are active high.
Department of Electronics & Communications 20Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
21/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Schematic of LEDS:
Diagram: LEDS
Eight-Tactile (SPST) switches
Eight Tactile switches are connected to port-1. Each key generates an interrupt on INT0 (port3.2) with the help of diodes.
Schematic of Eight Tactile (SPST) switches:
Department of Electronics & Communications 21Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
22/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Diagram: Eight Tactile (SPST) switches
/**********************************************************************//*PROGRAM TO READ INPUTS FROM SWITCHES AND PRODUCE
DIFFERENT DANCING PATTERNS ON LEDS*/
/**********************************************************************/
SW1 EQU P0.0SW2 EQU P0.1SW3 EQU P0.2SW4 EQU P0.3SW5 EQU P0.4SW6 EQU P0.5SW7 EQU P0.6SW8 EQU P0.7ORG 00H /*START OF THE PROGRAM*/
/*INITIALIZATION OF PORTS*/
MOV P0,#0FFHMOV P1,#0FFHMOV P2,#0FFHMOV P3,#0FFHCHECK: MOV P1, #0FFH
MOV P2, #0FFHMOV P3, #0FFH
BACK: JNB SW1, PTRN1 /*CHECKING OF
EIGHT SWITCHES CONTINUOUSLY*/
JNB SW2, PTRN2JNB SW3, PTRN3JNB SW4, PTRN4JNB SW5, PTRN5AJNB SW6, PTRN6AJNB SW7, PTRN7AJNB SW8, PTRN8A
JMP BACK /*STAY IN THE LOOP UNTIL ANY ONE OF THE SWITCHES*/
/* IS PRESSED*/
PTRN1: JNB SW1, PTRN1 /*PATTERN 1*/PTRN_1: MOV P1, #11111111BMOV P2, #11111111BMOV P3, #11111111B
Department of Electronics & Communications 22Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
23/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
ACALL DELAY1MOV P1, #0MOV P2, #0MOV P3, #0ACALL DELAY1
JMP PTRN_1 /*SWITCH IS PRESSED TO COME OUT OF THIS LOOP*/PTRN5A: JMP PTRN5PTRN6A: JMP PTRN6
/*PATTERN 2*/
PTRN2: JNB SW2, PTRN2PTRN_2: MOV P1, #11110000BACALL DELAY1MOV P1, #00001111BACALL DELAY1MOV P2, #11110000B
ACALL DELAY1MOV P2, #00001111BACALL DELAY1MOV P3, #11110000BACALL DELAY1MOV P3, #00001111BACALL DELAY1JMP PTRN_2PTRN8A: JMP PTRN8
/*PATTERN 3*/PTRN3: JNB SW3, PTRN3PTRN_3: MOV P1, #10101010BACALL DELAY1MOV P1, #01010101BACALL DELAY1MOV P2, #10101010BACALL DELAY1MOV P2, #01010101BACALL DELAY1MOV P3, #10101010BACALL DELAY1MOV P3, #01010101BACALL DELAY1JMP PTRN_3PTRN7A: JMP PTRN7
/*PATTERN 4*/
PTRN4: JNB SW4, PTRN4PTRN_4: ACALL DELAY1
Department of Electronics & Communications 23Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
24/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
MOV P1, #11001100BMOV P2, #11001100BMOV P3, #11001100BACALL DELAY1MOV P1, #00110011B
MOV P2, #00110011BMOV P3, #00110011BACALL DELAY1
/* MOV P3, #11011101BMOV P2, #10101010BACALL DELAY1
/* MOV P1, APTRN_4: RR AMOV P2, A
ACALL DELAY1RL AMOV P3, AACALL DELAY1
/* MOV P2, #11111100BACALL DELAY1MOV P3, #00111111BACALL DELAY1
/* MOV P1, #00110011BACALL DELAY1MOV P2, #00110011BACALL DELAY1MOV P3, #00110011BACALL DELAY1 */
JMP PTRN_4PTRN5: JNB SW5, PTRN5
/*PATTERN 5*/
PTRN_5: MOV P1, #0FFHACALL DELAY1MOV P2, #0FFHACALL DELAY1MOV P3, #0FFHACALL DELAY1MOV P1, #7EHACALL DELAY1MOV P2, #7EH
Department of Electronics & Communications 24Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
25/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
ACALL DELAY1MOV P3, #7EHACALL DELAY1MOV P1, #3CHACALL DELAY1
MOV P2, #3CHACALL DELAY1MOV P3, #3CHACALL DELAY1MOV P1, #18HACALL DELAY1MOV P2, #18HACALL DELAY1MOV P3, #18HACALL DELAY1MOV P1, #0H
ACALL DELAY1MOV P2, #0HACALL DELAY1MOV P3, #0HACALL DELAY1MOV P1, #0HACALL DELAY1MOV P2, #0HACALL DELAY1MOV P3, #0HACALL DELAY1MOV P1, #18HACALL DELAY1MOV P2, #18HACALL DELAY1MOV P3, #18HACALL DELAY1MOV P1, #3CHACALL DELAY1MOV P2, #3CHACALL DELAY1MOV P3, #3CHACALL DELAY1MOV P1, #7EHACALL DELAY1MOV P2, #7EHACALL DELAY1MOV P3, #7EHACALL DELAY1MOV P1, #0FFH
Department of Electronics & Communications 25Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
26/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
ACALL DELAY1MOV P2, #0FFHACALL DELAY1MOV P3, #0FFHACALL DELAY1
JMP PTRN_5
PTRN6: JNB SW6, PTRN6 /*PATTERN 6*/MOV A, #10000000BMOV P1, AACALL DELAY1;MOV P2, A;ACALL DELAY1;MOV P3, A;ACALL DELAY1
PTRN_6: RR AMOV P1, AACALL DELAY1RR AMOV P2, AACALL DELAY1RR AMOV P3, AACALL DELAY1
JMP PTRN_6PTRN7: JNB SW7, PTRN7 /*PATTERN 7*/MOV A, #11111110BMOV P1, AACALL DELAY1MOV P2, AACALL DELAY1MOV P3, AACALL DELAY1PTRN_7: RL AMOV P1, AACALL DELAY1RR AMOV P2, AACALL DELAY1RL AMOV P3, AACALL DELAY1JMP PTRN_7
Department of Electronics & Communications 26Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
27/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
PTRN8: JNB SW8, PTRN8 /*PATTERN 8*/PTRN_8: MOV P1, #0H
ACALL DELAY1MOV P1, #0FFHACALL DELAY1MOV P2, #0HACALL DELAY1MOV P2, #0FFHACALL DELAY1MOV P3, #0HACALL DELAY1MOV P3, #0FFHACALL DELAY1
JMP PTRN_8
PTRN8A: JMP PTRN8
DELAY1: MOV R6, #150 /*DELAY TO VISUALISE THEPATTERNS*/
HERE: MOV R7, #150 /*MORE CLEARLY*/
BACKK: JNB SW1, PTRN_1A /*CHECKING OF EIGHTSWITCHES
CONTINUOUSLY*/JNB SW2, PTRN_2AJNB SW3, PTRN_3AJNB SW4, PTRN_4AJNB SW5, PTRN_5AJNB SW6, PTRN_6AJNB SW7, PTRN_7AJNB SW8, PTRN8_ADJNZ R7, BACKKDJNZ R6, HERERETPTRN8_A: JMP PTRN8PTRN_7A: JMP PTRN7PTRN_6A: JMP PTRN6PTRN_5A: JMP PTRN5PTRN_4A: JMP PTRN4PTRN_3A: JMP PTRN3PTRN_2A: JMP PTRN2PTRN_1A: JMP PTRN1
Department of Electronics & Communications 27Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
28/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
END /*END OF THE PROGRAM*//**********************************************************************/
/* Program for 8 Switches and 8 LEDs using C Language*/
/**********************************************************************/
#include sfr LEDS = 0X80;void delay(int );void PATTERN1(void);void PATTERN2(void);void PATTERN3(void);void PATTERN4(void);void PATTERN5(void);void PATTERN6(void);void PATTERN7(void);void PATTERN8(void);
sbit sw1=P1^0;sbit sw2=P1^1;sbit sw3=P1^2;sbit sw4=P1^3;sbit sw5=P1^4;sbit sw6=P1^5;sbit sw7=P1^6;sbit sw8=P1^7;void main(){
P1=0xff;P2=0xff;
while(1){
//while(P1==0xff);
if(sw1==0)PATTERN1();
if(sw2==0)PATTERN2();
if(sw3==0)PATTERN3();
if(sw4==0)PATTERN4();
if(sw5==0)PATTERN5();
if(sw6==0)
Department of Electronics & Communications 28Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
29/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
PATTERN6();if(sw7==0)
PATTERN7();if(sw8==0)
PATTERN8();
} }
void PATTERN1(void){
while(sw1==0); /*debounce check */
while(sw1==1) /* repeat this loop till switch1 is pressed */{
LEDS=0;delay(100);
LEDS=0XFF;delay(100);}
while(sw1==0); /*debounce check */}
void PATTERN2(void){
while(sw2==0); /*debounce check */
while(sw2==1){
LEDS=0X55;delay(100);LEDS=0XAA;delay(100);
}while(sw2==0);
}void PATTERN3(void){
while(sw3==0);
while(sw3==1){
LEDS=0XF0;delay(100);LEDS=0X0F;delay(100);
Department of Electronics & Communications 29Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
30/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
}
while(sw3==0);}
void PATTERN4(void){while(4==0);while(sw4==1)
{LEDS=0X33;delay(100);LEDS=0XCC;delay(100);
}while(sw4==0);
}void PATTERN5(void){
while(sw5==0);while(sw5==1)
{LEDS=0X81;delay(100);LEDS=0X42;delay(100);LEDS=0X24;delay(100);LEDS=0X18;delay(100);LEDS=0X24;delay(100);LEDS=0X42;delay(100);LEDS=0X81;delay(100);
}while(sw5==0);
}
void PATTERN6(void){
while(sw6==0);LEDS=0XFC;while(sw6==1)
Department of Electronics & Communications 30Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
31/75
7/31/2019 Shiva ES Experiments
32/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Results: As per programmed application leds and switches are interface to themicrocontroller AT89s51 with neat schematic . Hence dancing of LEDs application is
verified on embedded 8051 kit.
Department of Electronics & Communications 32Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
33/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 5
SERIAL DATA TRANSMISSION USING 8051
Aim: To perform an experiment demonstrating the serial communication i.e.,
transmission and reception, between the PC and the 8051 SDK microcontroller
development kit.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
General Description:
There are 2 ways to transfer the data in computer one is serial and another is the
parallel communication. In parallel communication data is transferred using 2 or more lines.
Parallel communication is used to transfer data to the devices which are a few feet away and
it is fast. In Serial communication the data is sent one bit at a time. Data can be transferred to
longer distances with minimum number of wires efficiently. It is economical and error free
compared to parallel communication. To establish serial communication we need a
RS232 Serial connector, MAX232 (to match voltage levels of 2 devices) and a serial cable.
Schematic of Serial Communication:
Department of Electronics & Communications 33Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
34/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Hardware Explanation:
RS-232C:
RS-232 (ANSI/EIA-232 Standard) is a standard serial protocol used to establish a
communication between the two same or different processors. RS232 is developed to
support different voltage levels of devices in the range of
+3V to +25V for logic 0
-3V to -25V for logic 1
RS-232 hardware can be used for serial communication up to a distance of 12 feet.
RS232 or DB-9 pin connector:
Pin Functions:
Data: TX on pin 3, RX on pin 2
Handshake: RTS on pin 7, CTS on pin 8, DSR on pin 6,
CD on pin 1, DTR on pin 4
Common: Common pin 5(ground)
Other: RI on pin 9
The method used by RS-232 for communication allows for a simple connection of
three lines: TX, RX, and Ground. The three essential signals for 2 way RS-232
communication are:
TXD: carries data from DTE to the DCE.
RXD: carries data from DCE to the DTE
MAX232:
Max232 is used to convert the TTL voltage levels of microcontroller (logic0-0v,
logic15v) into voltage levels of RS232 standards (logic0 - +3 to +25v, logic1 - 3 to
25v).
MAX232 is a DC-to-DC converter, which takes TTL levels as input and produces RS232
levels, which are required for DTE to DTE communication. RS-232 communication is
Department of Electronics & Communications 34Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
35/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
asynchronous. That is a clock signal is not sent with the data. Each word is synchronized
using its start bit, and an internal clock on each side, keeps tabs on the timing.
The RS232 levels are generated internally using switching latches and capacitors of 10ufeach.
Max232 pin configuration:
Serial Communication Block Diagram:
Serial communication can be established with the help of 2 wires one for transmit and the
one for receiving data.
Department of Electronics & Communications 35Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
36/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Hardware connections:
SFRs Used for Serial Communication:
The special function registers used in serial communication are,
(i) SCON
(ii) TMOD Register
(iii) TCON Register
(iv) Timer(T1) Registers
SCON (Serial Control register):
Load the SCON register with 0x50 to select serial communication in mode 1
(8 bit with variable baud rate).
Serial Mode Selection:
SM2: This bit is used in multi processor communication, hence place SM2=0
REN: (Receive Enable): To receive data in serial communication REN bit must be 1
Department of Electronics & Communications 36Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
37/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Enabling of this bit will not effect the transmission
TB8 & RB8: Transmit 8th bit and receive 8th bit these are used for 9 bit data transferMode when 8-bit data is transmitting place TB8 =0 & RB8 = 0
TI & RI: The Transmit and Receive Interrupt bits these are system control bits activate
When a byte of data is transmitted or received. TI =0 & RI =0
TMOD (Timer Mode Register):
Load the TMOD register with 0x20 to select the TIMER1 in auto reload mode whichgenerates corresponding Baud Rate.
TMOD is dedicated solely to the two timers (T0 & T1).
The timer mode SFR is used to configure the mode of operationof each of the two
timers. Using this SFR your program may configure each timer to be a 16-bit timer, or
13 bit timer, 8-bit auto reload timer, or two separate timers. Additionally you may
configure the timers to only count when an external pin is activated or to count
events that are indicated on an external pin.
It can consider as two duplicate 4-bit registers, each of which controls the action of
one of the timers.
To set TMOD for serial communication the bits in this register are
Gate bit =0
TIMER Mode operation:
TCON (Timer Control Register):
Department of Electronics & Communications 37Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
38/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
The timer control SFR is used to configure and modify the way in which the 8051s
two timers operate. This SFR controls whether each of the two timers is running or
stopped and contains a flag to indicate that each timer has overflowed. Additionally,
some non-timer related bits are located in TCON SFR.
These bits are used to configure the way in which the external interrupt flags are
activated, which are set when an external interrupt occurs.
D7 D6 D5 D4 D3 D2 D1 D0
TF1: Timer 1 over flow flag. Set by hardware when Timer/Counter 1 overflows
TR1: Timer 1 run control bit. Set (or) clear by software to turn Timer/Counter 1 ON and
OFF.
TF0: Timer 0 over flow flag. Set by hardware when Timer/Counter 0 overflows
TR0: Timer 0 run control bit. Set (or) clear by software to turn Timer/Counter 0 ON and
OFF.
IE1: External interrupt 1. Edge flag set by hardware
IT1: Interrupt 1 type control bit. Set (or) cleared by software
IE0: External interrupt 0. Edge flag set by hardware.
IT0: Interrupt 0 type control bit. Set (or) cleared by software
Set the TR1 bit in TCON register to run the TIMER 1 which helps in generation of Baud
rate for serial communication i.e. TR1=1.
BAUD RATE CALCULATION
Internal timer stages are as follows
Department of Electronics & Communications 38Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
39/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Divided by X block can be replaced with T1 timer so that by changing the value oftimer we can obtain the required baud rate.
Let XClk = 11.0592 MHz
Baud Rate = (XClk / 12 / 16 / 2 / X)
For attaining 9600 baud Rate
X can be calculated as
= (11.0592 x 106 ) / (12 * 16 * 2 * 9600)
= 3
So set the 2s Complement of 3 (FD) in Timer 1 so that we can achieve 9600 baud rates.
Note: Assuming 8-bit Auto reload mode and 8-bit variable baud rate modes.
Algorithm:
Serial Transmition Algorithm:
STEP1: Set the baud rate using SCON and TMOD.
STEP2: Copy the data into SBUF.
STEP3: Checks if TI is HIGH, if no go to 3.
STEP4: Clear TI.
STEP5: End.
Serial Reception Algorithm:
STEP1: Set the baud rate using SCON and TMOD.
STEP2: Checks if RI is HIGH, if no go to 2.
STEP3: Clear RI.
STEP4: Copy SBUF into Memory
STEP5: En
Department of Electronics & Communications 39Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
40/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Flow Chart:
Department of Electronics & Communications 40Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
41/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/**********************************************************************//*SERIAL RECEPTION*/
/*FROM PC TO MICROCONTROLLER*//**********************************************************************/
RS11 EQU P2.0 ;ASSIGN NAMES TO THE PORT PINS AS MENTIONEDRW11 EQU P2.1EN EQU P2.2
ORG 00HMOV DPTR, #CMD ;INITIALIZATION OF LCD COMMANDS
BACK1: CLR AMOVC A, @A+DPTR
JZ NEXTACALL COMMANDINC DPTR
SJMP BACK1
NEXT: MOV TMOD, #20H;TO SELECT TIMER 1 IN MODE 2 (AUTO RELOAD)
MOV SCON, #50H; TO SELECT SERIAL COMMUNICATION IN MODE 1; AND RECEIVER ENABLE
MOV TH1, #0FDH ; TO SET THE BAUD RATE TO 9600
BACK: SETB TR1 ; TO START THE TIMER
JNB RI,$;WAIT FOR THE CHARACTER TO BE LOADED INTO SBUF
CLR RI; CLEAR RI FOR THE NEXT RECEPTION
MOV A, SBUF ; TO MOVE THE RECEIVED CHARACTER INTO A
ACALL DATA1 ; CALL SUBROUTINE FOR DISPLAY ON THE LCD
JMP BACK
COMMAND: MOV P1, ACLR RS11
Department of Electronics & Communications 41Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
42/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
CLR RW11SETB EN
ACALL DELAYCLR EN
RET
DATA1: MOV P1, ASETB RS11CLR RW11SETB EN
ACALL DELAYCLR EN
RET
DELAY: MOV R6, #255
HERE: MOV R7, #255DJNZ R7, $DJNZ R6, HERERET
CMD: DB 38H, 0EH, 01H, 06H, 80H, 0END
Department of Electronics & Communications 42Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
43/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/**********************************************************************//*SERIAL TRANSMISSION*/
/*FROM MICROCONTROLLER TO PC*//**********************************************************************/
ORG 00H MOV TMOD, #20H;TO SELECT TIMER 1 IN MODE 2(AUTO RELOAD)
MOV SCON, #50H; TO SELECT SERIAL COMMUNICATION IN MODE 1; AND RECEIVER ENABLE
MOV TH1, #0FDH ; TO SET THE BAUD RATE TO 9600MOV DPTR, #MSG
BACK: CLR A
MOVC A,@A+DPTR ; TO LOAD THE MESSAGE INTO; ACCUMULATOR CHARACTER BYCHARACTER
JZ NEXTACALL TRANSMIT ;CALL SUBROUTINE FOR TRANSMISSION
INC DPTRSJMP BACK
NEXT: SJMP NEXT ;TERMINATION OF THE PROGRAM/*TRANSFERRING DATA SERIALLY*/TRANSMIT: SETB TR1 ; TO START THE TIMER
MOV SBUF, A ; LOAD DATA INTO SBUFJNB TI, $ ;WAIT FOR THE TRANSMISSION TO BE
;COMPLETEDCLR TI ;CLEAR TI FOR NEXT TRANSMISSION
RETMSG:
DB 13, 10,"Welcome to Nishitha College Of Engineering & Technology,Hyderabad, 13,10,13,10, "You are working with WINKIT Brand World Class, State-of-Art EmbeddedSystems Lab Trainer Board", 13, 10, 0END
Results: As per programmed application serial communication, LCD and PC interface to
the microcontroller AT89s51 with the help of RS-232 cable. Hence Serial
Department of Electronics & Communications 43Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
44/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
communication application is verified on embedded 8051 kit and PC with the help of keil
uvision and Encript, with communication terminal in the PC.
Output of the Program:
Screen 1 : Transmitter Window
Screen 2 : Receiver Window
Department of Electronics & Communications 44Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
45/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
RESULTS: Demonstrating the serial communication i.e., transmission and reception,
between the PC and the 8051 SDK microcontroller has been verified.
Experiment No: 6
ANALOG-TO-DIGITAL CONVERTER
Aim: To interface an analog-to-digital converter (ADC) with the 8051-SDK
Microcontroller Development Kit and send the analog data such as the temperature to the
PC.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
ANALOG TO DIGITAL CONVERTER, DIGITAL TO ANALOG CONVERTER
(PCF8591P)
It is an I2C device which consists of 4 Channel 8-bit Analog to Digital Converterand 1 channel 8 bit Digital to Analog Converter, which is connected to I2C bus.
General Description:
The PCF8591 is a single-chip, single-supply low power 8-bit CMOS data acquisition
device with four analog inputs, one analog output and a serial I2C-bus interface. Three
address pins A0, A1 and A2 are used for programming the hardware address, allowing the
use of up to eight devices connected to the I2C-bus without additional hardware. Address,
control and data to and from the device are transferred serially via the two-line bidirectional
I2C-bus. The functions of the device include analog input multiplexing, on-chip track and
hold function, 8-bit analog-to-digital conversion and an 8-bit digital-to-analog conversion.
The maximum conversion rate is given by the maximum speed of the I2C.
Department of Electronics & Communications 45Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
46/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Schematic of ADC/DAC:
Department of Electronics & Communications 46Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
47/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Features:
Single power supply
Operating supply voltage 2.5 V to 6 V
Low standby current
Serial input/output via I2C-bus
Address by 3 hardware address pins
Sampling rate given by I2C-bus speed
4 analog inputs programmable as single-ended or differential inputs
Auto-incremented channel selection
Analog voltage range from VSS to VDD
On-chip track and hold circuit
8-bit successive approximation A/D conversion
Multiplying DAC with one analog output.
Applications:
Closed loop control systems
Low power converter for remote data acquisition Battery operated equipment
Acquisition of analog values in automotive, audio and TV applications.
Department of Electronics & Communications 47Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
48/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/*********************************************************************//* program to send the adc data(temperature) to pc */
**********************************************************************/#include #includesbit RD1 = P2^5;sbit WR1 = P2^6;sbit INTR1 =P2^7;sfr adcdata = 0x90;//void display(unsigned char );
void delay(int );void main(){ unsigned char value;
SCON=0X50;TMOD=0X20;TH1=0XFD;TR1=1;printf("temeperature:");adcdata=0xff;INTR1=1;RD1=1;
while(1){ WR1=0;
delay(5);
WR1=1;while(INTR1==1);RD1=0;value=adcdata;printf("%d",value);//display(value);RD1=1;
}}/*void display(unsigned char ){ unsigned char x,d1,d2,d3;
x=value/10;d1=value%10;d2=x%10;d3=x/10;*/
void delay(int n){ int x,y;
for(x=0;x
7/31/2019 Shiva ES Experiments
49/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
for(y=0;y
7/31/2019 Shiva ES Experiments
50/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 7
REAL TIME CLOCK
Aim: To interface a real time clock (RTC) with the 8051-SDK MicrocontrollerDevelopment Kit.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
: /*********************************************************************//* program for RTC */
**********************************************************************/
#include
#include
#include
#include
void send(unsigned char dat) // uart baud rate set to 9600
{
TMOD = 0X20;
TH1 = 0XFD;
SCON = 0X50;TR1 = 1;
SBUF = dat;
while(TI == 0){}
TI = 0;
TR1 = 0;
Department of Electronics & Communications 50Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
51/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
}
void print(char *str)
{
while(*str != '\0')
{
send(*str);
str++;
}
}
void ToASCII(unsigned int t)
{
if(t
7/31/2019 Shiva ES Experiments
52/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
__bit __at(0x94) SCLK;
__bit __at(0x95) SDA;
bit ACK;
#define HIGH 01;
#define LOW 00;
unsigned int read_time[0x03];
void set_rtc_time();
void get_rtc_time();
int get_hour();
int get_minute();
int get_second();
unsigned int hour,minute,second;
void set_hour() // load the RTC hour register (0x04)
{
I2C_START();
I2C_WRITE(0XA0);
I2C_WRITE(0x04);
I2C_WRITE(0x02);
I2C_STOP();
}void set_minute() // load the RTC minute register
(0x03)
{
I2C_START();
I2C_WRITE(0XA0);
I2C_WRITE(0x03);
I2C_WRITE(0x15);
I2C_STOP();}
void set_second() // load the RTC second register (0x02)
{
I2C_START();
I2C_WRITE(0XA0);
Department of Electronics & Communications 52Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
53/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
I2C_WRITE(0x02);
I2C_WRITE(0x56);
I2C_STOP();
}
int get_second() // read RTC second register (0x02)
{
unsigned char s;
I2C_START();
I2C_WRITE(0XA0);
I2C_WRITE(0x02);
I2C_STOP();
I2C_START();
I2C_WRITE(0XA1);
s = I2C_READ();
I2C_STOP();
return(s);
}
int get_minute() // read the RTC minute register (0x03)
{
unsigned char m;I2C_START();
I2C_WRITE(0XA0);
I2C_WRITE(0x03);
I2C_STOP();
I2C_START();
I2C_WRITE(0XA1);
m = I2C_READ();
I2C_STOP();
return(m);
}
int get_hour() // read the RTC hour register (0x04)
{
unsigned char h;
Department of Electronics & Communications 53Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
54/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
I2C_START();
I2C_WRITE(0XA0); //RTC write command
I2C_WRITE(0x04); //RTC Control Register address
I2C_STOP();
I2C_START();
I2C_WRITE(0XA1); //RTC read command
h = I2C_READ();
I2C_STOP();
return(h);
}
void main()
{
set_hour();
set_hour();
set_minute();
set_second();
while(1)
{
second = get_second();
minute = get_minute();hour = get_hour();
minute = get_minute();
second = get_second();
hour = get_hour();
print("\n\r Real Time Clock = ");
ToASCII(hour/16);
ToASCII(hour%16);
send(0x20);
ToASCII(minute/16);
ToASCII(minute%16);
minute = get_minute();
minute = get_minute();
second = get_second();
Department of Electronics & Communications 54Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
55/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
send(0x20);
ToASCII(second/16);
ToASCII(second%16);
}
}
void I2C_START() //starting i2c by creating a clock pulse by settingand clearing the port pins
{
SCLK =LOW;
SDA =LOW;
Delay_Time();
Delay_Time();
SCLK=HIGH;
Delay_Time();
Delay_Time();
SDA=HIGH;
Delay_Time();
Delay_Time();
SDA=LOW;
Delay_Time();
Delay_Time();
SCLK=LOW;
}
void I2C_WRITE(unsigned char j) //write data/command to RTC registers
{
dat=j;for(i=0;i
7/31/2019 Shiva ES Experiments
56/75
7/31/2019 Shiva ES Experiments
57/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Delay_Time();
SCLK=LOW;
}
Delay_Time();
Delay_Time();
SDA = LOW;
Delay_Time();
Delay_Time();
SCLK = HIGH;
Delay_Time();
Delay_Time();
SCLK = LOW;
Delay_Time();
Delay_Time();
SDA = HIGH;
return(j);
}
void Delay_Time()
{ unsigned long int i;for(i=0;i
7/31/2019 Shiva ES Experiments
58/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 8
DIGITAL-TO-ANALOG CONVERTER
Aim: To interface an digital-to-analog converter (DAC) with the 8051-SDK
Microcontroller Development Kit using I2C protocol.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
/*********************************************************************//* program for DAC */
**********************************************************************/
#include
#define HIGH 01;
#define LOW 00;
__xdata __at 0xffc5 unsigned char swt;
__idata unsigned char dat;
__idata unsigned char i;
__bit __at(0x94) SCLK;
__bit __at(0x95) SDA;
bit ACK;
void I2C_Start(void);
void I2C_Stop(void);
void I2C_Write(unsigned char j);
Department of Electronics & Communications 58Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
59/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
unsigned char I2C_Read(void);
void Delay_Time();
void I2C_Start(void) //Start I2C by creating clock by setting and clearing the portpins
{
SCLK=LOW;
SDA=LOW;
Delay_Time();
SCLK = HIGH;
Delay_Time();
SDA=HIGH;
Delay_Time();
SDA = LOW;
Delay_Time();
SCLK = LOW;
}
void I2C_Stop(void) //Stop I2C operation by clearing the SCLK Pin
{
SCLK = LOW;
Delay_Time();
SDA = HIGH;
}
void I2C_Write(unsigned char j) // shifting data bit by bit to MSB andmoving through i2c
{
dat=j;
for(i=0;i
7/31/2019 Shiva ES Experiments
60/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
SCLK = LOW;
}
SDA=HIGH;
Delay_Time();
SCLK = HIGH;
Delay_Time();
ACK = SDA;
Delay_Time();
SCLK = LOW;
}
unsigned char I2C_Read(void) //reading from i2c device bit by bit
{
unsigned char i,j;
j = 0;
i = SDA;
for(i=0;i
7/31/2019 Shiva ES Experiments
61/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
void main()
{
unsigned int i=0x00;
I2C_Start();
I2C_Write(0x9E); //send device address
I2C_Write(0x40); //send device's control register address
I2C_Start();
I2C_Write(0x9E); // send command for read
while(1)
{
if((swt & 0x1f)== 0x1E)
{
i=i+0x0a;
if(i>0xff)
i=0x00;
I2C_Write(i);
Delay_Time();
}
}
}void Delay_Time()
{
unsigned int i;
for(i=0;i
7/31/2019 Shiva ES Experiments
62/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 9
STEPPER MOTOR
Aim: To interface a stepper motor with the 8051-SDK Microcontroller Development
Kit.
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
: /*********************************************************************//* program for stepper motor */
**********************************************************************/
#include
void serial_intr (void) interrupt 4;void delay_ms(unsigned int j){unsigned int k;while(j-->0){
for(k=0;k
7/31/2019 Shiva ES Experiments
63/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
delay_ms(5);
P1 = 0x66;delay_ms(5);
P1 = 0xaa;delay_ms(5);
P1 = 0x99;delay_ms(5);
}}
RESULT :
As per programmed application stepper motor is interface to the microcontroller
AT89s51.
Department of Electronics & Communications 63Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
64/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Experiment No: 10
SEVEN SEGMENT DISPLAY
Aim: To interface seven segment display with the 8051-SDK Microcontroller
Development Kit
Apparatus, Equipments and Tools:
1. 12V DC, 1.5A Adaptor
2. 8051 SDK Microcontroller Development Kit
3. RS 232 serial communication cable
4. Personal Computer
5. Keil Software
6. AC Power Supply
Description:
Each of the segments of the display is connected to a pin on the 8051 (the
schematic shows how to do this). In order to light up a segment on the the pin must be set
to 0V. To turn a segment off the corresponding pin must be set to 5V. This is simply done
by setting the pins on the 8051 to '1' or '0'.
LED displays are
Power-hungry (10ma per LED)
Pin-hungry (8 pins per 7-seg display)
But they are cheaper than LCD display
7-SEG Display are available in two types -1. Common anode & 2. common cathode ,
but command anode display are most suitable for interfacing with 8051 since 8051 port
pins can sink current better than sourcing it.
Department of Electronics & Communications 64Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
65/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
CREATING DIGIT PATTERN
For displaying Digit say 7 we need to light segments -a ,b, c. Since we are using
Common anode display , to do so we have to to provide Logic -0 (0 v) at anode of these
segments.
so need to clear pins- P1.0 ,P1.1,P1.2. that is 1 1 1 1 1 0 0 0 -->F8h .
Digit Seg. h Seg. g Seg. f Seg. e Seg. d Seg. c Seg. b Seg. a HEX
0 1 1 0 0 0 0 0 0 C0
1 0 0 0 0 0 1 1 0 06
2 1 0 1 0 0 1 0 0 A4
3 1 0 1 1 0 0 0 0 B0
4 1 0 0 1 1 0 0 1 99
Department of Electronics & Communications 65Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
66/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
Connection
You can also do this for some characters like A ,E .. but not for D or B because it
will be same as that of 0 & 8 . So this is one of limitation of 7-seg display.Since we can Enable only one 7-seg display at a time ,we need to scan these display at
fast rate .The scanning frequency should be high enough to be flicker-free. At least 30HZ
.Therefore time one digit is ON is 1/30 seconds
INTERFACING
Note that I am using Common Anode display. so the common Anode pin is tied to
5v .The cathode pins are connected to port 1 through 330 Ohm resistance (current
limiting).
Department of Electronics & Communications 66Nishitha College of Engineering and Technology
Segment number 8051 pin number
a P1.0
b P1.1
c P1.2
d P1.3
e P1.4
f P1.5
g p1.6
h(dp) P1.7
7/31/2019 Shiva ES Experiments
67/75
7/31/2019 Shiva ES Experiments
68/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
float measure_temp(void);
unsigned char pulse,temp_id[9];
unsigned char a,b,c;
bit t_flag=0;
unsigned char cnt;
int n;
float m;
void main (void)
{
unsigned char k,l,u,r,g,h,j;
float f;
init();
clr();
while(1)
{
j=0xf0;
f=measure_temp();
k=f;
l=k/10;u=k%10;
j=j+u;
m=f-k;
m=m*100;
r=m;
g=r/10;
h=r%10;
write(1,15);
write(2,15);
write(3,15);
write(4,15);
write(5,l);
write(6,j);
Department of Electronics & Communications 68Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
69/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
write(7,g);
write(8,h);
delay_ms(1000);
}
}
float measure_temp(void)
{
float f;
pulse=reset();
if(pulse==0)
write_byte(0xcc); //skip rom
write_byte(0x44); //convert temp
delay_ms(750);
pulse=reset();
if(pulse==0)
write_byte(0xcc); //skip rom
read_ds1822();
f=measure_ds1822();
return f;}
float measure_ds1822(void)
{
unsigned char temp_msb,temp_lsb,temp,mask=0x01,decimal=0;
int sign=1,cnt=16;
float f=0.0;
temp_lsb=temp_id[0];
temp_msb=temp_id[1];
if(temp_msb>=0x80)
{
sign=-1;
temp_lsb=(~temp_lsb)+1;
Department of Electronics & Communications 69Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
70/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
temp_msb=~temp_msb;
}
decimal=(temp_lsb4;
temp=temp_msb4;
do
{
if(decimal&mask)
f=f+((float)1/cnt);
cnt=cnt/2;
mask=mask*2;
}while(mask
7/31/2019 Shiva ES Experiments
71/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
/*-------------------------------------------------------------------------------------------*/
unsigned char reset()
{
unsigned char presence;
WIRE=0;
delay_micro(29);
WIRE=1;
delay_micro(3);
presence=WIRE;
delay_micro(25);
return presence;
}
void write_byte(unsigned char c)
{
int mask1;
for(mask1=1;mask1
7/31/2019 Shiva ES Experiments
72/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
c=c|mask1;
}
return c;
}
void write_bit1()
{
WIRE=0;
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_(); //6us
WIRE=1;
delay_micro(3); //60us
}
void write_bit0()
{
WIRE=0;
delay_micro(3); //64us
WIRE=1;_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_(); //10us
}
unsigned char read_bit()
{
unsigned char b;
WIRE=0;
_nop_();_nop_();
_nop_();_nop_();
Department of Electronics & Communications 72Nishitha College of Engineering and Technology
7/31/2019 Shiva ES Experiments
73/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
_nop_();_nop_(); //6us
WIRE=1;
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();_nop_(); //9us
b=WIRE;
delay_micro(2); //55us
return b;
}
/*-------------------------------------------------------------------------------------------*/
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j
7/31/2019 Shiva ES Experiments
74/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
void init(void)
{
write(0x09,0xff);//decode mode reg set to nodecode operation
write(0x0a,0x0f);//intensity reg set to maximum intensity
write(0x0b,0x07);//scan limit reg set to 4 seven segments
write(0x0c,0x01);//shutdown reg set tonormal mode
write(0x0f,0x00);//display test reg is ste to 0 i.e. normal operation
clr();
}
void write(unsigned char address, unsigned char dataa)
{
unsigned char i,mask=0x80;
LOAD=0;
for(i=0;i>1;
}
mask=0x80;
for(i=0;i
7/31/2019 Shiva ES Experiments
75/75
M.Tech.Sem II (ES Lab) Roll No.: 11M31D5704
CLK=0;
if(dataa & mask)
DI=1;
else
DI=0;
CLK=1;
mask=mask>>1;
}
LOAD=1;
}
void clr(void)
{
write(dig1,0x00);
write(dig2,0x00);
write(dig3,0x00);
write(dig4,0x00);
write(dig5,0x00);
write(dig6,0x00);
write(dig7,0x00);
write(dig8,0x00);}
RESULTS: Interface seven segment display with the 8051-SDK Microcontroller