PDA

View Full Version : bản kìa con bướm vàng phát ra từ pic


dinhminh09
08-11-2010, 09:51 AM
em còn ga lắm cái này viết chơi thôi

#include <16F877A.h>
#fuses NOWDT,NOLVP,XT,PUT,NOPROTECT
#use delay(clock=20000000)



#include "titit.c"
int32 i;
void main()
{

output_high(pin_c0);
while(1)
{

kiaconbuomvang();

// kìa con buom vang


// trái ?át này là c?a chúng mình
}
}
//////////////////////////////////////////////

titit.c
//////////////////////////////////////////////
#define rc0 pin_c0
int32 a;

void tocdo()
{

output_high(rc0),
delay_us(500),
output_low(rc0),
delay_us(100);
}
void amtit1()
{
// phat xung tao am thanh
for(a=0;a<=20;a++)
{
delay_us(1000),
output_high(rc0),
delay_us(1000),
output_low(rc0);
}
}


void amtit2()
{
// phat xung tao am thanh
for (a=0;a<=100;a++)
{
delay_us(3000),
output_high(rc0),
delay_us(3000),
output_low(rc0);
}
}

void amtit3()
{
delay_us(4000),
output_high(rc0),
delay_us(4000),
output_low(rc0);
}

void amtohop()
{
for (a=0;a<=50;a++)
{
delay_us(800),
output_high(rc0),
delay_us(800),
output_low(rc0);
}

for (a=0;a<=50;a++)
{
delay_us(1000),
output_high(rc0),
delay_us(800),
output_low(rc0);
}

for (a=0;a<=50;a++)
{
delay_us(800),
output_high(rc0),
delay_us(1000),
output_low(rc0);
}

for (a=0;a<=50;a++)
{
delay_us(800),
output_high(rc0),
delay_us(1200),
output_low(rc0);
}

for (a=0;a<=50;a++)
{
delay_us(800),
output_high(rc0),
delay_us(1400),
output_low(rc0);
}

for (a=0;a<=50;a++)
{
delay_us(800),
output_high(rc0),
delay_us(1600),
output_low(rc0);
}
}

void trong()
{
delay_ms(20);
}

void do1() // c
{
for (a=0;a<=60;a++)
{
delay_us(3800),
output_high(rc0),
delay_us(3800),
output_low(rc0);
}
}

void do11() // c
{
for (a=0;a<=60;a++)
{
delay_us(3600),
output_high(rc0),
delay_us(3600),
output_low(rc0);
}
}





void re1() //
{
for (a=0;a<=60;a++)
{
delay_us(3400),
output_high(rc0),
delay_us(3400),
output_low(rc0);
}
}

void re11() //
{
for (a=0;a<=60;a++)
{
delay_us(3200),
output_high(rc0),
delay_us(3200),
output_low(rc0);
}
}

void mi1()
{
for (a=0;a<=60;a++)
{
delay_us(3000),
output_high(rc0),
delay_us(3000),
output_low(rc0);
}
}

void mi11()
{
for (a=0;a<=60;a++)
{
delay_us(2900),
output_high(rc0),
delay_us(2900),
output_low(rc0);
}
}

void fa1()
{
for (a=0;a<=60;a++)
{
delay_us(2800),
output_high(rc0),
delay_us(2800),
output_low(rc0);
}
}

void fa11()
{
for (a=0;a<=60;a++)
{
delay_us(2700),
output_high(rc0),
delay_us(2700),
output_low(rc0);
}
}

void sol1()
{
for (a=0;a<=60;a++)
{
delay_us(2500),
output_high(rc0),
delay_us(2500),
output_low(rc0);
}
}

void sol11()
{
for (a=0;a<=60;a++)
{
delay_us(2400),
output_high(rc0),
delay_us(2400),
output_low(rc0);
}
}



void la1()
{
for (a=0;a<=60;a++)
{
delay_us(2300),
output_high(rc0),
delay_us(2300),
output_low(rc0);
}
}

void la11()
{
for (a=0;a<=60;a++)
{
delay_us(2200),
output_high(rc0),
delay_us(2200),
output_low(rc0);
}
}


void si1()
{
for (a=0;a<=60;a++)
{
delay_us(2000),
output_high(rc0),
delay_us(2000),
output_low(rc0);
}
}

void si11()
{
for (a=0;a<=60;a++)
{
delay_us(2100),
output_high(rc0),
delay_us(2100),
output_low(rc0);
}
}

void ddo()
{
for (a=0;a<=60;a++)
{
delay_us(9500),
output_high(rc0),
delay_us(9500),
output_low(rc0);
}
}

void ddo1()
{
for (a=0;a<=60;a++)
{
delay_us(1900),
output_high(rc0),
delay_us(1900),
output_low(rc0);
}
}

void kiaconbuomvang()
{
do11(); re11(); mi11(); do11();trong();
do11(); re11(); mi11(); do11();trong();
mi11(); fa11(); sol11();trong();
mi11(); fa11(); sol11();trong();
sol11(); la11(); sol11(); fa11(); mi11(); do11();trong();
sol11(); la11(); sol11(); fa11(); mi11(); do11();trong();
ddo1(); sol11(); ddo1(); trong();trong();
ddo1();trong(); sol11(); ddo1(); trong();trong();trong();trong();trong();
}

void kenhieu()
{
sol1(); trong(); re11();re11(); sol1(); trong(); sol1(); sol1(); si1();trong();
sol1(); sol1(); si1();trong(); re11(); trong(); si1(); si1(); re11();trong();
si1(); si1(); re11();trong();si1(); trong();sol1(); re11(); re11(); re11(); sol1();trong();
si1(); re11(); trong(); si1(); si1(); re11(); trong(); si1(); trong(); sol1();
re11(); re11(); sol1(); trong(); trong ();


la11();trong(); mi1(); mi1(); la11(); trong();
mi1(); mi1(); la11(); trong();trong();
ddo1();trong(); la11(); la11(); ddo1();trong();la11();la11();ddo();trong();
mi11();trong(); ddo(); ddo(); mi11();trong();ddo(); ddo(); mi11();trong();
ddo(); la1(); trong(); mi11();trong(); mi11(); mi11(); la1(); trong();
trong(); ddo1(); mi11(); trong(); ddo(); ddo(); mi11(); trong();
ddo(); ddo(); mi11(); trong(); ddo(); la11(); mi11(); mi11(); mi11(); la1();

}

void nangsom()
{


do1();trong(); do1();sol1(); trong(); la1(); la1(); fa1(); re1();trong();
trong(); trong(); trong();
do1();trong(); do1();sol1(); trong(); la1(); la1(); fa1(); re1();trong();

}


chỉ cần nối ra cái loa từ chân rc0
mà cái này thích thì khai báo lại. nhưng mà có cái sao âm thanh nó không hay lắm bác nào biết làm thế nào để tạo ra âm thanh hay thì giúp mình với.mắt dô mấy cái mạch lọc rc thì nó lại bị rè rất khó chịu
định dung pwm nhưng phải tạo lại từng nốt. về cái tần số bên pwm tính toán cũng khó qua!!!!!