This project shows the addition and subtraction process using 8051. To simulate circuit in this project, initially activate Mixed Mode simulator from the Schematic Editor window. Simulation can be performed by selecting Run Transient analysis (Oscillograph) from Simulation menu.
The circuit contains an 8051 chip, Parallel Pattern Generator with Interrupt, Binary to 7-segment decoder and 7-Segment Displays. In this circuit, Port P0 of 8051 is assigned as the input port while Port P1 is assigned as output port. A ‘Low’ state at Port 2.7 invokes Subtraction while a ‘High’ state invokes Addition.
Parallel Pattern Generator with Interrupt
generates a parallel pattern when Start Pattern button is enabled. This parallel pattern includes a data byte along with an interrupt pulse. This interrupt pulse is given to the ‘INT0’ pin of 8051.
For this database, the mode of transmission chosen is ‘Interruptable’ and the style of transmission is ‘Repeat’. The size of data in bytes is specified as 15. Each time the Start Pattern button is clicked, a parallel pattern is produced. When the interrupt signal appears at INT0 pin, and if the state at Port 2.7 is ‘High’, then the parallel pattern data byte is added to the data that is specified internally through the code.
If the state at Port 2.7 is ‘Low’, then the data that is specified internally through the code is subtracted from the parallel pattern data byte. After addition or subtraction, the output from port P1 passes through the Binary to 7-Segment Decoders and the result is displayed in 7-segment form.
The program is as shown:
void my_int ( ) interrup 0; // Interrupt function declaration
void main ( )
EA=1; // EA is set to enable all interrupts
EX0=1; // EX0 is set to enable external interrupt 0
ACC=0X00; // Accumulator is initialised with ‘00’
for( ; ; ) // Infinite loop
// Interrupt function definition
void my_int ( ) interrupt 0
int i, j; // Variables declared
j=0X10; // The value ‘10’ is assigned to variable j
i=P0; // The value at Port 0 is given to i
P2_5=0; // P2.5 which is externally connected to the 'LE' pin of decoder is
set to ‘0’.
If (P2_7 ==1) // Checks whether the state of P2.7 is High