You are on page 1of 30

IPC EDUCATIONAL TRAINERS

8051 BASED MICROCONTROLLER TRAINER & PROGRAMMER Model: - IPC-8605-MC

Teacher / Student User Manual

Note:- we reserve the right to change the shape & design of the trainer without prior notice.
Ijaz Parvez &Co, 3 Hall Road Lahore Ph # 042-5424363, 7352790 Email: - babar_imtiaz@yahoo.com

TABEL OF CONTENTS: History 8051 Microcontroller Single Bit Port Programming Byte Writing Bit Rotation Arithmetic Instruction Logic Instruction LCD Interface Serial Communication Seven Segment Drive Key Pad Interface Traffic Light Signal 1 3 4 7 9 10 13 16 18 21 23 26

History
It was year 1969, and a team of Japanese engineers from the BUSICOM Company arrived to United States with a request that a few integrated circuits for calculators be made using their projects. The proposition was set to INTEL, and Marcian Hoff was responsible for the project. Since he was the one who has had experience in working with a computer (PC) PDP8, it occured to him to suggest a fundamentally different solution instead of the suggested construction. This solution presumed that the function of the integrated circuit is determined by a program stored in it. That meant that configuration would be more simple, but that it would require far more memory than the project that was proposed by Japanese engineers would require. After a while, though Japanese engineers tried finding an easier solution, Marcian's idea won, and the first microprocessor was born. In transforming an idea into a ready made product, Frederico Faggin was a major help to INTEL. He transferred to INTEL, and in only 9 months had succeeded in making a product from its first conception. INTEL obtained the rights to sell this integral block in 1971. First, they bought the license from the BUSICOM Company who had no idea what treasure they had. During that year, there appeared on the market a microprocessor called 4004. That was the first 4-bit microprocessor with the speed of 6 000 operations per second. Not long after that, American company CTC requested from INTEL and Texas Instruments to make an 8-bit microprocessor for use in terminals. Even though CTC gave up this idea in the end, Intel and Texas Instruments kept working on the microprocessor and in April of 1972, first 8-bit microprocessor appeared on the market under a name 8008. It was able to address 16Kb of memory, and it had 45 instructions and the speed of 300 000 operations per second. That microprocessor was the predecessor of all today's microprocessors. Intel kept their developments up in April of 1974, and they put on the market the 8-bit processor under a name 8080 which was able to address 64Kb of memory, and which had 75 instructions, and the price began at $360. In another American company Motorola, they realized quickly what was happening, so they put out on the market an 8-bit microprocessor 6800. Chief constructor was Chuck Peddle, and along with the processor itself, Motorola was the first company to make other peripherals such as 6820 and 6850. At that time many companies recognized greater importance of microprocessors and began their own developments. Chuck Peddle leaved Motorola to join MOS Technology and kept working intensively on developing microprocessors. At the WESCON exhibit in United States in 1975, a critical event took place in the history of microprocessors. The MOS Technology announced it was marketing microprocessors 6501 and 6502 at $25 each, which buyers could purchase immediately. This was so sensational that many thought it was

some kind of a scam, considering that competitors were selling 8080 and 6800 at $179 each. As an answer to its competitor, both Intel and Motorola lowered their prices on the first day of the exhibit down to $69.95 per microprocessor. Motorola quickly brought suit against MOS Technology and Chuck Peddle for copying the protected 6800. MOS Technology stopped making 6501, but kept producing 6502. The 6502 was a 8-bit microprocessor with 56 instructions and a capability of directly addressing 64Kb of memory. Due to low cost , 6502 becomes very popular, so it was installed into computers such as: KIM-1, Apple I, Apple II, Atari, Comodore, Acorn, Oric, Galeb, Orao, Ultra, and many others. Soon appeared several makers of 6502 (Rockwell, Sznertek, GTE, NCR, Ricoh, and Comodore takes over MOS Technology) which was at the time of its prosperity sold at a rate of 15 million processors a year! Others were not giving up though. Frederico Faggin leaves Intel, and starts his own Zilog Inc. In 1976 Zilog announced the Z80. During the making of this microprocessor, Faggin made a pivotal decision. Knowing that a great deal of programs have been already developed for 8080, Faggin realized that many would stay faithful to that microprocessor because of great expenditure which redoing of all of the programs would result in. Thus he decided that a new processor had to be compatible with 8080, or that it had to be capable of performing all of the programs which had already been written for 8080. Beside these characteristics, many new ones have been added, so that Z80 was a very powerful microprocessor in its time. It was able to address directly 64 Kb of memory, it had 176 instructions, a large number of registers, a built in option for refreshing the dynamic RAM memory, single-supply, greater speed of work etc. Z80 was a great success and everybody converted from 8080 to Z80. It could be said that Z80 was without a doubt commercially most successful 8-bit microprocessor of that time. Besides Zilog, other new manufacturers like Mostek, NEC, SHARP, and SGS also appeared. Z80 was the heart of many computers like Spectrum, Partner, TRS703, Z-3. In 1976, Intel came up with an improved version of 8-bit microprocessor named 8085. However, Z80 was so much better that Intel soon lost the battle. Altough a few more processors appeared on the market (6809, 2650, SC/MP etc.), everything was actually already decided. There weren't any more great improvements to make manufacturers convert to something new, so 6502 and Z80 along with 6800 remained as main representatives of the 8bit microprocessors of that time.

Microcontrollers versus Microprocessors


Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In short that means that microprocessor is the very heart of the computer. On the other hand, microcontroller is designed to be all of that in one. No other external components are needed for its

application because all necessary peripherals are already built into it. Thus, we save the time and space needed to construct devices.

8051 MICROCONTROLLER
A large variety of microcontrollers are available in market. Most common are 8051 and pic microcontroller family. In 8051 family there are many chips having different part number, & brands. Intel Philips, Dallas, seimens, Atmel etc. but in Pakistan there is only atmel brand is most commonly used. There are some microcontrollers number of 8051 family, AT89C51/52/55 & AT89S51/52/53. We will use in all labs AT89S51.

Features
Compatible with MCS-51 Products 4K Bytes of In-System Programmable (ISP)
Flash Memory Endurance: 1000 Write/Erase Cycles 4.0V to 5.5V Operating Range Fully Static Operation: 0 Hz to 33 MHz Three-level Program Memory Lock 128 x 8-bit Internal RAM 32 Programmable I/O Lines Two 16-bit Timer/Counters Six Interrupt Sources Full Duplex UART Serial Channel Low-power Idle and Power-down Modes Interrupt Recovery from Power-down Mode Watchdog Timer Dual Data Pointer Power-off Flag Fast Programming Time Flexible ISP Programming (Byte and Page Mode)

Description
The AT89S51 is a low-power, high-performance CMOS 8-bit microcontroller with 4K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industrystandard 80C51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S51 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications. The AT89S51 provides the following standard features: 4K bytes of Flash, 128 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, two 16-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S51 is designed with static logic for operation

down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next external interrupt or hardware reset.

LAB # 1
SINGLE BIT PORT PROGRAMMING
OBJECTIVE: HOW TO PROGRAME SINGLE BIT OF POTR DESCRIPTION: There are some examples of single bit instruction. You just type these examples in Pinnacle52 software and name the file with extension asm (test.asm).This file is called assembly source file. Now you will need an executable file to run this program into microcontroller, so press ctrl+f2 keys for making an executable file. Now this file should copied into microcontroller by using IPC MC- 8605 and verify the performance. Now you can see your program output on LEDs connecting with port 2.

Apparatus / Component.
Microcontroller AT89S51, IPC MC- 8605.

Example #1. Single LED blinking. ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} LOOP: SETB ACALL CLR ACALL SJMP DELAY: MOV AG: MOV DJNZ DJNZ RET END R2,#0FFH R2,$ R1,AG ;write value on register R2. ; stay here till R2=0 ; jump on label (AG) if R2 not equal to zero. ; return R1,#0FFH ;write value on register R1. P2.0 DELAY P2.0 DELAY LOOP ; Set bit zero of port 2. ; delay (140ms) ; low bit zero of port 2. ; delay (140ms) ; jump to function LOOP

;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} 6

Example #2. Two LED blinking. ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ SETB P2.0 ; Set bit zero of port 2. SETB ACALL CLR CLR P2.1 ; Set bit one of port 2.

DELAY ; delay (140ms) P2.0 ; low bit zero of port 2. P2.1 ; low bit one of port 2.

ACALL DELAY SJMP LOOP ; Jump to label (LOOP). DELAY: MOV AG: MOV R2,#0FFH ;write value on register R2. DJNZ R2,$ ; stay here till R2=0 DJNZ R1,AG ; jump on label (AG) if R2 not equal to zero. RET ; retun END ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} R1,#0FFH ;write value on register R1.

Example #3. Running lights ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ LOOP: SETB ACALL CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB CLR ACALL SETB SJMP P2.7 DELAY P2.7 DELAY P2.7 P2.6 DELAY P2.6 P2.5 DELAY P2.5 P2.4 DELAY P2.4 P2.3 DELAY P2.3 P2.2 DELAY P2.2 P2.1 DELAY P2.1 P2.0 DELAY P2.1 LOOP ; Set bit seven of port 2. ; delay (140ms) ; low bit seven of port 2. ;delay (140ms) ; Set bit seven of port 2. ; low bit six of port 2. ;delay (140ms) ; Set bit six of port 2. ; low bit five of port 2. ; Set bit five of port 2. ; low bit four of port 2. ; Set bit four of port 2. ; low bit three of port 2. ; Set bit three of port 2. ; low bit two of port 2. ; Set bit two of port 2. ; low bit one of port 2. ; Set bit one of port 2. ; low bit zero of port 2. ; Set bit one of port 2. ; Jump to label (LOOP). 8

DELAY: AG: MOV MOV DJNZ DJNZ RET END R1,#0FFH R2,#0FFH R2,$ R1,AG ;write value on register R1. ;write value on register R2. ; stay here till R2=0 ; jump on label (AG) if R2 not equal to zero. ; return :End of program

LAB # 2
BYTE WRITING
OBJECTIVE: HOW TO WRITE DATA ON PORTS/REGISTER/MEMORY ADDRESS.

DESCRIPTION: There are some examples of byte writing instruction. You just type these examples in Pinnacle52 software and name the file with extension asm (first.asm).This file is called assembly source file. Now you will need an executable file to run this program into microcontroller, so press ctrl+f2 keys for making an executable file. Now this file should copied into microcontroller by using IPC MC- 8605 Now you can see your program output on LEDs connecting with port 2.

Apparatus / Component.
Microcontroller AT89S51, IPC MC- 8605 .

Example #1. Write byte on ports & registers. ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ LOOP: MOV P2,#0 ;Send value on port 2. ACALL DELAY ;Delay (2100ms) MOV P2,#0FFH ;Send value on port 2. ACALL DELAY ;Delay (2100ms) MOV R4,#3 ;Send value in register R4. MOV P2,R4 ;Copy data of R4 into port 2. ACALL DELAY MOV R7,#100 ACALL DELAY MOV P2,R7 ;Copy data of R7 into port 2. ACALL DELAY SJMP LOOP ;Delay (2100ms) DELAY: MOV REE: MOV AG: MOV R2,#0FFH ;write value on register R2. DJNZ R2,$ ; stay here till R2=0 DJNZ R1,AG ; jump on label (AG) if R2 not equal to zero. DJNZ R0,REE ; jump on label (REE) if R0 not equal to zero. RET END ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} R1,#0FFH ;write value on register R1. R0,#0FH ;write value on register R0

10

Example #2. Write byte to register, copy byte to register, copy byte to Accumulator ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ LOOP: MOV R4,#11 ; write data in R4 MOV R5,R4 ; Copy R4 data into R5 MOV P2,R5 ; Copy R5 data into P2 ACALL DELAY MOV A,#51 ; ; write data in A MOV P2,A ACALL DELAY MOV R4,P2 MOV A,#200 MOV P2,A ACALL DELAY MOV P2,R4 ACALL DELAY SJMP LOOP DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END :End of program ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} R1,#0FFH R0,#0FH

11

LAB #3
BIT ROTATION
OBJECTIVE: How To Rotate Bits Of Any Ports/Register/Memory address DESCRIPTION: There are some examples of bit rotating instructions. You just type these examples in Pinnacle52 software and name the file with extension asm (rotate.asm). This file is called assembly source file. Now you will need an executable file to run this program into microcontroller so press ctrl+f2 keys for making an executable file. Now this file should copied into microcontroller by using programmer device. The programmed microcontroller should be place on microcontroller to verify the performance. Now you can see your program output on LEDs connecting with port 2

Apparatus / Component.
Microcontroller AT89C51, IPC MC- 8605 . Example #1 Rotate accumulator bits left and copy accumulator data on port2. ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ MOV LOOP: MOV ACALL RL SJMP DELAY: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG RET END :End of program ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} Example #2. Rotate accumulator bits right and copy accumulator data on port2. ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ MOV A,#01111111B ; A=127 LOOP: MOV P2,A ACALL DELAY RR A SJMP LOOP DELAY: MOV R1,#0FFH AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG 12 R1,#0FFH P2,A ; write value of register A on port2 DELAY A ; Rotate left bits of register A LOOP A,#11111110B ; A=254

RET END :End of program

LAB #4
ARITHMETIC INSTRUCTIONS
OBJECTIVE: HOW TO PLUS, MINUS, MULTIPLY, AND DIVIDE NUMBERS IN 8051. DESCRIPTION: There are some examples of arithmetic instructions. You just type these examples in Pinnacle52 software and name the file with extension asm(abc.asm). This file is called assembly source file. Now you will need an executable file to run this program into microcontroller, so press ctrl+f2 keys for making an executable file. Now this file should copied into microcontroller by using programmer device. The programmed microcontroller should be place on microcontroller trainer to verify the performance. Now you can see your program output on LEDs connecting with port 2

Apparatus / Component.
Microcontroller AT89C51, IPC MC- 8605 . Example #1. THIS IS ADDITION EXAMPLE ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ ORG 30H LOOP: MOV A,#10 ; A=10 MOV R7,#51 ; R7=51 ADD A,R7 ;A+R7=61, Now A= 61 MOV P2,A ; P2=A . (P2=61) ACALL DELAY ; 140ms delay ADD A,#33 ; A=33 MOV P2,A ; A=P2. (P2=33) ACALL DELAY SJMP LOOP ; GOTO LOOP DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END :End of program ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} R1,#0FFH R0,#01FH

13

Example #2. SUBTRACTION ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ ORG LOOP: MOV MOV SUBB MOV ACALL MOV SUBB MOV ACALL SJMP LOOP DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END ;}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} Example #3. MULTILPLICATION LOOP: MOV MOV MUL MOV ACALL MOV ACALL MUL MOV ACALL MOV ACALL A,#10 B,#11 AB P2,A DELAY P2,B DEL AB P2,A DELAY P2,B DELAY 14 R1,#0FFH R0,#1FH A,#10 ;A=10 R3,#1 ; R3=1 A,R3 ; A-R3=9, NOW A=9 P2,A ; P2=9 DELAY A,#101 ; A=101 A,#99 ; A-99=2 P2,A ; P2=2 DELAY 30H

SJMP LOOP DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END ;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ R1,#0FFH R0,#1FH

Example #4. DIVISION MOV MOV DIV MOV ACALL MOV ACALL MOV MOV DIV MOV ACALL MOV ACALL SJMP LOOP A,#99 B,#9 AB P2,A DELAY P2,B DELAY A,#205 B,#11 AB P2,A DELAY P2,B DELAY

DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END 15 R1,#0FFH R0,#1FH

16

LAB #5
LOGIC INSTRUCTION
OBJECTIVE: How to use logic instructions (Anding, Oring, Xoring, compliment). DESCRIPTION: There are some examples of logic control instructions. You just type these examples in Pinnacle52 software and name the file with extension asm (abc.asm) This file is called assembly source file. Now you will need an executable file to run this program into microcontroller, so press ctrl+f2 keys for making an executable file. Now this file should copied into microcontroller by using programmer device. After programmed microcontroller you should be place this on microcontroller trainer to verify the performance. Now you can see your program output on LEDs connecting with port 2

Apparatus / Component.
Microcontroller AT89C51, IPC MC- 8605 . Example of logic And. ORG 30H MOV A,#10101010B ANL A,#11111111B MOV P2,A ACALL DELAY MOV A,#01111000B ANL A,#11001001B ;anding MOV P2,A ACALL DELAY SJMP LOOP DELAY: MOV R0,#1FH REE: MOV R1,#0FFH AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END

17

Example of logic Or gate


ORG 30H LOOP: MOV A,#00001111B ORL A,#11110001B MOV P2,A ACALL DELAY MOV P2,A ACALL DELAY SJMP LOOP DELAY: MOV R0,#1FH REE: MOV R1,#0FFH AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}]

example of Xor gate.

ORG LOOP: MOV XRL MOV ACALL XRL MOV ACALL SJMP DELAY: MOV REE: MOV AG: MOV

30H A,#00110110B A,#00100001B P2,A DELAY A,#00000000B P2,A DELAY LOOP R0,#1FH R1,#0FFH R2,#0FFH 18

DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END Example of Compliment bits (Not gate). ORG LOOP: MOV MOV ACALL CPL MOV ACALL SJMP DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END R1,#0FFH R0,#0AH A,#00001111B P2,A DELAY A P2,A DELAY LOOP 30H

19

LAB #6
LCD interface Objective: How to interface alphanumeric LCD to 8051.
DESCRIPTION: There is an examples of interfacing a matrix LCD to 8051 microcontroller. You just type this example in Pinnacle52 software and name the file with extension asm(lcd.asm). This file is called assembly source file. Now you will need executable file to run this program into microcontroller so press ctrl+f2 keys for making executable file. this file should copied into microcontroller by using programmer device. After programmed microcontroller you should be place on microcontroller trainer to verify the performance. Now you can see your program output on LCD connecting with microcontroller.

Apparatus / Component.
Microcontroller AT89C51, IPC MC- 8605.

LCD code example.


ORG MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL 30H A,#38H ; 2 Line LCD COMNWRT DELAY A,#38H COMNWRT DELAY A,#0EH COMNWRT DELAY A,#01H COMNWRT DELAY A,#06H COMNWRT DELAY A,#80H COMNWRT A,#A DATAWRT DELAY A,#L DATAWRT DELAY A,#L DATAWRT DELAY ;

; Clear LCD

; cursor position ; print character A on lcd

; ; print character L on lcd

20

MOV ACALL ACALL MOV ACALL ACALL SJMP COMNWRT: MOV CLR NOP CLR SETB NOP CLR NOP RET DATAWRT:

A,#A DATAWRT DELAY A,#H DATAWRT DELAY $

P1,A P3.2 ;RS P3.3 ;READ/WRITE P3.4 ; ENABLE P3.4

MOV P1,A SETB P3.2 ;RS NOP CLR P3.3 ;READ,WRITE SETB P3.4 ; ENABLE NOP CLR P3.4 NOP RET

21

LAB # 7
Serial Communication Objective: How to send data using UART (serial communication).
DESCRIPTION: There is an examples of serial communication to computer. This is full duplex serial communication. Microcontroller send data to computer and display this data on monitor via hyper terminal software, when computer send data to microcontroller it display this data on LCD which is connected to microcontroller . You just type this example in Pinnacle52 software and name the file with extension asm. This file is called assembly source file. Now you will to need executable file to run this program into microcontroller, so press ctrl+f2 keys for making executable file. Now this file should burned to microcontroller by using programmer device. After programmed microcontroller you should be place on microcontroller trainer to verify the performance. Now you can see your program output on LCD connecting with microcontroller & HyperTerminal.

Apparatus / Component.
Microcontroller AT89S51, IPC MC- 8605. ; Receive & Transmit data to & from Pc Comm. port ; SEND THIS DATA ON LCD AND P2

ORG MOV ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL ACALL MOV ACALL

00 R7,#07 ;Pointer address DELAY A,#38H ; 2 line matrix LCD COMNWRT DELAY A,#0EH COMNWRT DELAY A,#01H ; Clear LCD COMNWRT DELAY A,#06H COMNWRT DELAY A,#80H COMNWRT 22

