⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 解码控制程序.asm

📁 mp3的汇编代码。包括对sta013的控制
💻 ASM
字号:
;MP3详细内容请查阅logic电子技术网 http://www.logicth.com
;罗进2004.4深圳大学
;http://www.pjrc.com/tech/mp3/sta013.html
;程序和原理图基本上是按上面网里的来设计的。

;主要包括了: 首先对解码芯片sta103的初始化,然后从闪存中读出mp3数据并送入sta013中去

; These lines configure which pins are connected to the STA013.
;http://www.pjrc.com/tech/mp3/sta013.html

        sda_pin equ p1.0           ;P1.0 = I2C SDA, Pin 3

        scl_pin equ p1.1           ;P1.1 = I2C SCL, Pin 4

        reset_pin equ p1.7         ;P1.7 = RESET, Pin 26

        clock_pin equ p1.5         ;P1.5 = SCKR, Pin 6

        data_pin equ p1.2          ;P1.2 = SDI, Pin 5

        data_req_pin equ p1.6      ;P1.6 = DATA_REQ, Pin 28



;These lines configure which pins are connected to the tc58v64bft,(64m闪存芯片)
        RYBY   EQU P2.1
        RE     EQU P2.2
        CE     EQU P2.3
        CLE    EQU P2.4
        ALE    EQU P2.5
        WE     EQU P2.6
        WP     EQU P2.7


; This little header tells PM2 that this is a program.  PM2
; recognizes these bytes and makes this program appear in
; its run menu.  The actual executable code begins at 2040.


	;reset the STA013 chip
main:
	clr	reset_pin	;reset the STA013
	nop
	nop
	nop
	nop
	nop
	nop
	setb	reset_pin	;let it start up

	;read the ident register, make sure it's 0xAC
        clr  p1.4                   ; 调试时通过p1.3,p1.4 的熄灭和亮来监视单片机的工作情况的
        setb p1.3
	mov	r4, #1
	acall	sta013_read
	jc	d1
        ajmp j1
   d1:  clr p1.3
   j1:  mov	a, r3
        cjne    r3,#0ACh,  d2
        ajmp j2
   d2:  clr p1.3
   j2:




	;check to see if the sta013 data file is loaded into memory

;	mov	dptr, #sta013_config_location
;	acall	check_data_file
 ;       jc      d3
 ;       ajmp j3
 ;   d3: clr p1.4
 ;   j3:
  ;      mov   r4,#16
   ;     mov   r3,#1
    ;    acall  sta013_write
    ;    mov   r4,#16
    ;    acall  sta013_read
    ;    jc   d7
     ;   ajmp j7
   ; d7: clr p1.4
    ;j7: mov   a,r3
    ;    cjne  r3,#0,d3
    ;    ajmp  j3
   ; d3: clr p1.4
   ; j3:

        ;now attempt to download the config data
	;to the STA013 chip

	acall	sta013_config
        setb  p1.4
   	jc	d4
        ajmp j4
    d4: clr  p1.4
    j4:





	;tell the STA013 to start running

	mov	r4, #114
	mov	r3, #1
	acall	sta013_write		;run command
	jc	d5
        ajmp    j5
    d5: clr     p1.4
    j5:



	;tell the STA013 to enter play mode

	mov	r4, #19
	mov	r3, #1
	acall	sta013_write		;begin play
        jc    d6
        ajmp  j6
    d6: clr p1.4
    j6:



      ;read from e2prom chip tc58v64bft,
next:   clr ALE
        setb RE
        clr CE
        clr wp
        setb  CLE
        clr WE
        mov p0,#00h   ;write command in mode read 1
        setb WE
        clr  CLE
        setb ALE
        clr WE
        mov p0,#00h   ;write column address from A0 to A7 in value0
        setb WE
        clr WE
        mov p0,#00h   ;write page address from A9 to A16 in value 0
        setb WE
        clr WE
        mov p0,#00h   ;write page address from A17 to A22 in value 0
        setb WE
        clr ALE
        MOV P0,#0ffH
        clr	clock_pin


	;now let's send it some MP3 data !!
xmit_mp3_clip:
	;mov	dptr, #mp3_clip_location
send_loop:
	;we could get stuck here forever if something goes
	;wrong with the STA013 and it stops requesting bits
	;jb	ri, xmit_abort
        clr     a
	jnb	data_req_pin, send_loop
        clr     RE                      ;data out
        jnb     ryby,$
        mov     a, p0
        setb    RE
	;clr	a
	;movc	a, @a+dptr
	;inc	dptr
        clr     p1.3
	rlc	a
	mov	data_pin, c		;send bit 7
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 6
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 5
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 4
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 3
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 2
	setb	clock_pin
    	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 1
	setb	clock_pin
	clr	clock_pin
	rlc	a
	mov	data_pin, c		;send bit 0
	setb	clock_pin
	clr	clock_pin
	clr	c
        ajmp     xmit_mp3_clip



