You are on page 1of 34

School of Computing, Engineering & Physical Sciences

Digital Electronics Assignment Solution

Develop of a specification and software for a microcontroller circuit meets simple processor based system

Lecturer Name

Name Student Number

OVERVIEW OF THE REPORT The aim of the report is to develop and making understanding in details of hardware specifications and writing a code to perform a task and use of simulator to debug the program or code which meets the specification for a simple processor based system. In the analysis the given design is for 8051 Microcontroller based system which is capable of monitoring the concentration of hazardous gases within a manufacturing environment. The 8051 Microcontroller based system supervise the gas concentration and gives the result in two ways; as a character string on a PC display and by lighting a number of LEDs. The system inputs are Gas concentration input four digital lines giving a range of 0-15 Active RS232 input single digital line where low toggles RS232 output on/off. The aims of this report are to: Recognition of the hardware specification. Write a program to perform given task. Translate the specification of an interface. Demonstrate basic competence in using embedded system development systems. Use a simulator to debug the program. Test the system against the specifications.

THEORY OF MICROCONTROLLER A single chip that contains the processor (the CPU), non-volatile memory for the program (ROM or flash), volatile memory for input and output (RAM), a clock and an I/O control unit. Also called a "computer on a chip," billions of microcontroller units (MCUs) are embedded each year in a myriad of products from toys to appliances to automobiles. Microcontrollers come in all sizes and architectures, with the smaller, commodity chips costing as little as 50 cents in quantities of 10,000. The most commonly used set of microcontrollers belong to 8051 Family. The below given diagram (Block diagram) will show you how the things work in microcontroller and what are the important parts connected to it.

The 8051 architecture provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a single package

8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8bit microcontroller 8-bit data bus It can access 8 bits of data in one operation

16-bit address bus It can access 216 memory locations 64 KB (65536 locations) each of RAM and ROM On-chip RAM 128 bytes (data memory) On-chip ROM 4 Kbyte (program memory) Four byte bi-directional input/output port UART (serial port) Two 16-bit Counter/timers Two-level interrupt priority Power saving mode (on some derivatives)

DETAILED SPECIFICATION FOR BOARD


CIRCUIT DIAGRAM

ICs Used
Microcontroller: 8051 (AT89C4051) Serial Controller: MAX 232 Power Regulator: IC 7805

Configuration of Pins
VccPin 40 o Vcc provides supply voltage to the chip. o The voltage source is +5V. GNDPin 20Ground XTAL1 and XTAL2Pins 19, 18 RSTPin 9Reset o It is an input pin and is active high (normally low.

The high pulse must be high at least 2 machine cycles. o It is a power-on reset. Upon applying a high pulse to RST, the microcontroller will reset and all values in registers will be lost. Reset values of some 8051 registers /EAPin 31External access o There is no on-chip ROM in 8031 and 8032. o The /EA pin is connected to GND to indicate the code is stored externally. o /PSEN ALE are used for external ROM. o For 8051, /EA pin is connected to Vcc. o / means active low. /PSENPin 29Program store enable o This is an output pin and is connected to the OE pin of the ROM. ALEPin 30Address latch enable o It is an output pin and is active high. o 8051 port 0 provides both address and data. o The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 latch. I/O port Pins o The four ports P0, P1, P2, and P3. o Each port uses 8 pins. o All I/O pins are bi-directional. The 8051 has four I/O ports o Port 0 pins 32-39P0P0.0P0.7 o Port 1pins 1-8 P1P1.0P1.7 o Port 2pins 21-28P2P2.0P2.7 o Port 3pins 10-17P3P3.0P3.7 o Each port has 8 pins. Named P0.X X=0,1,...,7, P1.X, P2.X, P3.X ExP0.0 is the bit 0LSBof P0 ExP0.7 is the bit 7MSBof P0 These 8 bits form a byte. Each port can be used as input or output (bi-direction).

PSEUDO CODE
/* pseudo code for the program */ delay { //delay for 0.5 secs Timeout = 4000; while(Timeout > 0 ) Timeout -- ; } main() { init serial params; FlowRate = P3.5 @ P3.4 @ P3.3 @ P3.2 // read 4 bit data SerialEnable = P3.7 if(FlowRate == 0 ) { if(enabled(SerialEnable)) SerialWrite ("0 ppm\n"); GreenLedBit = 1; delay(); } else if(FlowRate == 1) { if(enabled(SerialEnable)) SerialWrite ("1 ppm\n"); GreenLedBit = 1; delay(); } else if(FlowRate == 2 ) { GreenLedBit = 1; if(enabled(SerialEnable)) SerialWrite ("2 ppm\n"); delay(); } else if(FlowRate == 3 ) { if(enabled(SerialEnable)) SerialWrite ("3 ppm\n");

GreenLedBit = 1; delay(); } else if(FlowRate == 4 ) { if(enabled(SerialEnable)) SerialWrite ("4 ppm\n"); YellowLedBit = 1; delay(); } else if(FlowRate == 5 ) { if(enabled(SerialEnable)) SerialWrite ("5 ppm\n"); YellowLedBit = 1; delay(); } else if(FlowRate == 6 ) { if(enabled(SerialEnable)) SerialWrite ("6 ppm\n"); YellowLedBit = 1; delay(); } else if(FlowRate == 7 ) { if(enabled(SerialEnable)) SerialWrite ("7 ppm\n"); YellowLedBit = 1; delay(); } else if(FlowRate == 8 ) { if(enabled(SerialEnable)) SerialWrite ("8 ppm\n"); YellowLedBit ^= 1; delay(); } else if(FlowRate == 9 ) { if(enabled(SerialEnable)) SerialWrite ("9 ppm\n"); YellowLedBit ^= 1; delay(); } else if(FlowRate == 10 ) { if(enabled(SerialEnable)) SerialWrite ("10 ppm\n"); YellowLedBit ^= 1; delay(); } else if(FlowRate == 11 )

{ if(enabled(SerialEnable)) SerialWrite ("11 ppm\n"); YellowLedBit ^= 1; delay(); } else if(FlowRate == 12 ) { if(enabled(SerialEnable)) SerialWrite ("12 ppm\n"); RedLedBit ^= 1; delay(); } else if(FlowRate == 13 ) { if(enabled(SerialEnable)) SerialWrite ("13 ppm\n"); RedLedBit ^= 1; delay(); } else if(FlowRate == 14 ) { if(enabled(SerialEnable)) SerialWrite ("14 ppm\n"); RedLedBit = 1; delay(); RedLedBit = 0; } else if(FlowRate == 15 ) { if(enabled(SerialEnable)) SerialWrite ("15 ppm\n"); RedLedBit = 1; delay(); RedLedBit = 0; } delay(); }

ASSEMBLY PROGRAM
ORG 0000H LJMP 093AH ; set up serial interface MOV SCON,#50H ORL 89H,#20H MOV TH1,#0EBH SETB 8EH SETB SBUF CLR A MOV 90H,A ; getting the input data MOV A,0B0H RRC A MOV 09H,C MOV A,0B0H MOV C,0E1H MOV 0AH,C MOV A,0B0H MOV C,0E2H MOV 0BH,C MOV A,0B0H MOV C,0E3H MOV 0CH,C MOV A,0B0H RLC A MOV 0DH,C JNB 0DH,04H ; setting white led if serial input is enabled SETB 93H SJMP 02H CLR 93H JB 0BH,04H ; check if flow rate = 0 MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H

MOV A,R6 ANL A,R7 JZ 0FH JNB 0DH,46H MOV R3,#0FFH MOV R2,#08H MOV R1,#64H LCALL 04CBH LJMP 0127H JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 0EH JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#6BH LCALL 04CBH SJMP 76H JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H

; sending serial output ; check if flow rate = 1

; sending serial output ; check if flow rate = 2

MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 0EH JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#72H LCALL 04CBH SJMP 3AH JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 15H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#79H LCALL 04CBH SETB 90H CLR 91H CLR 92H LJMP 03DCH JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H

; sending serial output ; check if flow rate = 3

; sending serial output ; enable green led ; off red ; off yellow ; check if flow rate = 4

MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 15H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#80H LCALL 04CBH CLR 90H CLR 91H SETB 92H LJMP 03DCH JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 15H JNB 0DH,09H

; sending serial output ; off red ; enable green led ; check if flow rate = 5

MOV R3,#0FFH MOV R2,#08H MOV R1,#87H LCALL 04CBH CLR 90H CLR 91H SETB 92H LJMP 03DCH JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 15H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#8EH LCALL 04CBH CLR 90H CLR 91H SETB 92H LJMP 03DCH JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H

; sending serial output ; off red ; enable green led ; check if flow rate = 6

; sending serial output ; off red ; enable green led ; check if flow rate = 7

SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 15H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#95H LCALL 04CBH CLR 90H CLR 91H SETB 92H LJMP 03DCH JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 18H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#9CH LCALL 04CBH CLR 90H CLR 91H MOV C,92H CPL C

; sending serial output ; off red ; enable green led ; check if flow rate = 8

; sending serial output ; off red

MOV 92H,C LJMP 03DCH JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 18H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0A3H LCALL 04CBH CLR 90H CLR 91H MOV C,92H CPL C MOV 92H,C LJMP 03DCH JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7

; blink yellow ; check if flow rate = 9

; sending serial output ; off red ; blink yellow ; check if flow rate = 10

MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 18H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0AAH LCALL 04CBH CLR 90H CLR 91H MOV C,92H CPL C MOV 92H,C LJMP 03DCH JB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 18H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0B2H LCALL 04CBH CLR 90H CLR 91H MOV C,92H CPL C MOV 92H,C LJMP 03DCH

; sending serial output ; off red ; blink yellow ; check if flow rate = 11

; sending serial output ; off red ; blink yellow

JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 17H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0BAH LCALL 04CBH CLR 90H CLR 92H MOV C,91H CPL C MOV 91H,C SJMP 43H JNB 0BH,04H MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H

; check if flow rate = 12

; sending serial output ; off yellow ; blink yellow ; check if flow rate = 13

MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 1BH JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0C2H LCALL 04CBH ; sending serial output CLR 90H CLR 92H; off yellow MOV C,91H CPL C MOV 91H,C ; blink yellow LCALL 08DAH ; Delay LJMP 0463H JNB 0BH,04H ; check if flow rate = 14 MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 0EH JNB 0DH,45H MOV R3,#0FFH MOV R2,#08H MOV R1,#0CAH LCALL 04CBH ; sending serial output SJMP 3AH JNB 0BH,04H ; check if flow rate = 15 MOV R7,#01H SJMP 02H MOV R7,#00H JNB 0CH,04H MOV R6,#01H

SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 0AH,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 MOV R7,A JNB 09H,04H MOV R6,#01H SJMP 02H MOV R6,#00H MOV A,R6 ANL A,R7 JZ 17H JNB 0DH,09H MOV R3,#0FFH MOV R2,#08H MOV R1,#0D2H LCALL 04CBH ; sending serial output CLR 90H SETB 91H CLR 92H; off yellow LCALL 08DAH ; Delay CLR 91H; off red LCALL 08DAH ; Delay LJMP 0013H MOV A,17H ADD A,#0BH MOV R0,A MOV A,@R0 INC 17H RET MOV R0,#08H JNB 07H,02H MOV R0,#0BH CLR A MOV 0F0H,#01H LCALL 082EH LJMP 07D6H JB 00H,0EBH MOV R7,#2EH SETB 00H SJMP 18H MOV A,R7 ANL A,#0FH ADD A,#90H DA A ADDC A,#40H DA A MOV R7,A

JNB 04H,0BH MOV A,R7 ADD A,#0BFH CJNE A,#1AH,00H JNC 03H ADD A,#61H MOV R7,A MOV A,18H JZ 02H DEC 18H INC 1BH MOV A,1BH JNZ 02H INC 1AH JNB 07H,0DH MOV R0,#08H CLR A MOV 0F0H,#01H LCALL 082EH MOV A,R7 LJMP 081CH LJMP 0913H MOV A,#03H SETB 07H SJMP 03H CLR A CLR 07H MOV 17H,A MOV 08H,R3 MOV 09H,R2 MOV 0AH,R1 CLR A MOV 18H,A MOV 1AH,A MOV 1BH,A MOV A,18H JZ 07H MOV R7,#20H LCALL 04A4H ; send serial output SJMP 0F5H MOV 19H,#0FFH CLR 01H CLR 00H CLR 02H CLR 03H CLR 05H CLR 06H CLR 08H LCALL 0472H MOV R7,A JNZ 0DH JNB 07H,05H MOV R7,#00H LCALL 04B5H MOV R7,1BH

