完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
程序功能:播放类似摩尔斯电码的声音,现在是可以放,但是不能暂停,也就是两个外中断功能没写好
/******22.1184MHz******/ #include "stc15f2k60s2.h" #include #define uint unsigned int #define uchar unsigned char ***it Voice_Frequency = P4^5; //ÒôƵ¶¨Òå ***it Key_Pause = P3^3; ***it Key_Stop = P3^2; void System_Init(void); void Delay1ms(void); void Delay_ms(uint ms); void Delayms(uint ms); void Test_Play(uchar V,uchar *Tel_Table); //²ÎÊý˳ÐòΪ:ÂëËÙ,ÂëºÅ,Âë±í uchar Tel_Table[10]={0,4,1,3,4,7,6,7,8,6}; uchar Tel_Table_All[20]={1,3,1,4,5,2,0,7,9,7,9,5,3,6,4,8,2,0,6,8}; uchar Code_Table0[1]={3}; // uchar Code_Table1[3]={1,1,3}; // uchar Code_Table2[5]={1,1,1,1,3}; // uchar Code_Table3[7]={1,1,1,1,3,1,3};// uchar Code_Table4[7]={1,1,1,1,1,1,3};// uchar Code_Table5[7]={1,1,1,1,1,1,1};// uchar Code_Table6[7]={3,1,1,1,1,1,1};// uchar Code_Table7[7]={3,1,3,1,1,1,1};// uchar Code_Table8[3]={3,1,1}; // uchar Code_Table9[1]={1}; uchar WAIT; //WAITΪÑÓʱµÈ´ý·û uint times,Count; //TimesΪµã»®±êÖ¾·û,CountΪ¶¨Ê±Æ÷2¼Æʱ±äÁ¿ bit Play_Flag = 0; void main(void) { P3 = 0xFF; System_Init(); while(1) { Delay_ms(3000); Test_Play(80,Tel_Table_All); //²âÊÔÉùÒôЧ¹û } } void Test_Play(uchar V,uchar *Tel_Table) { uchar Group,Code_Val,Group_length,Group_Val; for(Group=0;Group<10;Group++) { Group_Val = Tel_Table[Group]; switch(Group_Val) { case 0: Group_length = 1; break; case 1: Group_length = 3; break; case 2: Group_length = 5; break; case 3: Group_length = 9; break; case 4: Group_length = 9; break; case 5: Group_length = 9; break; case 6: Group_length = 9; break; case 7: Group_length = 9; break; case 8: Group_length = 5; break; case 9: Group_length = 3; break; } for(Code_Val=0;Code_Val switch(Group_Val) { case 0: Times = Code_Table0[Code_Val]*V; break; case 1: Times = Code_Table1[Code_Val]*V; break; case 2: Times = Code_Table2[Code_Val]*V; break; case 3: Times = Code_Table3[Code_Val]*V; break; case 4: Times = Code_Table4[Code_Val]*V; break; case 5: Times = Code_Table5[Code_Val]*V; break; case 6: Times = Code_Table6[Code_Val]*V; break; case 7: Times = Code_Table7[Code_Val]*V; break; case 8: Times = Code_Table8[Code_Val]*V; break; case 9: Times = Code_Table9[Code_Val]*V; break; } if(Code_Val%2==0) { TR0 = 1; } AUXR |= 0X10; //Æô¶¯¶¨Ê±Æ÷2 while(!WAIT); WAIT = 0; } if((Group+1)%4 == 0) { Times = 5*V; AUXR |= 0X10; while(!WAIT); WAIT = 0; } else { Times = 3*V; AUXR |= 0X10; while(!WAIT); WAIT = 0; } } } void Pause_ISR(void) interrupt 2 { EX1 = 0; if(Key_Pause == 0) { Delayms(15); if(Key_Pause == 0) { if(Play_Flag == 0) { AUXR &= 0XEF; TR0 = 0; WAIT = 0; while(!Key_Pause); SBUF = 0XB1;while(TI == 0);TI = 0; } else if(Play_Flag == 1) { AUXR |= 0X10; TR0 = 1; WAIT = 1; while(!Key_Pause); SBUF = 0XB2;while(TI == 0);TI = 0;//test } } } Play_Flag = ~Play_Flag; SBUF = Play_Flag;while(TI == 0);TI = 0;//test EX1 = 1; } void Stop_ISR(void) interrupt 0 { EX0 = 0; if(Key_Stop == 0) { Delayms(15); if(Key_Stop == 0) { AUXR &= 0XEF; TR0 = 0; Count = 0; Times = 0; EX1 = 0; Play_Flag = 0; WAIT = 1; while(!Key_Stop); SBUF = 0XAA;while(TI == 0);TI = 0;//test } } EX0 = 1; } void Timer2_ISR(void) interrupt 12 using 2 { Count++; if(Count == Times) { AUXR &= 0XEF;TR0 = 0; WAIT = 1; Count = 0; } } void Timer0_ISR(void) interrupt 1 using 0 //18.432 { Voice_Frequency = !Voice_Frequency; } void System_Init(void) //@22.1184MHz 115200bps T0×°³õÖµ T2×°³õÖµ { //³õʼ»¯´®¿Ú SCON = 0X50; AUXR |= 0x40; //¶¨Ê±Æ÷1ʱÖÓ1Tģʽ AUXR &= 0xFE; //´®¿Ú1Ñ¡¶¨Ê±Æ÷1Ϊ²¨ÌØÂÊ·¢ÉúÆ÷ TMOD &= 0x0F; //¶¨Ê±Æ÷1¹¤×÷·½Ê½16λÖØ×° TL1 = 0xD0; // TH1 = 0xFF; //T1³õÖµ,115200bps TR1 = 1; ET1 = 0; //³õʼ»¯¶¨Ê±Æ÷0 AUXR |= 0X80; TMOD &= 0XF0; TL0 = 0x9A; //T0³õÖµ,ƵÂÊ1000HZ TH0 = 0xA9; // TF0 = 0; TR0 = 0; //¹Ø±Õ¶¨Ê±Æ÷0 ET0 = 1; //ÔÊÐí¶¨Ê±Æ÷0ÖÐ¶Ï //³õʼ»¯¶¨Ê±Æ÷2 AUXR |= 0x04; T2L = 0x9A; //T2³õÖµ,¶¨Ê±1MS T2H = 0xA9; // IE2 |= 0X04; //ÔÊÐí¶¨Ê±Æ÷2ÖÐ¶Ï //³õʼ»¯ÍâÖжÏ0/1ΪµÍµçƽ´¥·¢ TCON |= 0x05; IT0 = 1; IT1 = 1; EX0 = 1; EX1 = 1; IP = 0x05; //Á½¸öÍⲿÖжÏÓÅÏȼ¶×î¸ß EA = 1; } void Delay_ms(uint ms) { uint i; for(i=ms;i>0;i--) { Delay1ms(); } } void Delayms(uint ms) { uint i; for(i=ms;i>0;i--) { Delay1ms(); } } void Delay1ms() //@22.1184MHz { unsigned char i, j; _nop_(); _nop_(); i = 22; j = 128; do { while (--j); } while (--i); } 补充内容 (2017-1-23 20:56): 怎么办呀,就卡这儿动不了了.
|
|
相关推荐
2个回答
|
|
wa,你更牛。。。。。。。。。。。。。
|
|
|
|
风声 楼主好厉害呀
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
304 浏览 0 评论
使用Keil建立完整的工程,并使用外部中断0触发数码管显示903
842 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
1131 浏览 0 评论
876 浏览 0 评论
914 浏览 1 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11838 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 03:54 , Processed in 0.644913 second(s), Total 76, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号