sta013_config: mov dptr,#00h
	mov	dptr, #sta013_config_location
	;acall	get_16_bits	;r6/r7 has cksum addr
	;mov	a, r6
	;anl	a, #11111110b
	;mov	r6, a
         mov    r6, #00h
         mov    r7, #00h
cfgloop:acall	get_8_bits	;get the address
	mov	r4, a
	acall	get_8_bits	;get the data byte
	mov	r3, a
        ;mov     30h, a
	acall	sta013_write	;send this byte to its address
	;cjne	a, dpl, cfgloop	;send all the bytes

        ;acall   sta013_read
        ;mov     a, r3
        ;cjne    a,30h,lu1

   jin: cjne    r4,#24,cfgloop
	ret
   lu1: clr p1.4
        ajmp jin


	;checks for a data file in memory @dptr.  The test
	;is simple... the first 2 bytes are the location of
	;the file's last two bytes, that are a simple 16 bit
	;checksum of all the data bytes

check_data_file:
	acall	get_16_bits	;r6/r7 has cksum addr
	clr	a
	mov	r0, a		;r0/r1 will hold the computed cksum
	mov	r1, a
ckloop:	acall	get_8_bits	;get each byte
	add	a, r0		;add it to the cksum
	mov	r0, a
	clr	a
	addc	a, r1
	mov	r1, a
	mov	a, r6
	cjne	a, dpl, ckloop	;check all the data bytes
	mov	a, r7
	cjne	a, dph, ckloop
	acall	get_8_bits	;get cksum lsb
	mov	b, r0
	cjne	a, b, ckfail
	acall	get_8_bits	;get cksum msb
	mov	b, r1
	cjne	a, b, ckfail
	clr	c
	ret
ckfail:	setb	c
	ret



get_8_bits:
	clr	a
	movc	a, @a+dptr
	inc	dptr
	ret

get_16_bits:
	acall	get_8_bits
	mov	r6, a
	acall	get_8_bits
	mov	r7, a
	ret

	;read a byte from the sta013 at address r4 and return it
	;in r3.  Carry cleared if success, set for fail
sta013_read:
	acall	i2c_start
	mov	a, #10000110b
	acall	i2c_write		;wr device addr, wr cmd
	jc	s013r3
	mov	a, r4
	acall	i2c_write		;wr addr of data to read
	jc	s013r3
	;acall	i2c_stop
	acall	i2c_start
	mov	a, #10000111b		;wr device addr, rd cmd
	acall	i2c_write
	jc	s013r3
	acall	i2c_read
	mov	r3, a
	clr	c
s013r3: ajmp    i2c_stop


	;write a byte in r3 to the sta013 at address r4
	;Carry cleared if success, set for fail
sta013_write:
	acall	i2c_start
	mov	a, #10000110b
	acall	i2c_write
	jc	s013w3
	mov	a, r4
	acall	i2c_write
	jc	s013w3


	mov	a, r3
	acall	i2c_write


s013w3: ajmp	i2c_stop	;i2c stop doesn't change carry bit






i2c_write:  ;writes acc to i2c bus, return ack bit in Carry
        mov     r5, #8
        clr     scl_pin
i2cw:   rlc     a
        mov     sda_pin, c
	nop
	nop
        setb    scl_pin
	nop
	nop
        clr    scl_pin
        djnz    r5, i2cw
        rlc     a
        setb    sda_pin
	nop
	nop
        setb    scl_pin
	nop
	nop
        mov     c, sda_pin
        clr     scl_pin
        ret


i2c_read:  ;reads i2c bus into acc, send ack bit from Carry
	;rlc	a
        clr     a
        mov     r5, #8
        setb    sda_pin
i2cr:   nop
	nop
        setb    scl_pin
        nop
	nop
        mov     c, sda_pin
        rlc     a
        clr     scl_pin
        djnz    r5, i2cr
        ret
        mov     sda_pin, c
	nop
	nop
        setb    scl_pin
	nop
	nop
        clr     scl_pin
        ret



i2c_start:
        setb    sda_pin
        setb    scl_pin
	nop
	nop
        clr     sda_pin
	nop
	nop
        clr     scl_pin
        ret

i2c_stop:
        clr     sda_pin
        setb    scl_pin
	nop
	nop
        setb    sda_pin
        nop
        nop
        clr     scl_pin
        ret


sta013_config_location:

 db 58, 1
 db 42, 4
 db 40, 0
 
 .........;
 
 
 db 97, 15
 db 100, 85
 db 101, 85
 db 5, 161
 ;db 13,4
 db 24, 4
 ;db 12, 1
 db 0 ,0








end



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -