thấy chuông điện thoại ở nhà giống với ông hàng xóng we , nhân gặp đợt thực tập VĐK , tui làm lun sp này , Nói chung rất cute , rất style ko đụng hàng ! ông thầy ko có chỗ nào để hỏi (chắc có lẽ nó dở we..heee) ...chạy rất ổn định và tốt ......
mạch nguyên lý
mạch thu tín hiệu chuông
mạch phát nhạc
sp của tui đã chạy thực tế , các u có thể xem nó hoạt động ở video sau
http://www.2shared.com/file/3517579/.../MOV03285.html
mạch nguyên lý
mạch thu tín hiệu chuông
mạch phát nhạc
Code:
//----------nạp cho kon U1 , con nhận tín hiệu bell_signal #include<AT89S53.h> sbit bell_signal = 0xB0; sbit OFF = 0xB1; sbit ON13 = 0xA5; sbit OFF13 = 0xA4; void delay_ms(unsigned char ms) { unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<120;j++){}; } main() { bell_signal = 1; OFF = 1; ON13 = 1; OFF13 = 1; while(1) { if(!bell_signal) { delay_ms(1);ON13=0;delay_ms(1);ON13 = 1;}; bell_signal = 1; } }
Code:
#include<AT89S53.h> sbit OFF34 = 0xA5; sbit ON34 = 0xA6; sbit ON13 = 0xB5; sbit OFF13 = 0xB6; sbit play = 0x80; sbit stop = 0x81; sbit next = 0x82; unsigned char preloadTH=0xFF,preloadTL=0xFF; unsigned int pointer=0,i=0,j; //octa: 0 //key : C C# D D# E F F# G G# A A# B const float key_octa0[]={16.35,17.32,18.35,19.45,20.6,21.83,23.12,24.5,25.96,27.5,29.14,30.87}; const unsigned int chuan=200; const float crystal=11.0592; code unsigned char array[]= {"4a~,5d^,5F^,5e~,5a~,5d^,5C^,5d^,5e^,5F&,5d^,5g^,5g@,5g%,5d^,5C~,5C%,4a@,5a^,5a@,5a^,5e@,5e^ \ 5d&,4a^,4b^,5d~,5F^,5e^,5a~,5C^,5d. \ 5d@,5C@,5d@,5e@,5F@,5g@,5F@,5e@,5g^,5F^,5g^,5b@,5b%,5a~,5g^,5F^,5e^ \ 5F^,6C^,6d&,6d^,6e^,6d@,6d%,6d^,6e^,6d^,6C^,5b^,5a.,5g@,5F@,5g@,5a@,5b~ \ 5g^,5F^,5g^,5b@,5b%,5a~,5g^,5F^,5e^,5F^,6C^,6e^,6d~,5a^,5b^,5a@,5b%,6d^,6e~,6d^,6C^,6d. \ 5a^,5F@,5g@,5a^,5F@,5g@,5a@,4a@,4b@,5C@,5d@,5e@,5F@,5g@,5F^,5d@,5e@,5F^ \ 4F@,4g@,4a@,4b@,4a@,4g@,4a@,4F@,4g@,4a@,4g^,4b@,4a@,4g^,4F@,4e@,4F@,4e@,4d@,4e@,4F@,4g@,4a@,4b@,4g^ \ 4b@,4a@,4b^,5C@,5d@,4a@,4b@,5C@,5d@,5e@,5F@,5g@,5a@ \ 5a^,5F@,5g@,5a^,5F@,5g@,5a@,4a@,4b@,5C@,5d@,5e@,5F@,5g@,5F^,5d@,5e@,5F^ \ 4F@,4g@,4a@,4b@,4a@,4g@,4a@,4F@,4g@,4a@,4g^,4b@,4a@,4g^ \ 4F@,4e@,4F@,4e@,4d@,4e@,4F@,4g@,4a@,4b@,4g^,4b@,4a@,4b^ \ 5C@,5d@,4a@,4b@,5C@,5d@,5e@,5F@,5g@,5a@ \ 4a~,5d^,5F^,5e~,5a~,5d^,5C^,5d^,5e^,5F& \ 5d^,5g^,5g~,5d^,5C^,5C~,s" }; void delay_ms( unsigned int ms ) { unsigned int i,j; for (i=0;i<ms;i++) for (j=0;j<120;j++){}; } void doitanso(float tanso) { unsigned int giatrinap; giatrinap=65536-(unsigned int)((1000000*crystal)/(24*tanso)); preloadTL=(unsigned char)giatrinap; preloadTH=(unsigned char)(giatrinap>>8); } void key(unsigned char octa,unsigned char k) { float tanso; switch (k) { case 'c' : tanso=key_octa0[0]; break; case 'C' : tanso=key_octa0[1]; break; case 'd' : tanso=key_octa0[2]; break; case 'D' : tanso=key_octa0[3]; break; case 'e' : tanso=key_octa0[4]; break; case 'f' : tanso=key_octa0[5]; break; case 'F' : tanso=key_octa0[6]; break; case 'g' : tanso=key_octa0[7]; break; case 'G' : tanso=key_octa0[8]; break; case 'a' : tanso=key_octa0[9]; break; case 'A' : tanso=key_octa0[10]; break; case 'b' : tanso=key_octa0[11]; break; } switch (octa) { case '1' : tanso*=2; break; case '2' : tanso*=4; break; case '3' : tanso*=8; break; case '4' : tanso*=16; break; case '5' : tanso*=32; break; case '6' : tanso*=64; break; case '7' : tanso*=128; break; case '8' : tanso*=256; break; } doitanso(tanso); } unsigned int trave(unsigned int ms) { unsigned int a; a=preloadTH; a=a<<8|preloadTL; return (ms*crystal*1000)/12/(65536-a); } unsigned int tempo(unsigned char tem) { switch (tem) { case '/' : return trave(chuan/4); break; // 0,25 case '<' : return trave(chuan/2); break; // 0,5 case '@' : return trave(chuan*3/4); break; // 0,75 case '=' : return trave(chuan); break; // 1 case '#' : return trave(chuan*5/4); break; // 1,25 case '^' : return trave(chuan*3/2); break; // 1,5 ; den = 180 case '!' : return trave(chuan*7/4); break; // 1,75 case '>' : return trave(chuan*2); break; // 2 case '%' : return trave(chuan*9/4); break; // 2,25 case '`' : return trave(chuan*5/2); break; // 2,5 case 'o' : return trave(chuan*11/4);break; //2,75 case '~' : return trave(chuan*3); break; // 3 case '$' : return trave(chuan*7/2); break; // 3,5 case '+' : return trave(chuan*15/4);break; // 3,75 case '*' : return trave(chuan*4); break; // 4 case '&' : return trave(chuan*9/2); break; // 4,5 case ':' : return trave(chuan*5); break; // 5 case '.' : return trave(chuan*6); break; //6 case '?' : return trave(chuan*7); break; //7,5 } } void timer0_ISR() interrupt 1 { P2_0=!P2_0; TL0=preloadTL; TH0=preloadTH; if(i==0) { if(array[pointer]=='s') { TR0 = 0; pointer = 0; // comeback TR0 = 1; }; key(array[pointer],array[pointer+1]); j=tempo(array[pointer+2]); } i++; if(i==j) { i=0; pointer+=4; } } void main(void) { TMOD =0x01; // dung timer0 16 bit TL0 =0xFF; TH0 =0xFF; ET0 =1; EA =0; // chua cho phep ngat TR0 =1; ON13 = 1; OFF13 = 1; ON34 = 1; OFF34 = 1; play = 1; stop = 1; while(1) { if(!ON13){ON34=0;EA=1;}; if(!stop) { delay_ms(50); while(!stop) continue ; delay_ms(10); EA=0;pointer =0; }; if(!play) { delay_ms(50); while(!play) continue ; delay_ms(10); EA = 1; }; //if(!OFF13){ON13=1;ON34=1;EA=0;OFF34=0;pointer=0;}; //OFF34 = 1; //OFF13 = 1; }; }
http://www.2shared.com/file/3517579/.../MOV03285.html
Comment