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

📄 dt005.asm

📁 at89C51的超级电池管理的程序,可管理3-4节电池,与ds2751用1-wire通讯
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; 海南电台只智能电池程序
; 使用I2C与2083通讯和Uart与PC通讯
; 电路板号HN-4B-S-0512

;AT89C4051 CPU,  11.0592MHz
;== 4051-pc =======================================================
 ;pc向4051发送-------------------------
;pc发送的命令:7 bytes                           B1    B2       B3            B4          B5              B6          B7
;PC发送读命令 read word         串行命令格式:  #A1H, command, not_command,  0,         0,             xrl(B4,B5), #AEH
;PC发送写命令 write word        串行命令格式:  #A2H, command, not_command,  msb,        lsb,            xrl(B4,B5), #AEH
;PC发送读块命令 block read      串行命令格式:  #A3H, command, not_command,  byte_lenth, 0,              xrl(B4,B5), #AEH

;PC发送读Data Flash,  read  DF  串行命令格式:  #A4H, #51h,    not_#51h,     #52h,       flash_location, xrl(B4,B5), #AEH
;PC发送写Data Flash,  write DF  串行命令格式:  #A5H, #50h,    not_#50h,     data,       flash_location, xrl(B4,B5), #AEH

;                                        byte_lenth=n,D1,D2,D3,...,Dn

 ;4051向PC返回数据和命令号------------------------
 ;4051向PC返回word   [read word OK]   串行命令格式:  #B1H, command, not_command,msb,lsb,xrl(B4,B5),#BEH
 ;4051向PC发送写完成 [write word ok]  串行命令格式:  #B2H, command, not_command,msb, lsb, xrl(B4,B5),#BEH
 ;4051向PC发送块     [block read ok]  串行命令格式:  #B3H, command, not_command,byte_lenth,data1,data2,...,datan,xrl(byte_lenth--data1),#BEH
 ;                                        byte_lenth=n,D1,D2,D3,...,Dn
 ; 4051向PC发送DF [read DF ok]  串行命令格式:  #B4H, flash_location, not_flash_location,msb, lsb, xrl(B4,B5),#BEH

 ;4051向PC返回错误-------------------------------
 ;PC命令错误和xor错误,原样返回:#A1H, command, not_command,0,0,xrl,#AEH
 ;                               #A2H, command, not_command,msb,lsb,xrl,#AEH
 ;                               #A3H, command, not_command,0,0,xrl,#AEH

 ;i2c错误,#CxH代替#AxH,向PC发送:#C1H, command, not_command,0,0,xrl,#CEH
 ;                               #C2H, command, not_command,msb,lsb,xrl,#CEH
 ;                               #C3H, command, not_command,0,0,xrl,#CEH


          ;uart数据指针s_point
          ;待发送的字节数占用s_nnn
          ;发送缓冲区: 占用RAM 31H-37H

          ;block指针s_point
          ;待发送的字节数占用s_nnn
          ;block数据缓冲区:占用41h-52h

;=================================================================
                AD_2083     DATA 16H

                scl         BIT P3.3    ;white wire,I2C_CLK, int1   serial clock
                SDA         BIT P1.6    ;blue wire,I2C_DA ,serial data

                lamp_Y	BIT	p1.3		; YELLOW LAMP
                lamp_R	BIT	p1.4		; RED LAMP
;=================================================================
                r_point EQU   20H      ;串口接收指针
                s_point EQU   21H      ;串口发送指针
                s_nnn   equ   22h      ;发送缓冲区中待发送的字节数

                block_xrl equ   23h
                byte_lenth equ 24h     ;data lenth

                DF_location equ 25h

                zdata_h	EQU	26H	; data register
                zdata_l	EQU	27H	; data register
                zdata	EQU	28H	; data register

                pc_cmd_code   EQU 29h   ;PC命令号
                pc_cmd_type   EQU 2ah   ;PC命令类型,A1,A2,A3
                
                i2c_err_num   equ 2bh

                i2c_err bit 2fh.0     ;I2C错误(1)
                cmd_p_flag bit 2fh.1  ;I2C命令处理完成,可向PC发送,(1)。
                cmd_err_flag bit 2fh.2 ;PC cmd err flag