AGAIN: AJMP MAIN1

COMNWRT: MOV CLR NOP CLR SETB NOP CLR NOP RET DATAWRT: MOV SETB NOP CLR SETB NOP CLR NOP DJNZ MOV MOV ACALL GORET: RET DELAY: MOV R3,#0FH HERE2: MOV R4,#0FH HERE: DJNZ R4,HERE DJNZ R3,HERE2 RET ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MAIN1: MOV MOV MOV MOV SETB ACALL SJMP P2,#0FFH TMOD,#20H ; Timer 1 mode 2 TH1,#0FAH ; 4800 BAUDRATE SCON,#50H ; Receive & Transmit both enable. TR1 ; start timer1 TX MAIN P1,A P3.2 ;RS P3.3 ;READ,WRITE P3.4 ; ENABLE P3.4 R7,GORET R7,#07 A,#80H COMNWRT P1,A P3.2 ;RS P3.3 ;READ/WRITE P3.4 ; ENABLE P3.4

;*************************************** 23

TX: MOV A,#A MOV SBUF,A HER: JNB TI,HER CLR TI MOV A,#L MOV SBUF,A HER1: JNB TI,HER1 CLR TI RET ;*************************************** ;+++++++++++++++++++++++++++++++++++ MAIN: JNB RI,MAIN MOV A,SBUF MOV P2,A ACALL DATAWRT CLR RI ACALL TX SJMP MAIN ;+++++++++++++++++++++++++++++++++++ END

24

LAB #8
7 SEGMENT DRIVE Objective: How to drive multiplexed 7 segment display with microcontroller
DESCRIPTION: There is an examples of multiplexed 7 segment display interfacing. In this experiment there is four common anode 7 segment display connecting to port zero and their common points are connected to P2.0 , P2.1 ,P2.2 ,P2.3. You just type this example in Pinnacle52 software and name the file with extension asm (7seg.asm). This file is called assembly source file. Now you will to need executable file to run this program into microcontroller so press ctrl+f2 keys for making executable file. Now this file should burned to microcontroller by using programmer device. After programmed microcontroller you should be place microcontroller on microcontroller trainer to verify the performance. Now you can see your program output on 7segment display connected with microcontroller Trainer board.

Apparatus / Component.
Microcontroller AT89C51, IPC MC- 8605 . ;multiplexed seven segment drive SCAN: ACALL DIGIT1 ; digit 1 subroutine ACALL DIGIT2 ; digit 2 subroutine ACALL DIGIT3 ; digit 3 subroutine ACALL DIGIT4 ; digit 4 subroutine SJMP SCAN DIGIT1: MOV CLR ACALL SETB NOP NOP NOP RET DIGIT2: MOV CLR ACALL SETB NOP NOP NOP

P0,#F9H ; Display 1 on digit one P2.0 ON P2.0

P0,#A4H ; Display 2 on digit two P2.1 ON P2.1

25

RET DIGIT3: MOV CLR ACALL SETB NOP NOP RET

P0, #B0H; Display 3 on digit three P2.2 ON P2.2

DIGIT4: MOV CLR ACALL SETB NOP NOP NOP RET

P0,#99H ; Display 4 on digit four P2.3 ON P2.3

ON: MOV AGA: MOV DJNZ DJNZ RET R1,#0FH R2,#050H R2,$ R1,AGA

26

LAB #9
KEYPAD INTERFACE
Objective: How to interface matrix Keypad DESCRIPTION: There is an example of interfacing a matrix key pad to 8051 microcontroller. You just type this example in Pinnacle52 software and name the file with extension asm (keypad.asm)... This file is called assembly source file. Now you will need executable file to run this program, so press ctrl+f2 keys for making executable file. Now this file should copied into microcontroller by using programmer device. After programmed microcontroller you should be place this on microcontroller trainer to verify the performance. Now you can see your program output on 7 segment connecting with microcontroller.

Apparatus / Component.
Microcontroller AT89C51 , IPC MC- 8605

; c1=4wire c2=5 c3=2 r1=3 R2=6WIRE R3=8 ; R4=11 ;********************************************************************** ; C1=P1.0 C2=P1.1 C3=P1.2****** R1=P1.3*** R2=P1.4 ** R3=P1.5 * ; R4=P1.6 * ;**********************************************************************

;********************************************** ; ROUTINE FOR KEY IDENTIFICATION |* ; |* ;********************************************** 30H MOV KEYSCAN: CLR JNB J4: JNB J7: JNB J*: JNB SETB ORG

P2,#00H P1.0 P1.3,ONE ; 1 P1.4,FOUR ; 4 P1.5,SEVEN; 7 P1.6,JSTAR ; "*" P1.0

;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| CLR P1.1 JNB P1.3,TWO ; 2 J5: JNB P1.4,FIVE ; 5 J8: JNB P1.5,EIGHT; 8 J0: JNB P1.6,ZERO ; 0 SETB P1.1 ;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| CLR P1.2

27

J6: J9: J#:

JNB JNB JNB JNB SETB AJMP SJMP

P1.3,THREE; 3 P1.4,SIX ; 6 P1.5,NINE; 9 P1.6,HASH ; # P1.2 KEYSCAN STAR

JSTAR:

;|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||| ONE: MOV P0,#F9H ACALL DEL JNB P1.3,$ AJMP J4 ;????????????????????????????????????????????????????????????????????? TWO: MOV P0,#A4H ACALL DEL JNB P1.3,$ AJMP J5 ????????????????????????????????????????????????????????????????????? ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ THREE: MOV P0,#B0H ACALL DEL JNB P1.3,$ AJMP J6 ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ FOUR: MOV P0,#99H ACALL DEL JNB P1.4,$ AJMP J7 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FIVE: MOV P0,#92H ACALL DEL JNB P1.4,$ AJMP J8 ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ SIX: MOV P0,#82H ACALL DEL JNB P1.4,$ AJMP J9 ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

;)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) SEVEN: MOV P0,#F8H ACALL DEL JNB P1.5,$ AJMP J* ;`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EIGHT: MOV P0,#80H

28

ACALL JNB

DEL P1.5,$

AJMP J0 ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NINE: MOV P0,#98H ACALL DEL JNB P1.5,$ AJMP J# ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ZERO: MOV ACALL JNB AJMP P0,#C0H DEL P1.6,$ KEYSCAN

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! STAR: MOV P0,#89H ACALL DEL JNB P1.6,$ AJMP KEYSCAN ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ;====================================================================== HASH: MOV P0,#8CH ACALL DEL JNB P1.6,$ AJMP KEYSCAN ;=========================================================== DEL: LOOP: MOV MOV DJNZ DJNZ RET END R1,#FFH R2,#FFH R2,$ R1,LOOP

29

LAB 10
TRAFFIC LIGHT SIGNAL
Design a traffic light signal system using AT89C51 microcontroller. REQUIRMENT: following Program a microcontroller such that it can control traffic light in the sequence. Red light should be on for 8 seconds Red & Yellow light should be on for 2 seconds Green light should be on for 8 seconds Yellow light should be on for 2 seconds The loop should continue

Apparatus / Component.
Microcontroller AT89C51,Microcontroller programmer and microcontroller trainer.
MOV CLR ACALL ACALL ACALL CLR ACALL SETB SETB CLR ACALL ACALL ACALL ACALL SETB CLR ACALL SETB SJMP P2,#0FFH P2.0 DELAY DELAY DELAY P2.1 DELAY P2.0 P2.1 P2.2 DELAY DELAY DELAY DELAY P2.2 P2.1 DELAY P2.1 LOOP ; All bits of p2 are high ; red LED is on ; delay for 2 Second ; delay for 2 Second ; delay for 2 Second ; Yellow LED is on ; delay for 2 Second ;Red LED is off ; yellow LED is off ;Green LED is on ; delay for 2 Second ; delay for 2 Second ; delay for 2 Second ; delay for 2 Second ;Green LED is off ;Yellow LED is on ; delay for 2 Second ; yellow LED is off ;repeat same sequence again

DELAY: MOV REE: MOV AG: MOV R2,#0FFH DJNZ R2,$ DJNZ R1,AG DJNZ R0,REE RET END R1,#0FFH R0,#0EH

; 2 Second delay routine

30

You might also like