MOV R6,1AH RET CJNE A,#25H,5FH CLR 0D5H CLR 04H LCALL 0472H MOV R7,A ADD A,#0D0H CJNE A,#0AH,00H JNC 1AH MOV 0F0H,#0AH MOV R0,#18H JNB 0D5H,05H INC R0 CJNE @R0,#0FFH,01H INC @R0 XCH A,@R0 MUL AB ADD A,@R0 MOV @R0,A JB 0D5H,04H JNZ 02H SETB 03H SJMP 0D9H ADD A,#0CFH CJNE A,#1AH,00H MOV A,R7 JNC 04H CLR 0E5H SETB 04H LJMP 06B5H SETB 01H SJMP 0C6H SETB 00H SJMP 0C0H SETB 02H SJMP 0BCH SETB 0D5H SJMP 0BAH SETB 05H SJMP 0B4H MOV R7,#20H LCALL 04A4H ; send serial output JB 02H,07H MOV A,#01H CJNE A,18H,00H JC 0F1H LCALL 0469H MOV R7,A LCALL 04A4H ; send serial output LJMP 04DDH SETB 08H SETB 06H SJMP 95H LCALL 0469H

MOV R3,A LCALL 0469H MOV R2,A LCALL 0469H MOV R1,A ORL A,R2 ORL A,R3 JNZ 06H MOV R1,#86H MOV R2,#07H MOV R3,#0FFH JB 02H,2EH MOV A,18H JZ 2AH MOV R6,#00H MOV DPL,R6 MOV DPH,#00H LCALL 07EFH JZ 06H INC R6 MOV A,R6 XRL A,19H JNZ 0F0H CLR 0D5H MOV A,R3 PUSH 0E0H MOV A,R2 PUSH 0E0H MOV A,R1 PUSH 0E0H MOV A,R6 LCALL 06FCH POP 0E0H MOV R1,A POP 0E0H MOV R2,A POP 0E0H MOV R3,A LCALL 07D6H MOV R7,A JZ 0AAH MOV A,R3 PUSH 0E0H MOV A,R2 PUSH 0E0H MOV A,R1 PUSH 0E0H LCALL 04A4H ; send serial output POP 0E0H ADD A,#01H MOV R1,A POP 0E0H ADDC A,#00H MOV R2,A POP 0E0H

MOV R3,A MOV A,19H INC A JZ 0DCH DJNZ 19H,0D9H SJMP 87H MOV R3,#0FFH MOV R2,#06H MOV R1,#0F8H SETB 02H SJMP 9CH MOV R1,#10H SJMP 02H MOV R1,#08H CLR 06H CLR 08H SJMP 08H SETB 0D5H MOV R1,#0AH SJMP 04H MOV R1,#0AH CLR 0D5H MOV A,19H INC A JNZ 02H MOV 19H,A CLR A MOV R2,A MOV R5,A MOV R6,A MOV R7,A LCALL 0469H MOV R4,A MOV R3,#08H JB 01H,13H LCALL 0469H MOV R5,A MOV R3,#10H JNB 00H,0AH LCALL 0469H MOV R6,A LCALL 0469H MOV R7,A MOV R3,#20H MOV A,R4 RLC A ANL C,0D5H MOV 0D5H,C JNC 13H CLR C CLR A JNB 00H,06H SUBB A,R7 MOV R7,A CLR A

SUBB A,R6 MOV R6,A CLR A JB 01H,03H SUBB A,R5 MOV R5,A CLR A SUBB A,R4 MOV R4,A CLR A XCH A,R3 MOV R0,A CLR 01H MOV A,R4 JNZ 0CH XCH A,R7 XCH A,R6 XCH A,R5 XCH A,R4 MOV A,R0 ADD A,#0F8H MOV R0,A JNZ 0F3H SJMP 17H CLR C MOV A,R7 RLC A MOV R7,A MOV A,R6 RLC A MOV R6,A MOV A,R5 RLC A MOV R5,A MOV A,R4 RLC A MOV R4,A MOV A,R3 RLC A MOV R3,A SUBB A,R1 JC 02H MOV R3,A INC R7 DJNZ R0,0E9H MOV A,R3 JNB 01H,05H MOV R0,A POP 0E0H SWAP A ORL A,R0 CPL 01H PUSH 0E0H INC R2 MOV A,R4

ORL A,R5 ORL A,R6 ORL A,R7 MOV R0,#20H MOV R3,#00H JNZ 0C2H MOV A,R2 CJNE A,19H,00H JC 0BCH PUSH 0E0H LCALL 06FEH POP 0F0H POP 0E0H JB 01H,04H SWAP A PUSH 0E0H SWAP A CPL 01H PUSH 0F0H LCALL 048DH POP 0F0H DJNZ 0F0H,0EBH LJMP 04DDH LCALL 083EH INC 7AH ANL 05H,#0F4H ANL A,R0 INC 4BH ORL A,R4 INC 47H ORL 05H,A MOV R0,A ORL A,R7 INC @R0 NOP ORL A,#06H NOP ORL A,R1 INC 60H ORL 06H,#06H ANL A,05H MOV A,R2 ORL A,@R0 INC 0EAH ORL A,05H MOV A,R2 ORL A,@R1 INC @R1 MOV @R0,50H INC 4FH ADD A,R5 INC 53H ADD A,R6 INC 76H ADD A,R3

INC 57H RL A INC 74H JB 07H,8FH ADD A,R2 INC 0FH ORL A,R0 NOP NOP INC 6EH ADDC A,R7 ADDC A,R7 ADDC A,R7 NOP MOV R1,#0AH MOV C,0D5H JB 03H,14H JNB 05H,09H CJNE R1,#10H,02H INC A INC A CJNE R1,#08H,01H INC A MOV C,0D5H JB 06H,02H JNC 01H INC A JB 02H,68H MOV 02H,C CJNE A,18H,00H JNC 34H PUSH 0E0H MOV R7,#20H JNB 03H,19H MOV R7,#30H MOV C,02H ORL C,06H ORL C,05H JNC 0FH LCALL 0755H CLR 02H CLR 06H CLR 05H CLR 08H MOV R7,#30H SJMP 0FH JNB 05H,03H MOV A,R1 PUSH 0E0H LCALL 04A4H ; send serial output JNB 05H,03H POP 0E0H MOV R1,A POP 0E0H CJNE A,18H,0CCH

JNB 05H,17H MOV R7,#30H CJNE R1,#10H,0CH LCALL 04A4H ; send serial output MOV R7,#58H JNB 04H,07H ; check if flow rate = 5 MOV R7,#78H SJMP 03H CJNE R1,#08H,03H LCALL 04A4H ; send serial output JNB 02H,05H MOV R7,#2DH LJMP 04A4H MOV R7,#20H JB 08H,0F8H MOV R7,#2BH JB 06H,0F3H RET MOV 02H,C SJMP 0CFH ADD A,R0 XRL A,R6 MOV 6CH,#6CH ADD A,R1 NOP SETB 01H LCALL 0469H JNB 01H,0F8H CLR 01H MOV R0,#18H JNB 0D5H,01H INC R0 MOV @R0,A LJMP 050FH ADD A,R5 JNC 43H ORL A,R1 ANL A,R0 LCALL 0469H ADD A,#03H CJNE A,#05H,00H JC 01H CLR A MOV DPTR, #07A1H MOVC A,@A+DPTR LCALL 0495H MOV A,#3AH LCALL 0495H SETB 03H MOV 18H,#04H LJMP 05F4H MOV A,R3 SUBB A,R7 MOV 0F0H,A MOV A,R2

SUBB A,R6 ORL 0F0H,A MOV A,R1 SUBB A,R5 ORL 0F0H,A MOV A,R0 SUBB A,R4 ORL A,0F0H RET CJNE R3,#01H,06H MOV DPL,R1 MOV DPH,R2 MOVX A,@DPTR RET JNC 02H MOV A,@R1 RET CJNE R3,#0FEH,02H MOVX A,@R1 RET MOV DPL,R1 MOV DPH,R2 CLR A MOVC A,@A+DPTR RET CJNE R3,#01H,0CH MOV A,DPL ADD A,R1 MOV DPL,A MOV A,DPH ADDC A,R2 MOV DPH,A MOVX A,@DPTR RET JNC 06H MOV A,R1 ADD A,DPL MOV R0,A MOV A,@R0 RET CJNE R3,#0FEH,06H MOV A,R1 ADD A,DPL MOV R0,A MOVX A,@R0 RET MOV A,DPL ADD A,R1 MOV DPL,A MOV A,DPH ADDC A,R2 MOV DPH,A CLR A MOVC A,@A+DPTR RET

CJNE R3,#01H,06H MOV DPL,R1 MOV DPH,R2 MOVX @DPTR,A RET JNC 02H MOV @R1,A RET CJNE R3,#0FEH,01H MOVX @R1,A RET MOV R2,A MOV A,@R0 MOV R3,A INC R0 INC R0 MOV A,@R0 MOV R1,A ADD A,0F0H MOV @R0,A DEC R0 MOV A,@R0 XCH A,R2 ADDC A,R2 MOV @R0,A RET POP DPH POP DPL MOV R0,A CLR A MOVC A,@A+DPTR JNZ 12H MOV A,#01H MOVC A,@A+DPTR JNZ 0DH INC DPTR INC DPTR MOVC A,@A+DPTR MOV R0,A MOV A,#01H MOVC A,@A+DPTR MOV DPL,A MOV DPH,R0 CLR A JMP @A+DPTR MOV A,#02H MOVC A,@A+DPTR XRL A,R0 JZ 0EFH INC DPTR INC DPTR INC DPTR SJMP 0DFH JNB 20H,70H JNZ 6DH

INC R2 NOP ACALL 120H JNZ 70H XRL A,R5 INC R2 NOP RETI JB 70H,70H XRL A,R5 INC R2 NOP RLC A JB 70H,70H XRL A,R5 INC R2 NOP ADDC A,#20H JNZ 70H XRL A,R5 INC R2 NOP ADDC A,20H JNZ 70H XRL A,R5 INC R2 NOP ADDC A,@R0 JB 70H,70H XRL A,R5 INC R2 NOP ADDC A,@R1 JB 70H,70H XRL A,R5 INC R2 NOP ADDC A,R0 JB 70H,70H XRL A,R5 INC R2 NOP ADDC A,R1 JB 70H,70H XRL A,R5 INC R2 NOP ACALL 130H JB 70H,70H XRL A,R5 INC R2 NOP ACALL 131H JB 70H,70H XRL A,R5

; delay function 0.5 secs CLR A MOV 1FH,#0A0H MOV 1EH,#0FH MOV 1DH,A MOV 1CH,A CLR A MOV R7,A MOV R6,A MOV R5,A MOV R4,A MOV R3,1FH MOV R2,1EH MOV R1,1DH MOV R0,1CH SETB C LCALL 07C5H; wait 0.5 secs JC 1AH MOV A,1FH ADD A,#0FFH MOV 1FH,A MOV A,1EH ADDC A,#0FFH MOV 1EH,A MOV A,1DH ADDC A,#0FFH MOV 1DH,A MOV A,1CH ADDC A,#0FFH MOV 1CH,A SJMP 0D3H RET ; Sending a character over serial port MOV A,R7

INC R2 NOP ACALL 132H JB 70H,70H XRL A,R5 INC R2 NOP ACALL 133H JB 70H,70H XRL A,R5 INC R2 NOP ACALL 134H JB 70H,70H XRL A,R5 INC R2 NOP ACALL 135H JB 70H,70H XRL A,R5 INC R2 NOP

CJNE A,#0AH,07H MOV A,#0DH LCALL 091EH MOV A,#0AH JNB SCON,11H MOV R0,SBUF CJNE R0,#13H,0CH CLR SCON JNB SCON,0FDH MOV R0,SBUF CLR SCON CJNE R0,#11H,0F6H JNB SBUF,0FDH CLR SBUF MOV SBUF,A RET; initalise MOV R0,#7FH CLR A MOV @R0,A DJNZ R0,0FDH MOV 81H,#21H LJMP 0003H END

USE OF SIMULATOR TO DEBUG CODE The code was run and the bits for input port p3 were changed. And, corresponding outputs were obtained for port p1. The steps below show how the simulation runs.

Yellow LED Blinks (1Hz) (at input flow rate = 11)

White LED is ON & Yellow LED Blinks (1Hz) (At input flow rate = 11, Serial Output = 1)