;------------   PROGRAM START   -------------------------
		ORG	0
                LJMP RST
                ORG	3            ;INT0
		RETI
		ORG	0BH          ;T0
                ljmp init_t0
		ORG	13H          ;INT1
		RETI
		ORG	1BH          ;T1
                RETI
                ORG	23H
		LJMP	INTI_SIO     ;SIO

        RST:
      		MOV IE,	#00010000B      ;禁止INT0中断(IE.0),INT1中断(IE.2),T0中断(IE.1),T1中断(IE.3)
                                   ;禁止串口中断(IE.4),和总体中断(IE.7)
                MOV SP,#64H     ; initialize stack pointer
                                ; Initialize AT24Cxx serial bus lines.
		setb	SDA		; high
		setb	SCL		; high

                                ;清内部存储器00H--5FH
                MOV R0,#20H
                MOV A,#0
    CLR_MEM:    MOV @R0,A
                INC R0
                CJNE R0,#63H,CLR_MEM



               MOV P1,#0FFH
               MOV P3,#0FFH

              ;LCALL YS150MS
               LCALL SYSINI

              clr lamp_R
              mov dph,#0
              mov dpl,#0

              mov s_point,#31h
              MOV r_point,#31h
              clr cmd_p_flag
;======================================================
loop_start:
             inc dptr
             mov a,dph
             cjne a,#0ffh,loop_cont
              mov dph,#0
              mov dpl,#0
             cpl lamp_R
loop_cont:   mov c,cmd_p_flag     ;检测命令处理标志
             jc proc_cmd
             ljmp loop_end

proc_cmd:   clr cmd_p_flag     ;清命令处理标志
            mov c,cmd_err_flag
            jnc chk_i2c_err
            lcall sent_pc_err     ;sent_pc_err
            clr cmd_err_flag
            ljmp loop_end

 chk_i2c_err: mov c,i2c_err
              jnc sent_bx
              clr i2c_err
            lcall sent_i2c_err    ;sent_i2c_err
            ljmp loop_end

 sent_bx:   ;检查当前的命令类型,pc_cmd_type(A1)
            mov a,pc_cmd_type
            cjne a,#0a1h,chk_cmd_next1
            lcall sent_B1         ;sent
            ljmp loop_end

chk_cmd_next1: ;检查当前的命令类型,pc_cmd_type(A2)
            cjne a,#0a2h,chk_cmd_next2
            lcall sent_B2
            ljmp loop_end

chk_cmd_next2: ;检查当前的命令类型,pc_cmd_type(A3)
            cjne a,#0A3h,chk_cmd_next3
            lcall sent_B3         ; 依据pc_cmd_code, block,41h--52h
            ljmp loop_end

chk_cmd_next3:;检查当前的命令类型,pc_cmd_type(A4)
            cjne a,#0A4h,chk_cmd_next4
            lcall sent_B4         ; 依据pc_cmd_code, block,31h--37h
            ljmp loop_end

chk_cmd_next4:;检查当前的命令类型,pc_cmd_type(A5)
            cjne a,#0A5h,chk_cmd_next4
            lcall sent_B5         ; 依据pc_cmd_code, block,31h--37h
            ljmp loop_end


loop_end:   ajmp loop_start

;-----------------------------
sent_pc_err:;向PC发送原命令
         mov s_point,#32h
         mov s_nnn,#6
         mov a,31h
         MOV SBUF,A
         ret

;-----------------------------
sent_i2c_err:
         mov s_point,#32h
         mov s_nnn,#6
         mov 34h,i2c_err_num
         mov a,35h
         xrl a,34h
         mov 36h,a
         mov a,31h
         add a,#20h
         mov 37h,#0ceh
         MOV SBUF,A
         ret


;-----------------------------
sent_B1:  ;向PC发送B1 数据
         mov s_point,#32h
         mov s_nnn,#6
         mov 32h,pc_cmd_code
         mov a,pc_cmd_code
         cpl a
         mov 33h,a
         mov 34h,zdata_h
         mov 35h,zdata_l
         mov a,zdata_h
         xrl a,zdata_l
         mov 36h,a
         mov 37h,#0beh
         mov a,#0b1h
         MOV SBUF,A
         ret


;-----------------------------
;向PC发送写完成 [write word]    串行命令格式:  #B2H, command, not_command,msb, lsb, xrl(B4,B5),#BEH
sent_B2:
         mov s_point,#32h
         mov s_nnn,#6
         mov 37h,#0beh
         mov a,#0b2h
         MOV SBUF,A
         ret

;-----------------------------
;向PC发送块  [block read]    串行命令格式:  #B3H, command, not_command,byte_lenth,data1,data2,...,datan,xrl(byte_lenth--datan),#BEH

;                                        byte_lenth=n,D1,D2,D3,...,Dn

sent_B3: ;长度字节数:s_nnn=1+byte_lenth+5
         mov s_point,#42h
         mov a,byte_lenth
         inc a
         inc a
         inc a
         inc a
         inc a
         mov s_nnn,a
         mov a,#0b3h
         MOV SBUF,A
         ret

;-----------------------------
sent_B4:  ;向PC发送B4 DF read OK
         mov s_point,#32h
         mov s_nnn,#6
         mov 32h,DF_location
         mov a,DF_location
         cpl a
         mov 33h,a
         mov 34h,zdata_h
         mov 35h,zdata_l

⌨️ 快捷键说明

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