PIANO USING AT89C51RD2
SIMULATOR: PROTEUS
8.0
SOFTWARE: KEIL
4.0
CIRCUIT DIAGRAM:
CIRCUIT
DESCRIPTION:
Switches from one to seven are connected in pull-up
configuration to p1.0 to p1.6 respectively. A buzzer is connected to p2.0.
WORKING:
In this project, I have created the prototype of the
piano using seven switches and a buzzer. Seven switches are used as a seven
keys(sa, re, ga, ma, pa, dha, ni, sa) of piano. A buzzer is used to generate
the sound given by the controller(AT89C51RD2).
Whenever a switch related to a particular key is
pressed, the frequency of that particular key is applied to the buzzer by the
controller(AT89C51RD2).
PROGRAM:
#include<reg51.h>
sbit sw1 = P1^0;
// SA
sbit sw2 = P1^1;
// RE
sbit sw3 = P1^2; // GA
sbit sw4 = P1^3; // MA
sbit sw5 = P1^4; // PA
sbit sw6 = P1^5; // DHA
sbit sw7 = P1^6; // NI
sbit pulse = P2^0; //buzzer
void tune(unsigned int th,unsigned int tl);
int main()
{
while(1)
{
if(sw1==0)
{
pulse = ~P2^0;
tune(0xf8,0x77); // frequency of sa
}
if(sw2==0)
{
pulse = ~P2^0;
tune(0xf9,0x4d); //
frequency of re
}
if(sw3==0)
{
pulse = ~P2^0;
tune(0xf9,0xf9); // frequency of ga
}
if(sw4==0)
{
pulse = ~P2^0;
tune(0xfa,0x59);
// frequency of ma
}
if(sw5==0)
{
pulse = ~P2^0;
tune(0xfa,0xfa);
// frequency of pa
}
if(sw6==0)
{
pulse = ~P2^0;
tune(0xfb,0x7b);
// frequency of dha
}
if(sw7==0)
{
pulse = ~P2^0;
tune(0xfb,0xfb);
// frequency of ni
}
}
}
// Function to display different frequencies
void tune(unsigned int th ,unsigned int tl)
{
TMOD = 0x01; // timer 0 in mode 1
TH0 = th; // load the higher value
TL0 = tl; // load the lower value
TR0 = 1; // start the timer
while(TF0 == 0); // wait for overflow
TF0 = 0; // clear overflow flag
TR0 = 0; // stop
the timer
}
PROGRAM
DESCRIPTION:
I have used timer 0 in mode 1 to generate square waves
of different frequencies of swaras. I have generated the square wave on by providing logic 1 and logic 0 alternatively to
p2.0.
Frequencies of swaras are as follows:
1.SA: 240hz
2.RE: 270hz
3.GA: 300hz
4.MA: 320hz
5.PA: 360hz
6.DHA: 400hz
7.NI: 450hz
I have calculated the timer values of the above swaras
as mentioned below:
Calculation of timer value to be loaded in
TH0 and TL0 register:
I have taken the micro-controller with a crystal frequency of 11.0592mhz frequency. Thus, the calculation is
SA : 240 HZ
1.(11.0592 MHZ ) / 12 = 921600 HZ
2.1 / (921600) = 1.08*10^-6
3.Here we want a square wave of 240 Hz. So time will be 1/ (240 Hz)=4.16 msec
4.As we want to generate the square wave, this delay is equivalent to Ton+Toff=4.16msec. As we know that in square wave Ton=Toff
5.Hence to get the required delay we will divide this 4.16 msec by 2 so that we will get the value of Ton and Toff.
6.Ton = Toff = (4.16*10^-3) / 2 = 2.08 msec
7.Count= required time / processor time
8.Here the required time is 2.08 msec
9.Count = (2.08*10^-3) / (1.08*10^-6)
10.Count = 1929.01=1929(decimal)
11.Value to be loaded in timer register: 65536 – 1929 = 63607 = f877(hex)
12.So, in TH0 = 0xf8 and TL0 = 0x77
RE: 270 HZ
1.Here the required time is (1/270)/2 = 1.85 msec
2.Count = (1.85*10^-3) / (1.08*10^-6)
3.Count = 1714.67=1715(decimal)
4.Value to be loaded in timer register: 65536 – 1715 = 63821 = f94d(hex)
5.So in TH0 = 0xf9 and TL0 = 0x4d
GA: 300 HZ
1.Here the required time is (1/300)/2 = 1.66 msec
2.Count = (1.66*10^-3) / (1.08*10^-6)
3.Count = 1543.20=1543(decimal)
4.Value to be loaded in timer register: 65536 – 1543 = 63993 = f9f9(hex)
5.So in TH0 = 0xf9 and TL0 = 0xf9
MA: 320 HZ
1.Here the required time is (1/320)/2 = 1.56 msec
2.Count = (1.56*10^-3) / (1.08*10^-6)
3.Count = 1446.75=1447(decimal)
4.Value to be loaded in timer register: 65536 – 1447 = 64089 = fa59(hex)
5.So in TH0 = 0xfa and TL0 = 0x59
PA: 360 HZ
1.Here the required time is (1/360)/2 = 1.38 msec
2.Count = (1.38*10^-3) / (1.08*10^-6)
3.Count = 1286.00=1286(decimal)
4.Value to be loaded in timer register: 65536 – 1286 = 64250 = fafa(hex)
5.So in TH0 = 0xfa and TL0 = 0xfa
DHA: 400 HZ
1.Here the required time is (1/400)/2 = 1.25 msec
2.Count = (1.25*10^-3) / (1.08*10^-6)
3.Count = 1157.40=1157(decimal)
4.Value to be loaded in timer register: 65536 – 1157 = 64379 = fb7b(hex)
5.So in TH0 = 0xfb and TL0 = 0x7b
NI: 450 HZ
1.Here the required time is (1/450)/2 = 1.11 msec
2.Count = (1.11*10^-3) / (1.08*10^-6)
3.Count = 1028.80=1029(decimal)
4.Value to be loaded in timer register: 65536 – 1029 = 64507 = fbfb(hex)
5.So in TH0 = 0xfb and TL0 = 0xfb
VIDEO:
NOTE:
Please visit below link to know how to interface timer and
generate the square wave using 8051:
https://embeddedprojects222.blogspot.com/2020/08/timer-interfacing-with-8051.html
Comments
Post a Comment