Microcontroller Based System Design

CHANDAN BERA 4th Year, ECE ROLL NO-09170003058



75C, Park Street, 4th Floor, Kolkata-700 016 Phone: 033-40648262

Trainer of ‘Micropro Training Center’.Acknowledgement First of all. without whom it would have been impossible to complete our project. Mangalik Pal. we express our gratitude to our teacher and project guide Mr. And secondly. . I would like to thank our group members and friends who supported each other to make the project a success.


Generally it starts counting from a predefined value called SET VALUE. For an example a semi-automated car parking lot gate use Down Counter for counting the number of cars enter or exit. is known as a Down Counter. under the control of a down selector input. . And when enter cars reach the limit of capacity of parking place. Unlike a counter. and then starts down counting until it goes to the zero. that can change state in only one direction. The down counter is used in various places of our regular life. often in relationship to a clock signal. means maximum counting and end the process.OVERVIEW A counter is a device which stores(sometimes displays) the number of times a particular event or process has occurred. the entrance gate is lock showing ‘NO VACANT PLACE HERE’.

The AT89C51 provides the following standard features:  Compatible with MCS-51 products  4KB in-system reprogrammable Flash Memory  Full static operation: 0HZ to 24MHZ  Three level program Memory Lock  128×8 bit internal RAM  32 programmable I/O lines  Two 16-bit Timer/Counter  Six Interrupts sources  Programmable serial channel  Low power idle and power down modes. while other allowing the RAM. The on chip flash memory allows the program memory to be programmed in system or by a conventional non-volatile memory programmer. .Why we Use AT89C51? The AT89C51 is a low power. The device is manufacture using Atmel’s high density non-volatile memory technology and compatible with the industry standard MCS-51 instruction-set and pin-out. In addition the AT89C51 is designed with static logic for operation Down-to-Zero frequency and supports and two software selectable power saving modes. by combining a versatile 8-bit CPU with flash on a monolithic chip. The Atmel AT89C51 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications. high performance CMOS 8-bit microcomputer with 4 bytes of Flash Erasable & Progra-mmable Read Only Memory (EPROM). Timer/Counters. The Idle mode stops the CPU.

RxD.Architecture:           8051µc is a 8bit microcontroller introduced by Intel Corporation in 1981 which comes in 40 pin dual inline package (DIP). It has two 16bit timers namely Timer 0 and Timer 1 which can be used either as timer for internal operation or as counter for external operation.0592MHz (~12MHz). It has 4KB of inbuilt ROM i. . They are External Interrupt 0. The programming mode of this microcontroller consists of general purpose registers (GPRs). Special Purpose Registers (SPRs) and Special Function Registers (SFRs). It has five interrupt sources. The instruction set of 8051 µc consists of more number of bit manipulations or Boolean variable manipulation group of instructions. It has full duplex serial I/O port having two pins namely TxD. port 1. There are 4 parallel 8bit ports namely port 0. All of them are maskable as well as vector interrupts. Timer Interrupt 1. It has 128bytes of inbuilt RAM space and if required external memory of 64KB can be interfaced to the microcontroller. External Interrupt 1. It has an on chip crystal oscillator with crystal frequency 11. Timer Interrupt 0.e. and Serial Port Interrupt. on chip program space. The instructions are very much useful to manipulate SFR bits and also port pins. port 2 and port 3 which are addressable as well as programmable.

It provides 4 special purpose registers – 16bit Program Counter (PC). Bank 2. IP. They are TMOD. o 00H – 1FH : These 32bytes are arranged as 4 register banks namely Bank 0. and PCON. o 30H – 7FH : These 80 bytes are available as scratch-pad RAM bytes . TCON. SBUF. 8bit Stack Pointer (SP). 16bit Data Pointer and 8bit Program Status Word (PSW). The 128bytes on chip RAM of 8051 µc is divided into three portions as given below.Register and Internal RAM organization:     8051 µc provides two 8bit general purpose registers – A (Accumulator) and B. It also provides few Special Function Registers. Bank 1. SCON. Bank 3 where each bank consists of 8 registers namely R0 through R7 o 20H – 2FH : These 16bytes (128bits) are made available as bit-addressable bytes. IE.

