Assignment for task 1 (Buzzer)
For this task, we need to build a buzzer. The game buzzer are widely used in school, colleges and tv programs. The team which presses the buzzer earlier is entitled to give the answer. this buzzer works when as soon as any role pressed the pin, the buzzer will sound and the 7 segment show the player number. If other try to push the pin, there will be no output until the clear or stop button pushed.
The assignment can be view on the video below.
Part 1 Demonstration
Part 2 Demonstration
Part 3 Demonstration
The buzzer will sound for 200ms. For this buzzer, it wall sound a bit because the buzzer is small.
Video for simulation:
----------------------------------------------- CODE FOR BUZZER ----------------------------------------------
#include <reg51.h> /*header file*/
unsigned int digi_val[6]={0x3F,0x86,0x5B,0x4F,0x66,0x6D}; /*unsigned integer digi_val .... set 0 to 5*/
sbit stop_pin = P3^2; /*stop button declare*/
sbit buzzer_pin = P1^7; /*buzzer pin declare*/
sbit Player1 = P1^0; /*set player 1*/
sbit Player2 = P1^1; /*set player 2*/
sbit Player3 = P1^2; /*set player 3*/
sbit Player4 = P1^3; /*set player 4*/
sbit Player5 = P1^4; /*set player 5*/
void delay(int ms) /*delay routine*/
{
int i,j; /*set i and j as integer*/
for(i=0; i < ms; i++) /*take int ms to ms to calculate*/
for(j=0; j < 1000; j++); /*set for ms second*/
}
void display(unsigned int current_dig) /*display routine and ask for current value*/
{
P0=digi_val[current_dig]; /*current value shown in port 0*/
buzzer_pin = 0; /*buzzer active*/
delay(200); /*delay for 200ms*/
buzzer_pin=1; /*buzzer deactive*/
while(stop_pin != 0); /*keep 1st input and stop scanning other input value*/
stop_pin = 1; /*if stop button trigger will continue next code*/
P0 = 0X00; /*port0 is 0, 7segment not show any number*/
}
void main(void) /*main body*/
{
stop_pin = 1; /*if stop button trigger will continue next code*/
P0 = 0X00; /*port0 is 0, 7segment not show any number*/
P1 = 0xFF; /*set port 1 as input*/
while(1) /*when circuit is running*/
{
if (Player1 == 0) /*when player 1 is pressed*/
{
display(1); /*call display routine for case 1*/
}
else if (Player2 == 0) /*when player 2 is pressed*/
{
display(2); /*call display routine for case 2*/
}
else if (Player3 == 0 ) /*when player 3 is pressed*/
{
display(3); /*call display routine for case 3*/
}
else if (Player4 == 0 ) /*when player 4 is pressed*/
{
display(4); /*call display routine for case 4*/
}
else if (Player5 == 0 ) /*when player 5 is pressed*/
{
display(5); /*call display routine for case 5*/
}
}
}

Comments
Post a Comment