Past exam question: Assignment 3, Q2
Open in the Padhaiko appYou have to interface ADC with 8085 using 8255A ports. Interface a fan and a heater using optocouplers to derive the I/O device. If the temperature is less than , turn on heater and if temperature is higher than , turn on the fan. Use port A of 8255 for transferring digital data output of ADC to the CPU and port C for control signals. Assume that an analog input is present at second input of the MUX and a clock input of suitable frequency is available for ADC.Draw the circuit diagram of your design and write the subroutine.
Solution
System Assumptions, Port Mapping, and Signal Allocation:
- ADC Selection: Use an 8-bit multiplexed ADC (ADC0808/0809) with 8 analog inputs (–). The sensor is connected to the second MUX input (channel address
001, i.e. ). - Temperature Scaling: Assume a calibrated sensor (such as LM35, ) with and so that the 8-bit resolution is . Hence:
- 8255A I/O-Mapped Addresses (base
80H, decoded from ):- Port A =
80H(Input: – from ADC) - Port B =
81H(Output:PB0Heater optocoupler,PB1Fan optocoupler; active-high) - Port C =
82H(Control signals:PC0= MUX select = 1,PC1= MUX select = 0,PC2= MUX select = 0,PC3= ALE & SOC,PC7= EOC input) - Control Register =
83H
- Port A =
- Control Word: Mode 0, Port A = Input (
1), Port C Upper = Input (1), Port B = Output (0), Port C Lower = Output (0):
Interfacing Circuit Diagram:
8085 CPU 8255A PPI ADC0808
+----------+ +-----------+ +---------+
| D0-D7 |<============>| D0-D7 | | |
| A0, A1 |------------->| A0, A1 | | |
| A7-A2 |--[Decode]--->| CS' | | |
| IOR' |------------->| RD' PA0 |<----------------| D0 |
| IOW' |------------->| WR' ... |<----------------| ... |
+----------+ | PA7 |<----------------| D7 |
| | | |
+5V | PC0 |---------------->| ADD A |
| | PC1 |---------------->| ADD B |
[R] | PC2 |---------------->| ADD C |
| Optocoupler | PC3 |--------+------->| ALE |
+---[LED | Photo-Triac]| | +------->| SOC |
| (MOC3021 + Triac) | PC7 |<----------------| EOC |
+---[Heater Driver]<---| PB0 | | |
| | | Temp Sensor-->| IN1 |
+---[Fan Driver] <---| PB1 | Ext. Clock--->| CLK |
+-----------+ +---------+Each optocoupler isolates the high-voltage AC/DC load (heater and fan) from the 5 V logic of Port B (PB0 drives the heater optocoupler LED through a current-limiting resistor; PB1 drives the fan optocoupler LED).
8085 Assembly Language Subroutine: The subroutine selects channel (01H on PC2–PC0), pulses ALE and SOC (PC3), polls EOC on PC7, reads the temperature byte from Port A, and switches the heater (PB0) or fan (PB1) via Port B:
TEMP_CTRL: MVI A, 98H ; Mode 0: PA=In, PCU=In, PB=Out, PCL=Out
OUT 83H ; Initialize 8255A control register
MVI A, 01H ; Select MUX channel IN1 (C=0, B=0, A=1), ALE=SOC=0
OUT 82H ; Output channel address to Port C
MVI A, 09H ; Set PC3=1 (ALE & SOC high) while keeping IN1 (01H)
OUT 82H
NOP ; Short pulse width for ALE/SOC
MVI A, 01H ; Return PC3=0 (ALE & SOC low)
OUT 82H
WAIT_EOC: IN 82H ; Read Port C status
ANI 80H ; Mask PC7 (EOC)
JZ WAIT_EOC ; Wait until EOC = 1 (conversion complete)
IN 80H ; Read 8-bit temperature value from Port A
CPI 0AH ; Compare with 10 deg C (0AH)
JC HEATER_ON ; If T < 10 deg C (CY=1), turn ON heater
CPI 24H ; Compare with 36 deg C (check T > 35 deg C)
JNC FAN_ON ; If T >= 36 deg C (i.e. T > 35 deg C), turn ON fan
MVI A, 00H ; 10 <= T <= 35 deg C: both heater and fan OFF
OUT 81H
RET
HEATER_ON: MVI A, 01H ; PB0 = 1 (Heater ON), PB1 = 0 (Fan OFF)
OUT 81H
RET
FAN_ON: MVI A, 02H ; PB1 = 1 (Fan ON), PB0 = 0 (Heater OFF)
OUT 81H
RETUsing an ADC0808 with sensor on channel (PC2–PC0 = 001), 8255A initialized with control word 98H (Port A input for ADC data, Port C lower output for MUX/ALE/SOC, Port C upper input for EOC on PC7, and Port B output for optocoupler-isolated heater on PB0 and fan on PB1), the subroutine polls EOC, reads Port A, turns on the heater if (0AH), turns on the fan if (23H), and turns both off in the deadband .