Schematicnya
Asm Codenya
ORG 0000H
MOV P2, #00H ;clearing all inputs
SETB P1.0 ;setting all outputs for common anode display
SETB P1.1
SETB P1.2
SETB P1.3
SETB P1.4
SETB P1.5
SETB P1.6
CLR P1.7
CLR P3.1
MOV R3,#0FFH
CHECK: ;To check for any input
MOV P1,#0FFH
JB P2.0, TEAMA
JB P2.1, TEAMB
JB P2.2, TEAMC
JB P2.3, TEAMD
JB P2.4, TEAME
JB P2.5, TEAMF
JB P2.6, TEAMG
JB P2.7, TEAMH
SJMP CHECK
TEAMA:
MOV P1,#00001000B ;
ACALL BUZZER ;
TEAMB:
MOV P1,#01100000B
ACALL BUZZER
TEAMC:
MOV P1,#00110001B
ACALL BUZZER
TEAMD:
MOV P1,#01000010B
ACALL BUZZER
TEAME:
MOV P1,#00110000B
ACALL BUZZER
TEAMF:
MOV P1,#00111000B
ACALL BUZZER
TEAMG:
MOV P1,#00100001B
ACALL BUZZER
TEAMH:
MOV P1,#01001000B
ACALL BUZZER
BUZZER:
CLR P1.7
ACALL HERE
SETB P1.7
LJMP DELAY
DELAY:
JB P3.1,CHECK
SJMP DELAY
RET
HERE: MOV R4,#0FFH
D1: MOV R5,#005H
D2: DJNZ R5,D2
DJNZ R4,D1
DJNZ R3,HERE
RET
END
Videonya
Source Code C :
#include<reg51.h>
unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; // Hex value corresponding to the digits 0 to 9
sbit output_on_pin = P3^0; // Enable pin to enable the seven segment.
sbit stop_pin = P3^1; // Stop pin to reset the buzzer.
sbit buzzer_pin=P0^0; // Buzzer pin to sound the buzzer.
int flag;
void delay() // Time delay function
{
int i,j;
for(i=0;i<200;i++)
for(j=0;j<1275;j++);
}
void display(unsigned int current_dig) // Function to display the resultant digit on the seven segment and sound the buzzer.
{
P2=digi_val[current_dig];
output_on_pin = 1;
buzzer_pin=0;
delay();
buzzer_pin=1;
while(stop_pin != 0);
}
void buzzer() //Function to monitor the input switches
{
flag = 0;
while(1)
{
while (P1 == 0xFF);
while (P1 == 0xFE) //Check if switch 1 is pressed
{
flag = 1;
display(1);
}
while (P1 == 0xFD) //Check if switch 2 is pressed
{
flag = 2;
display(2);
}
while (P1 == 0xFB ) //Check if switch 3 is pressed
{
flag = 3;
display(3);
}
while (P1 == 0xF7 ) //Check if switch 4 is pressed
{
flag = 4;
display(4);
}
while (P1 == 0xEF ) //Check if switch 5 is pressed
{
flag = 5;
display(5);
}
while (P1 == 0xDF) //Check if switch 6 is pressed
{
flag = 6;
display(6);
}
while (P1 == 0xBF ) //Check if switch 7 is pressed
{
flag = 7;
display(7);
}
while (P1 == 0x7F ) //Check if switch 8 is pressed
{
flag = 8;
display(8);
}
P1 = 0xFF;
stop_pin = 1;
output_on_pin = 0;
}
}
void main()
{
output_on_pin=0;
stop_pin = 1;
P1 = 0xFF;
buzzer();
}