You are on page 1of 24

2011

Microcontroller Based System Design

CHANDAN BERA 4th Year, ECE ROLL NO-09170003058

CERTIFICATE
TO WHOM IT MAY CONCERN
THIS IS TO CERTIFY THAT, CHANDAN BERA, STUDENT OF IMPS COLLEGE OF ENGINEERING & TECHNOLOGY IN ELECTRONICS & COMMUNICATION ENGINEERING COMPLETED AN ONE MONTH INDUSTRIAL TRAINING ON MICROCONTROLLER BASED SYSTEM DESIGN FROM OUR INSTITUTE. I WISH HIM ALL SUCCESS IN LIFE.

______________________________ AUTHORISED SIGNATURE WITH SEAL (MICROPRO TRAINING CENTER)

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

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

PREFACE

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

Why we Use AT89C51?


The AT89C51 is a low power, high performance CMOS 8-bit microcomputer with 4 bytes of Flash Erasable & Progra-mmable Read Only Memory (EPROM). The device is manufacture using Atmels high density non-volatile memory technology and compatible with the industry standard MCS-51 instruction-set and pin-out. The on chip flash memory allows the program memory to be programmed in system or by a conventional non-volatile memory programmer, 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. 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 1288 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. In addition the AT89C51 is designed with static logic for operation Down-to-Zero frequency and supports and two software selectable power saving modes. The Idle mode stops the CPU, while other allowing the RAM, Timer/Counters.

Architecture:

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

Register and Internal RAM organization:

8051 c provides two 8bit general purpose registers A (Accumulator) and B. It provides 4 special purpose registers 16bit Program Counter (PC), 8bit Stack Pointer (SP), 16bit Data Pointer and 8bit Program Status Word (PSW). It also provides few Special Function Registers. They are TMOD, TCON, IE, IP, SBUF, SCON, and PCON. The 128bytes on chip RAM of 8051 c is divided into three portions as given below. o 00H 1FH : These 32bytes are arranged as 4 register banks namely Bank 0, Bank 1, Bank 2, 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. o 30H 7FH : These 80 bytes are available as scratch-pad RAM bytes

Pin diagram:

Power Supply pins 8051 c works with +5V DC source applied to Vcc and 0V to Gnd input pin. It has an on chip crystal clock generator. As such it must be supported externally by connecting a crystal across crystal input XTAL1, XTAL2. It has active high reset input pin. As such the controller is said to be reset upon application of active high pulse. I/O port pins A total number of 32 I/O pins are provided as port pins divided into 4 ports port 0, port 1, port 2 and port 3. All ports are both byte and bit addressable. All ports are programmable. All the ports act as simple input/output ports. All the ports except port 1 offer alternate functions. They are as follows. 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. o Port 3: Each and every pin in this port offer some separate functionality irrespective of level at input pin Pin P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.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)

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, the C8051 CPU have no special knowledge of the data format (e.g. signed/unsigned binary, binary coded decimal, ASCII, etc.) The appropriate status bits in the PSW are set when specific conditions are met, which allows the user software to manage the different data formats (carry, overflow etc)

This group of operators performs arithmetic operations. Arithmetic operations affect the flags, such as Carry Flag (CY), Overflow Flag (OV) etc., in the PSW register.

Logic Operations:
Logical instructions perform Boolean operations (AND, OR, XOR, and NOT) on data bytes on a bit-by-bit basis

Logical instructions perform standard Boolean operations such as AND, OR, XOR, NOT (compliment). Other logical operations are clear accumulator, rotate accumulator left and right, and swap nibbles in accumulator.

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. Data can also be transferred between the internal and external RAM by using indirect addressing.

Boolean Algebraic Operations:


The C8051 processor can perform single bit operations The operations include set, clear, and, or and complement instructions Also included are bitlevel moves or conditional jump instructions

The Boolean Variable operations include set, clear, as well as and, or and complement instructions. Also included are bitlevel 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. conditional and unconditional branches.

The 8051 Assembler, Linker & Simulator:


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

Algorithm of Down Counter:


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

Steps to Develop a Program:


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

Program of Down-Counter:
;************************************************/ ;*************BYTE MEMORY LOCATION *************/ DOWN_COUNTER: SET_POINT: EQU 30H EQU 31H

;************************************************/ ;**************BIT MEMORY LOCATION ************/ SW1: EQU 7FH SW2: EQU 7EH SW3: EQU 7DH ;************************************************/ ;***********************************************/ .CHIP 8051 .SYMBOLS ORG 00H LJMP START ;************************************************/ ;************************************************/ ORG 100H START: MOV TMOD,#05H CLR P1.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 ;************************************************/

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

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

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

Block Diagram of Down-Counter:

Functional Description of Down-Counter:


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

Circuit Diagram:

Use of Equipment:
While making our project, 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- 10F-3 piece 33Pf- 2 pieces 0.1 F- 4 pieces 1000F- 2 pieces Resistors- 10k- 2 piece 15k- 1 piece 2.2k- 1 piece 470-21 pieces DiodeIN4007-5 piece Pull-Up Resistor- 1 piece IC 7447(ADC) - 3 piece Crstal-10MHZ-1 piece Transistor-2N2222A-1 piece Relay (12 V, 1 C/O) 1 piece 2 pin Relimate -4 piece 5 pin relimate-4 piece 1 piece

Other Components-

ConnectorsHeat-Sink for IC7805-

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

You might also like