3 P3. port 2 and port 3.6 Special Function RxD (Serial Input pin) TxD (Serial Output pin) (Interrupt 0 input pin) (Interrupt 1 input pin) (Timer 0 input if timer is counter) (Timer 1 input if timer is counter) (RAM write control signal output) . It has active high reset input pin. port 1. XTAL2.1 P3. All ports are programmable. o Port 3: Each and every pin in this port offer some separate functionality irrespective of level at input pin Pin P3. They are as follows.0 P3. As such the controller is said to be reset upon application of active high pulse.5 P3. o Port 0 and Port 2: If input pin is grounded then port 0 acts as lower order 8bit address data bus whereas port 2 acts as higher order 8 bit address bus.4 P3. I/O port pins A total number of 32 I/O pins are provided as port pins divided into 4 ports – port 0.Pin diagram: Power Supply pins 8051 µc works with +5V DC source applied to Vcc and 0V to Gnd input pin. All the ports act as simple input/output ports. It has an on chip crystal clock generator. All ports are both byte and bit addressable. All the ports except port 1 offer alternate functions.2 P3. As such it must be supported externally by connecting a crystal across crystal input XTAL1.

) ♦ The appropriate status bits in the PSW are set when specific conditions are met. overflow etc…) This group of operators performs arithmetic operations. binary coded decimal. etc.. signed/unsigned binary.Instruction-Set of 8051: The instruction-set of 8051 microcontroller are divided in five major groups Arithmetic Operations  Logic Operations  Data Transfer Operations  Boolean Algebraic Operations  Program and Machine Control Operations Arithmetic Operations: ♦ With arithmetic instructions. in the PSW register. ASCII. such as Carry Flag (CY). the C8051 CPU have no special knowledge of the data format (e. Overflow Flag (OV) etc. Arithmetic operations affect the flags. .g. which allows the user software to manage the different data formats (carry.

NOT (compliment). and swap nibbles in accumulator. OR. Data can also be transferred between the internal and external RAM by using indirect addressing. and NOT) on data bytes on a bit-by-bit basis Logical instructions perform standard Boolean operations such as AND. . rotate accumulator left and right. Other logical operations are clear accumulator. OR.Logic Operations: ♦ Logical instructions perform Boolean operations (AND. XOR. Data Transfer Operations: ♦ Data transfer instructions can be used to transfer data between an internal RAM location and an SFR location without going through the accumulator ♦ It is also possible to transfer data between the internal and external RAM by using indirect addressing Data transfer instructions are used to transfer data between an internal RAM location and SFR location without going through the accumulator. XOR.

or and complement instructions ♦ Also included are bit–level moves or conditional jump instructions The Boolean Variable operations include set. Also included are bit–level moves or conditional jump instructions. All bit accesses use direct addressing Program and Machine Control Operations: ♦ Program branching instructions are used to control the flow of program execution Program branching instructions are used to control the flow of actions in a program. . Some instructions provide decision making capabilities and transfer control to other parts of the program e.g. clear. and. conditional and unconditional branches. as well as and.Boolean Algebraic Operations: ♦ The C8051 processor can perform single bit operations ♦ The operations include set. clear. or and complement instructions.

Linker : The 8051 Linker is an application. Resistor.asm) Language file. Stack Pointer (SP). To read a HEX code the command is: RHC To load the data into the registers: MI R0=#DATA . which generate an object (. PSW. Linker & Simulator: Assembler: The 8051 Assembler is an application. which generate a HEX file(. Simulator: The 8051 Simulator contain itself resistors. DPTR etc.obj) file of an assembly (. It enables us to read the HEX code of a file. General Purpose Resistors. PSW etc.hex) of an object file (. positions of their in Stack and Program Counter. The output file format is as Intel Hex.obj). It also enables to load data to RAM or Registers. ports.The 8051 Assembler. run the program and after that shows the content of RAM. RAM memory etc. It also contains Program Counter (PC).

Step 10: Delay: Enter a Delay program as desire. either go to step 5(i). Decrement Set-Point. Down Counter and Set-Point value. Step 07: Display: (i) Check whether SW1 is pressed or not. Either continues. Step 02: Set the Microcontroller as ‘counter mode’. Step 09: Reset: Check if both SW2 and SW3 are pressed or not. either go to step 7(iii). The maximum counting value is ZERO (0). If pressed go to step 7(ii). If pressed.3 pin for output by clear it. If pressed. 2 pin of PORT-1. If both pressed reset the counter to its Set-Point.Algorithm of Down Counter: Step 01: Define the BIT and BYTE memory location for all Switches. Step 04: Ready Switch: Ready all switches to connect with 0. (ii) Convert the set-point from binary to decimal and Store it to RAM memory. Step 03: Set the P1. Step 05: Fix-Set-Point: (i)Check if SW1 is pressed or not. Step 11: Go to Step 4. If pressed. . (iii)Convert the Down-counter value from binary to Decimal and store it to RAM memory. go to Next step either repeat this step. Increment Set-Point. Step 08: Relay: Check the Down-Counter value. 1. Step 06: Down Counting: Starts Down counting from the SetPoint. (iii) Check if SW3 is pressed or not. If it is zero (0) Turn-on the Relay either continues. (ii) Check if SW2 is pressed or not. either go to Next step.

10. To store a data in resistors type MI Resistor name=#Data.Steps to Develop a Program: At first we should store the 8051 simulator files on a directory in the computer in any drive. Type ‘RHC’ and hit Enter. There will be change in Resistors. Type ‘EDIT’ and hit Enter. Open the command prompt window from Start>all program>accessories>command prompt 02. shows the errors if any and make an object file. 14.EXE) and hit Enter. RAM etc. Then enter input file name to read the HEX code of that file. By this method an 8051 program is developed and after running the program what is the content of resistors. 07.OBJ. Open the assembler by type ‘X8051. Give ‘m’ (Microtech) in the option and hit Enter. Write the assembly language program and save it as ‘. multiple input. . It assembles the input file. and output and library name if you want.EXE‘and hit Enter. Then give the output file name if you want and hit Enter. 09. it shows that. RAM etc. It shows the simulator. Go to that directory where the simulator files are stored. Type ‘L8051. Give (one Enter + one Space) or (one Enter + one Tab) 05. Give the input file name with extension and hit Enter. using change directory command. Hit Enter for several times. 11.EXE’ (or LINK4. 12. in every Enter. Type ‘S8051.ASM’ extension. It generates a HEX file of the input object file. 01. 08. 13.EXE’ and hit Enter. 04. 06. Go to File>Exit. 03. Offset for code. Give the input file name as NAME.

************************************************/ .Program of Down-Counter: .***********************************************/ .CHIP 8051 .SYMBOLS ORG 00H LJMP START .**************BIT MEMORY LOCATION ************/ SW1: EQU 7FH SW2: EQU 7EH SW3: EQU 7DH .************************************************/ .*************BYTE MEMORY LOCATION *************/ DOWN_COUNTER: SET_POINT: EQU 30H EQU 31H .************************************************/ .#05H CLR P1.************************************************/ ORG 100H START: MOV TMOD.3 LOOP1: NOP LCALL READ_SWITCH LCALL FIX_SET_POINT LCALL CAL_DOWN_COUNTER LCALL DISPLAY_DRIVE LCALL RELAY_DRIVE LCALL RESET_COUNTER LCALL DELAY SJMP LOOP1 .************************************************/ .************************************************/ .

DECREMENT CLR C MOV A. QUIT1 JNB SW2.0 CPL C MOV SW1..************************************************/ FIX_SET_POINT: JNB SW1. P1. SET POINT SHOULD BE >=00 DEC JZ QUIT1 DEC SET_POINT QUIT1: RET . P1.2 MOV C.SET_POINT SUBB A.QUIT1 MOV A.2 CPL C MOV SW3. P1.C RET .C SETB P1.#0C8H .1 MOV C.C SETB P1. SET POINT SHOULD BE <=200 DEC JNC QUIT1 INC SET_POINT SJMP QUIT1 DECREMENT: JNB SW3.1 CPL C MOV SW2.************************************************/ .SET_POINT .************************************************/ READ_SWITCH: SETB P1.************************************************/ .0 MOV C.

63H MOV P0.************************************************/ BIN2DEC: MOV A.SET_POINT SUBB A.************************************************/ . 63H UNIT ORL A. 62H TEN SWAP A .************************************************/ DISPLAY_DRIVE: JB SW1.B .63H MOV P0.A .61H QUIT2: RET ..A RET .DISPLAY_SP MOV 60H.60H MOV B. 60H INPUT BIN DATA LCALL BIN2DEC . 63H UNIT ORL A.A MOV P2.A MOV P2. 61H HUND MOV A.DOWN_COUNTER .************************************************/ . 61H HUND MOV A. 60H INPUT BIN DATA LCALL BIN2DEC . 62H TEN SWAP A .TL0 MOV DOWN_COUNTER.62H .SET_POINT .62H .61H SJMP QUIT2 DISPLAY_SP: MOV 60H.#64H DIV AB MOV 61H. HUND MOV A.************************************************/ CAL_DOWN_COUNTER: CLR C MOV A.

************************************************/ RELAY_DRIVE: JNB TCON.A .QUIT5 JNB SW2.QUIT5 JNB SW3.4.L1 RET . UNIT QUIT3: RET .QUIT5 MOV TL0.************************************************/ .************************************************/ .#00H SETB TCON. TEN MOV 63H.************************************************/ DELAY: MOV R7.B .#00H MOV TH0.4 QUIT5: RET .************************************************/ RESET_COUNTER: JB SW1.QUIT4 MOV A.L2 DJNZ R7.************************************************/ .3 CLR TCON.DOWN_COUNTER JZ RELAY_ON CLR P1.MOV B.3 SJMP QUIT4 RELAY_ON: SETB P1.#0AH DIV AB MOV 62H.4 QUIT4: RET .#0FFH L2: NOP DJNZ R6.#0FFH L1: MOV R6.****************END OF THE PROGRAM*************/ .

The equipment has three ‘seven segment display’ and three push-to-on switches (SW1-SW3) as user interface. If no switches are pressed the running counter value is displayed. To increment set-point press SW2. Lower limit for set-point is 0. Counting also stop. Relay will be ON. 6.Block Diagram of Down-Counter: Functional Description of Down-Counter: 1. while pressing down SW1. SW3 are pressed. while pressing down SW1. 7. 2. If counter value is zero. indicating end of batch. . If both SW2. To decrement set-point press SW3. Upper limit for set-point is 200 5. 4. 3. If SW1 is pressed set-point for batch count will be displayed. counter starts down counting from set-point again (Reset).

Circuit Diagram: .


we use the following components in our circuit – Counting SectionInput SectionOutput SectionPower SectionDiscrete componentsIC AT89C51-1 Piece Push-Button-Switch-3 piece Seven-Segment display-3 piece Light emitting diode-1 piece IC 7805 (5V Regulator)-1 piece IC 7812 (12V Regulator)-1 piece Capacitors.4 pieces 1000µF.3 piece Crstal-10MHZ-1 piece Transistor-2N2222A-1 piece Relay (12 V.1 piece 2.10µF-3 piece 33Pf.1 piece IC 7447(ADC) .2 piece 15kΩ.1 piece 470Ω-21 pieces DiodeIN4007-5 piece Pull-Up Resistor.10kΩ.1 µF.2 pieces Resistors.Use of Equipment: While making our project.2kΩ. 1 C/O) 1 piece 2 pin Relimate -4 piece 5 pin relimate-4 piece 1 piece Other Components- ConnectorsHeat-Sink for IC7805- .2 pieces 0.

which we deigned. is working properly with a negligible error.Conclusion: Performance of the circuitThe circuit of our project. We can further improve our circuit by changing the program and using some extra components. The error is mainly due to loose contacts of the components used. . Scope of Further Improvement: This circuit is designed to count from 0 to 200 or vice versa. Then the circuit starts running correctly. But we correct these later.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.