自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(1)
  • 资源 (1)
  • 收藏
  • 关注

原创 函数的引用和值拷贝

举个例子从代码说起 #include struct HString { char *ch; // 若是非空串,则按串长分配存储区,否则ch为NULL int length; // 串长度 }; void StrPrint(HString T) { // 输出T字符串。另加 int i; for(i=0;i<T.length;i++) printf("%c

2015-05-31 10:34:18 121

单片机 仿真 播放音乐

5 3主程序 #include&lt;reg51 h&gt; #include &lt;intrins h&gt; #define uchar unsigned char #define uint unsigned int #define GPIO KEY P0 sbit beep P3^1; sbit gao P3^3; sbit zhong P3^4; sbit di P3^5; void delayms uint xms ; void duliscan void ; uchar keyscan void ; void init void ; void playkey void ; void playmusic void ; void display uchar weitu uchar num ; uchar BTH0 BTL0;uchar a 1; uchar flag 0;uchar time 1; uchar m; uchar music; code unsigned char sszymmh[] {6 2 3 5 2 1 3 2 2 5 2 2 1 3 2 6 2 1 5 2 1 6 2 4 3 2 2 5 2 1 6 2 1 5 2 2 3 2 2 1 2 1 6 1 1 5 2 1 3 2 1 2 2 4 2 2 3 3 2 1 5 2 2 5 2 1 6 2 1 3 2 2 2 2 2 1 2 4 5 2 3 3 2 1 2 2 1 1 2 1 6 1 1 1 2 1 5 1 6 0 0 0 }; uchar code xiaopingguo[] {3 3 2 1 3 2 2 3 2 6 2 2 3 3 2 2 3 2 1 3 2 2 3 2 6 2 4 3 3 2 1 3 2 2 3 2 2 3 2 5 3 1 3 3 1 7 2 2 1 3 2 1 3 1 7 2 1 6 2 2 7 2 1 1 3 1 2 2 2 5 2 2 6 3 2 5 3 2 3 3 2 3 3 2 3 3 2 2 3 2 1 3 2 2 3 1 3 3 1 2 3 1 3 3 1 2 3 1 5 3 1 5 3 8 0 0 0 }; uchar code tableH[] {0xff 0xf8 0xf9 0xfa 0xfa 0xfb 0xfb 0xfc 0xfc 0xfc 0xfd 0xfd 0xfd 0xfd 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xff }; uchar code tableL[] {0xff 0x8c 0x5b 0x15 0x67 0x04 0x90 0x0c 0x44 0xac 0x09 0x34 0x82 0xc8 0x06 0x22 0x56 0x85 0x88 0xc1 0xe4 0x02 }; uchar code table[] {0x3f 0x06 0x5b 0x4f 0x66 0x6d 0x7d 0x07 0x08 0x48 0x49}; uchar code wei[] {0x07 0x0b 0x0d 0x0e}; void main 主程序 { init ; while 1 { if flag 0 { duliscan ; playkey ; } else { time 1; playmusic ; } } } void delayms uint xms 毫秒延时 { uint i j; for i xms;i&gt;0;i for j 120;j&gt;0;j ; } void duliscan 独立键盘扫描(高中低音切换) { if gao 0 { delayms 10 ; if gao 0 { a 2; while gao ; } } if zhong 0 { delayms 10 ; if zhong 0 { a 1; while zhong ; } } if di 0 { delayms 10 ; if di 0 { a 0; while di ; } } } uchar keyscan void { uchar i j temp Buffer[4] {0xfe 0xfd 0xfb 0xf7}; for j 0; j &lt; 4; j++ 循环四次 扫描四行 { P1 Buffer[j]; 在低四位分别输出一个低电平 nop ; temp 0x80; 计划先读出P1 7位 for i 0; i &lt; 4; i++ 循环四次 检查四列 { if P1 &amp; temp 从高四位 截取1位 { return i + j 4 ; 返回取得的按键值 } temp &gt;&gt; 1; 换右边一位 } } return 16; 没有键按下就返回16 } void playkey { uchar Key Temp1 Key Temp2; uchar Key Value 16; while 1 { TR0 0; T0工作停 暂不发音 Key Temp1 keyscan ; 第一次读入按键 if Key Temp1 16 { 有键按下 Key Temp2 keyscan ; 再读一次 if Key Temp1 Key Temp2 两次相等 { Key Value Key Temp1; 就确认下来 display 2 Key Value+1 ; display 3 a+8 ; BTH0 tableH[Key Value+7 a+1]; BTL0 tableL[Key Value+7 a+1]; TH0 BTH0; TL0 BTL0; 根据键值 取出定时半周期的初始值 TR0 1; 启动定时器T0 发音 while keyscan &lt; 16 ; 等待释放 beep 1; 停止发音 } } } } void playmusic 音乐播放 { uchar n 0; while time { if music+n 0 { n 0; } else { duliscan ; switch a { case 2:music sszymmh; case 1:music xiaopingguo; case 0:music xiaopingguo; } m music+n +7 music+n+1 1 ; BTH0 tableH[m]; BTL0 tableL[m]; time music+n+2 ; n n+3; TH0 BTH0; TL0 BTL0; TR0 1;delayms 187 time ;TR0 0; } } } void init { TMOD 0x01; EA 1; IT0 1; EX0 1; ET0 1; } void time0 interrupt 1 { TH0 BTH0; TL0 BTL0; beep beep; } void int0 interrupt 0 { flag flag; } void display uchar weitu uchar num { P2 wei[weitu]; P0 table[num]; delayms 5 ;">5 3主程序 #include&lt;reg51 h&gt; #include &lt;intrins h&gt; #define uchar unsigned char #define uint unsigned int #define GPIO KEY P0 sbit beep P3^1; sbit gao P3^3; sbit zhong P3^4; sbit di P3^5; void delayms uint xms ; void duliscan void ; uchar keyscan void ; void init void ; void playkey voi [更多]

2015-03-21

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除