📄 8.s
字号:
.module _8.c
.area lit(rom, con, rel)
_sound::
.byte 35,36
.byte 37,'D
.byte 'E,36
.byte 35,34
.byte 'B,64
.byte 64,35
.byte 34,33
.byte 'A,40
.byte 'H,35
.byte 37,'E
.byte 64,64
.byte 33,33
.byte 'B,33
.byte 33,'A
.byte 32,40
.byte 'G,38
.byte 23,22
.byte 21,'E
.byte 64,49
.byte 17,33
.byte 33,33
.byte 34,'B
.byte 64,32
.byte 35,35
.byte 36,37
.byte 36,35
.byte 36,37
.byte 38,35
.byte 35,'B
.byte 'B,64
.byte 35,34
.byte 33,'A
.byte 40,40
.byte 40,35
.byte 37,'E
.byte 'E,64
.byte 32,37
.byte 'F,40
.byte 40,'H
.byte 32,41
.byte 'G,38
.byte 23,22
.byte 21,'E
.byte 37,37
.byte 38,40
.byte 24,22
.byte 38,40
.byte 38,40
.byte 25,25
.byte 'I,'I
.byte 32,37
.byte 42,24
.byte 25,41
.byte 40,22
.byte 23,22
.byte 21,37
.byte 37,40
.byte 41,42
.byte 41,'H
.byte 40,'H
.byte 44,'L
.byte 'L,64
.byte 42,44
.byte 28,26
.byte 42,42
.byte 41,'J
.byte 43,42
.byte 'J,'J
.byte 64,42
.byte 41,41
.byte 40,40
.byte 38,'H
.byte 41,38
.byte 'E,'E
.byte 64,37
.byte 37,38
.byte 33,24
.byte 22,38
.byte 40,38
.byte 40,41
.byte 'I,'I
.byte 32,37
.byte 40,41
.byte 42,41
.byte 'I,40
.byte 'H,44
.byte 'L,'L
.byte 64,42
.byte 44,21
.byte 26,42
.byte 42,41
.byte 'J,43
.byte 42,'J
.byte 'J,64
.byte 42,41
.byte 41,40
.byte 40,38
.byte 40,40
.byte 41,38
.byte 'E,'E
.byte 64,37
.byte 37,38
.byte 40,40
.byte 38,42
.byte 25,24
.byte 40,24
.byte 25,'H
.byte 'H,64
.byte 64,64
.byte 64,40
.byte 'H,41
.byte 40,40
.byte 42,26
.byte 26,26
.byte 24,64
.byte 32,38
.byte 40,40
.byte 40,38
.byte 40,'H
.byte 38,37
.byte 'E,'E
.byte 64,64
.byte 64,40
.byte 'H,40
.byte 40,28
.byte 29,45
.byte 44,40
.byte 40,40
.byte 32,38
.byte 25,26
.byte 41,25
.byte 24,40
.byte 40,38
.byte 33,41
.byte 'I,'I
.byte 64,32
.byte 40,41
.byte 42,'J
.byte 'J,32
.byte 37,40
.byte 41,'H
.byte 'H,'H
.byte 37,37
.byte 38,40
.byte 40,38
.byte 42,25
.byte 24,40
.byte 24,25
.byte 'I,'I
.byte 64,64
.byte 37,40
.byte 42,'J
.byte 41,40
.byte 'H,40
.byte 38,'F
.byte 40,'E
.byte 37,40
.byte 42,'J
.byte 41,40
.byte 'H,40
.byte 41,'I
.byte 42,'I
.byte 64,42
.byte 'J,43
.byte 'L,64
.byte 61,29
.byte 45,45
.byte 'L,64
.byte 42,'J
.byte 44,'H
.byte 40,42
.byte 41,'F
.byte 37,'H
.byte 64,42
.byte 42,'J
.byte 42,42
.byte 'J,42
.byte 44,40
.byte 41,'J
.byte 'J,43
.byte 43,43
.byte 43,43
.byte 42,42
.byte 42,42
.byte 41,41
.byte 40,'I
.byte 'L,42
.byte 42,'J
.byte 42,42
.byte 'J,42
.byte 44,40
.byte 41,'J
.byte 'J,43
.byte 43,43
.byte 43,43
.byte 42,42
.byte 42,44
.byte 44,43
.byte 41,'H
.byte 'H,'J
.byte 42,41
.byte 40,41
.byte 40,39
.byte 'F,'F
.byte 'F,'F
.byte 'K,43
.byte 42,41
.byte 40,41
.byte 43,'J
.byte 'J,'J
.byte 'K,43
.byte 42,'I
.byte 41,43
.byte 'J,42
.byte 40,'F
.byte 'H,'G
.byte 'J,41
.byte 40,39
.byte 40,'F
.byte 'F,'F
.byte 'F,'J
.byte 42,41
.byte 40,41
.byte 40,39
.byte 'F,'F
.byte 'F,'F
.byte 'K,43
.byte 42,41
.byte 40,41
.byte 43,'J
.byte 'J,'J
.byte 'K,43
.byte 42,'I
.byte 41,43
.byte 'J,42
.byte 40,'F
.byte 'H,'G
.byte 'J,41
.byte 40,39
.byte 40,'F
.byte 'F,'F
.byte 'F,'C
.byte 'C,'E
.byte 'I,'I
.byte 'I,'H
.byte 'H,'E
.byte 'D,'D
.byte 'D,'C
.byte 'C,'C
.byte 'C,'D
.byte 'E,'F
.byte 'F,'F
.byte 'E,'E
.byte 'E,'C
.byte 'C,'E
.byte 'I,'I
.byte 'I,'H
.byte 'H,'E
.byte 'D,'D
.byte 'D,'C
.byte 'C,'E
.byte 'E,'F
.byte 'G,'H
.byte 'H,'H
.byte 'H,'H
.byte 'H,'I
.byte 'I,'E
.byte 'G,'F
.byte 'E,'C
.byte 'C,'E
.byte 'H,'H
.byte 'H,'F
.byte 'F,'H
.byte 'I,'I
.byte 'H,'G
.byte 'G,'G
.byte 'E,'E
.byte 'E,'C
.byte 'C,'E
.byte 'I,'I
.byte 'I,'H
.byte 'H,'E
.byte 'D,'D
.byte 'D,'C
.byte 'C,'E
.byte 'E,'F
.byte 'G,'H
.byte 'H,'H
.byte 'H,64
.byte 64,'E
.byte 'H,'J
.byte 'J,'J
.byte 'J,'J
.byte 'J,'I
.byte 'J,'I
.byte 'H,'H
.byte 'H,'H
.byte 'H,'E
.byte 'H,'J
.byte 'J,'H
.byte 'J,'L
.byte 'L,'K
.byte 'J,'I
.byte 'I,'I
.byte 'I,'I
.byte 'L,'K
.byte 'J,'J
.byte 'J,'I
.byte 'H,'H
.byte 'I,'J
.byte 'L,'K
.byte 'K,'K
.byte 'K,'K
.byte 'F,'F
.byte 'E,'E
.byte 'E,'G
.byte 'H,'I
.byte 'I,'J
.byte 'I,'H
.byte 'H,'H
.byte 'H,'H
.byte 'H,0
.byte 0
.dbfile D:\xij\demo\demo_diy02-8a\1\C语言\02-8A-8\8.c
.dbsym e sound _sound A[645:645]kc
_TONETABLE::
.word 64580
.word 64684
.word 64777
.word 64820
.word 64898
.word 64968
.word 65030
.word 65058
.word 65110
.word 65157
.word 65178
.word 65217
.word 65252
.word 65283
.word 65297
.dbsym e TONETABLE _TONETABLE A[30:15]ki
.area text(rom, con, rel)
.dbfile D:\xij\demo\demo_diy02-8a\1\C语言\02-8A-8\8.c
.dbfunc e delay_us _delay_us fV
; time -> R16,R17
.even
_delay_us::
.dbline -1
.dbline 90
; //10. I/O端口的又一应用-发出乐曲声。
; //PD.0端口开关控制音乐程序。
; //你能把你最喜欢的乐曲输入单片机吗?
; // www.sl.com.cn
; // Target : M48 Crystal: 8.0000Mhz
;
; #include <iom48v.h>
; #include <macros.h>
; /* 音乐数据 */
; /* 四分之一拍为0x10, 二分之一拍为0x20, 一拍为0x40*/
; /* 低1-1 2-2 3-3 4-4 5-5 6-6 7-7 */
; /* 中1-8 2-9 3-A 4-B 5-C 6-D 7-E */
; /* 高1-F*/
;
; const unsigned char sound[]={ //乐曲数据表
; 0x23,0x24,0x25,0x44,0x45,0x24,0x23,0x22,0x42,0x40,0x40,0x23,0x22,0x21,0x41,0x28,
; 0x48,0x23,0x25,0x45,0x40,0x40,0x21,0x21,0x42,0x21,0x21,0x41,0x20,0x28,0x47,0x26,
; 0x17,0x16,0x15,0x45,0x40,0x31,0x11,0x21,0x21,0x21,0x22,0x42,0x40,0x20,0x23,0x23,
; 0x24,0x25,0x24,0x23,0x24,0x25,0x26,0x23,0x23,0x42,0x42,0x40,0x23,0x22,0x21,0x41,
; 0x28,0x28,0x28,0x23,0x25,0x45,0x45,0x40,0x20,0x25,0x46,0x28,0x28,0x48,0x20,0x29,
; 0x47,0x26,0x17,0x16,0x15,0x45,0x25,0x25,0x26,0x28,0x18,0x16,0x26,0x28,0x26,0x28,
; 0x19,0x19,0x49,0x49,0x20,0x25,0x2a,0x18,0x19,0x29,0x28,0x16,0x17,0x16,0x15,0x25,
; 0x25,0x28,0x29,0x2a,0x29,0x48,0x28,0x48,0x2c,0x4c,0x4c,0x40,0x2a,0x2c,0x1c,0x1a,
; 0x2a,0x2a,0x29,0x4a,0x2b,0x2a,0x4a,0x4a,0x40,0x2a,0x29,0x29,0x28,0x28,0x26,0x48,
; 0x29,0x26,0x45,0x45,0x40,0x25,0x25,0x26,0x21,0x18,0x16,0x26,0x28,0x26,0x28,0x29,
; 0x49,0x49,0x20,0x25,0x28,0x29,0x2a,0x29,0x49,0x28,0x48,0x2c,0x4c,0x4c,0x40,0x2a,
; 0x2c,0x15,0x1a,0x2a,0x2a,0x29,0x4a,0x2b,0x2a,0x4a,0x4a,0x40,0x2a,0x29,0x29,0x28,
; 0x28,0x26,0x28,0x28,0x29,0x26,0x45,0x45,0x40,0x25,0x25,0x26,0x28,0x28,0x26,0x2a,
; 0x19,0x18,0x28,0x18,0x19,0x48,0x48,0x40,0x40,0x40,0x40,0x28,0x48,0x29,0x28,0x28,
; 0x2a,0x1a,0x1a,0x1a,0x18,0x40,0x20,0x26,0x28,0x28,0x28,0x26,0x28,0x48,0x26,0x25,
; 0x45,0x45,0x40,0x40,0x40,0x28,0x48,0x28,0x28,0x1c,0x1d,0x2d,0x2c,0x28,0x28,0x28,
; 0x20,0x26,0x19,0x1a,0x29,0x19,0x18,0x28,0x28,0x26,0x21,0x29,0x49,0x49,0x40,0x20,
; 0x28,0x29,0x2a,0x4a,0x4a,0x20,0x25,0x28,0x29,0x48,0x48,0x48,0x25,0x25,0x26,0x28,
; 0x28,0x26,0x2a,0x19,0x18,0x28,0x18,0x19,0x49,0x49,0x40,0x40,
;
; 0x25,0x28,0x2A,0x4A,0x29,0x28,0x48,0x28,
; 0x26,0x46,0x28,0x45,0x25,0x28,0x2A,0x4A,
; 0x29,0x28,0x48,0x28,0x29,0x49,0x2A,0x49,
; 0x40,0x2A,0x4A,0x2B,0x4C,0x40,0x3D,0x1D,
; 0x2D,0x2D,0x4C,0x40,0x2A,0x4A,0x2C,0x48,
; 0x28,0x2A,0x29,0x46,0x25,0x48,0x40,
;
; 0x2a,0x2a,0x4a,0x2a,0x2a,0x4a,0x2a,0x2c,0x28,0x29,
; 0x4a,0x4a,0x2b,0x2b,0x2b,0x2b,0x2b,0x2a,0x2a,0x2a,
; 0x2a,0x29,0x29,0x28,0x49,0x4c,0x2a,0x2a,0x4a,0x2a,
; 0x2a,0x4a,0x2a,0x2c,0x28,0x29,0x4a,0x4a,0x2b,0x2b,
; 0x2b,0x2b,0x2b,0x2a,0x2a,0x2a,0x2c,0x2c,0x2b,0x29,
; 0x48,0x48,
;
; 0x4a,0x2a,0x29,0x28,0x29,0x28,0x27,0x46,0x46,0x46,
; 0x46,0x4b,0x2b,0x2a,0x29,0x28,0x29,0x2b,0x4a,0x4a,
; 0x4a,0x4b,0x2b,0x2a,0x49,0x29,0x2b,0x4a,0x2a,0x28,
; 0x46,0x48,0x47,0x4a,0x29,0x28,0x27,0x28,0x46,0x46,
; 0x46,0x46,0x4a,0x2a,0x29,0x28,0x29,0x28,0x27,0x46,
; 0x46,0x46,0x46,0x4b,0x2b,0x2a,0x29,0x28,0x29,0x2b,
; 0x4a,0x4a,0x4a,0x4b,0x2b,0x2a,0x49,0x29,0x2b,0x4a,
; 0x2a,0x28,0x46,0x48,0x47,0x4a,0x29,0x28,0x27,0x28,
; 0x46,0x46,0x46,0x46,
;
; 0x43,0x43,0x45,0x49,0x49,0x49,0x48,0x48,0x45,0x44,
; 0x44,0x44,0x43,0x43,0x43,0x43,0x44,0x45,0x46,0x46,
; 0x46,0x45,0x45,0x45,0x43,0x43,0x45,0x49,0x49,0x49,
; 0x48,0x48,0x45,0x44,0x44,0x44,0x43,0x43,0x45,0x45,
; 0x46,0x47,0x48,0x48,0x48,0x48,0x48,0x48,0x49,0x49,
; 0x45,0x47,0x46,0x45,0x43,0x43,0x45,0x48,0x48,0x48,
; 0x46,0x46,0x48,0x49,0x49,0x48,0x47,0x47,0x47,0x45,
; 0x45,0x45,0x43,0x43,0x45,0x49,0x49,0x49,0x48,0x48,
; 0x45,0x44,0x44,0x44,0x43,0x43,0x45,0x45,0x46,0x47,
; 0x48,0x48,0x48,0x48,0x40,0x40,
;
; 0x45,0x48,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x49,0x4a,
; 0x49,0x48,0x48,0x48,0x48,0x48,0x45,0x48,0x4a,0x4a,
; 0x48,0x4a,0x4c,0x4c,0x4b,0x4a,0x49,0x49,0x49,0x49,
; 0x49,0x4c,0x4b,0x4a,0x4a,0x4a,0x49,0x48,0x48,0x49,
; 0x4a,0x4c,0x4b,0x4b,0x4b,0x4b,0x4b,0x46,0x46,0x45,
; 0x45,0x45,0x47,0x48,0x49,0x49,0x4a,0x49,0x48,0x48,
; 0x48,0x48,0x48,0x48,
;
; 0x00,0x00
; };
;
; /* 音阶表 */
; const unsigned int TONETABLE[15]={
; 64580,64684,64777,64820,64898,64968,65030,65058,
; 65110,65157,65178,65217,65252,65283,65297
; };
; /* 音阶重装常数 */
; /* 微秒级延时程序 */
; void delay_us(int time)
; {
L2:
.dbline 92
; do
; {
.dbline 93
; time--;
subi R16,1
sbci R17,0
.dbline 94
; }
L3:
.dbline 95
; while (time>1);
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlt L2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r time 16 I
.dbend
.dbfunc e delay_ms _delay_ms fV
; time -> R20,R21
.even
_delay_ms::
rcall push_gset1
movw R20,R16
.dbline -1
.dbline 100
; }
;
; /* 毫秒级延时程序 */
; void delay_ms(unsigned int time)
; {
rjmp L7
L6:
.dbline 102
.dbline 103
ldi R16,1000
ldi R17,3
rcall _delay_us
.dbline 104
subi R20,1
sbci R21,0
.dbline 105
L7:
.dbline 101
; while(time!=0)
cpi R20,0
cpc R20,R21
brne L6
X0:
.dbline -2
L5:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r time 20 i
.dbend
.area vector(rom, abs)
.org 26
rjmp _timer1_ovf_isr
.area text(rom, con, rel)
.dbfile D:\xij\demo\demo_diy02-8a\1\C语言\02-8A-8\8.c
.dbfunc e timer1_ovf_isr _timer1_ovf_isr fV
.even
_timer1_ovf_isr::
st -y,R2
st -y,R3
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 112
; {
; delay_us(1000);
; time--;
; }
; }
;
; unsigned int toneconst;
; #pragma interrupt_handler timer1_ovf_isr:14
; //iv_TIMER1_OVF
; void timer1_ovf_isr(void)
; {
.dbline 113
; TCNT1=toneconst;
lds R2,_toneconst
lds R3,_toneconst+1
sts 132+1,R3
sts 132,R2
.dbline 114
; PORTD^=0x08;
ldi R24,8
in R2,0xb
eor R2,R24
out 0xb,R2
.dbline -2
L9:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R3,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e music _music fV
; sound_add -> R20,R21
; temp1 -> R22
; temp -> R10
.even
_music::
rcall push_gset3
.dbline -1
.dbline 117
; }
; void music(void)
; {
.dbline 119
; unsigned char temp,temp1;
; unsigned int sound_add=0;
clr R20
clr R21
.dbline 120
; TCCR1A = 0x00;
clr R2
sts 128,R2
.dbline 121
; TCCR1B =(1<<CS11);//8分频
ldi R24,2
sts 129,R24
.dbline 122
; temp1 = sound[sound_add];
ldi R24,<_sound
ldi R25,>_sound
movw R30,R20
add R30,R24
adc R31,R25
lpm R22,Z
rjmp L12
L11:
.dbline 124
; while(temp1!=0)
; {
.dbline 125
; temp=temp1;
mov R10,R22
.dbline 126
; temp&=0x0f;
mov R24,R10
andi R24,15
mov R10,R24
.dbline 127
; if(temp!=0)
tst R24
breq L14
.dbline 128
; {
.dbline 129
; TIMSK1|=(1<<TOIE1);//根据SOUNDTABLE中数据的低四位选择音调频率
lds R24,111
ori R24,1
sts 111,R24
.dbline 130
; temp--;
dec R10
.dbline 131
; toneconst=TONETABLE[temp];
ldi R24,2
mul R24,R10
movw R30,R0
ldi R24,<_TONETABLE
ldi R25,>_TONETABLE
add R30,R24
adc R31,R25
lpm R0,Z+
lpm R1,Z
movw R30,R0
sts _toneconst+1,R31
sts _toneconst,R30
.dbline 132
; TCNT1=toneconst;
movw R2,R30
sts 132+1,R3
sts 132,R2
.dbline 133
; }
L14:
.dbline 134
mov R10,R22
.dbline 135
mov R24,R10
swap R24
andi R24,#0x0F
.dbline 136
andi R24,15
mov R10,R24
.dbline 137
ldi R24,129
mul R24,R10
movw R16,R0
rcall _delay_ms
.dbline 138
lds R24,111
andi R24,254
sts 111,R24
.dbline 139
subi R20,255 ; offset = 1
sbci R21,255
.dbline 140
ldi R24,<_sound
ldi R25,>_sound
movw R30,R20
add R30,R24
adc R31,R25
lpm R22,Z
.dbline 141
L12:
.dbline 123
tst R22
breq X1
rjmp L11
X1:
.dbline 142
; temp=temp1;
; temp>>=4;
; temp&=0x0f;
; delay_ms(temp*129);//根据SOUNDTABLE中数据的高四位*5后,为音调持续时间
; TIMSK1&=~(1<<TOIE1);
; sound_add++;
; temp1 = sound[sound_add];
; }
; delay_ms(1000);
ldi R16,1000
ldi R17,3
rcall _delay_ms
.dbline -2
L10:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r sound_add 20 i
.dbsym r temp1 22 c
.dbsym r temp 10 c
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 146
; }
; /* 主程序 */
; void main(void)
; {
.dbline 147
; DDRD=0xFB;
ldi R24,251
out 0xa,R24
.dbline 148
; PORTD=0xff;
ldi R24,255
out 0xb,R24
.dbline 151
; // DDRC=0x01;
; //PORTC=0xff;
; SEI();
sei
L17:
.dbline 153
L18:
.dbline 153
;
; while(PIND & 0x04);//等待PD2按键按下
sbic 0x9,2
rjmp L17
rjmp L21
L20:
.dbline 156
.dbline 157
rcall _music
.dbline 158
L21:
.dbline 155
rjmp L20
X2:
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile D:\xij\demo\demo_diy02-8a\1\C语言\02-8A-8\8.c
_toneconst::
.blkb 2
.dbsym e toneconst _toneconst i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -