微机原理远程数据采集系统设计

Created with Raphaël 2.1.2开始初始化设置周期?修改延时周期数据采集延时发送yesno

下位机

   S_SHOW MACRO STRING
   MOV AH,9
   MOV DX,OFFSET STRING
   INT 21H
ENDM

DATAS SEGMENT
  RESULT DB 40H
  num_h db 0
  num_l db 0
  msg db 'plaese set time_cycle:','$'
  ;msg db 'plaese set time_cycle:',0AH,0DH,'$'
  str1  db 'Please input! Enter q key exit!',0ah,0dh,'$'
  errm db 'Error!',0ah,0dh,'$'
  s1     db 0
  ;延时周期 
  time_cycle DB 3
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX

    ;;;;;;;;;;;;;8255初始化
    call init_8255

    ;;;;8253初始化
    call init_8253

    ;设置延时周期
    call SetTimeCycle

    ;;;发送初始化
    call init_send

    againshow:
      ;调用数据采集
      caLl SHUJUCAIJI

      ;显示数据
    ;  call show 

      ;发送数据
      call send

      ;判断键盘是否有输入
      MOV AH,0BH
      INT 21H
      CMP AL,0
      JE againshow

    MOV AH,1      
    INT 21H
    JMP START

;显示数据
show proc
    MOV AL, RESULT
    MOV BL,50

    MUL BL
    MOV AL,AH
    MOV AH,0
    MOV BL,10
    DIV BL
    ;ASCLL码加30
    ADD AL,30H
    MOV num_h,AL

    ADD AH,30H
    MOV num_L,AH


    MOV AH,02H
    MOV DL,num_h
    INT 21H


    MOV AH,02H
    MOV DL,'.'
    INT 21H

    MOV AH,02H
    MOV DL,num_L
    INT 21H

    MOV AH,02H
    MOV DL,'V'
    INT 21H
ret
show endp   

;功能:回车换行
huiche proc
  MOV AH,02H
  MOV DL,0AH
  INT 21H

  MOV AH,02H
  MOV DL,0DH
  INT 21H
RET
huiche endp


;功能:设置延时周期
SetTimeCycle proc

  S_SHOW msg
  ;循环判断是否有输入
  again: MOV AH,0BH
    INT 21H
    CMP AL,0
    JE again
  ;因是字符串
  ;获取的ASCLL码值减30 得到延时周期
  MOV AH,1
  INT 21H
  sub AL, 30H
  MOV time_cycle, AL

  MOV AH,02H
  MOV DL,0AH
  INT 21H

  MOV AH,02H
  MOV DL,0DH
  INT 21H


RET
SetTimeCycle endp

;功能:数据采集
;出口:返回RESULT 数据采集的值
SHUJUCAIJI proc
   MOV DX, 0E098H;通道0 对应298

   OUT DX,AL ;启动
   CALL delay 
   MOV DX,0E098H;
   IN AL,DX;读取电压 al
   MOV RESULT,AL 
RET
SHUJUCAIJI ENDP


;延时子程序
delay proc

   MOV DX,0E08BH
   MOV AL,01110000B
   OUT DX,AL

   MOV DX,0E089H
   ;计算相乘
   MOV AL,time_cycle
   MOV BL,100
   MUL BL   

   ;先传低后传高
   OUT DX,AL
   MOV AL,AH 
   OUT DX,AL

   ;取出C端口     
    MOV DX,0E082H
   ;看最高位是否是高电平
   ISNO:IN AL,DX
   TEST AL,1
   JZ ISNO

RET  
delay endp;


;功能:发送数据
send proc
    mov al,RESULT
    ;发送
    mov ah,1
  mov dx,0

    int 14h
send endp

init_8253 proc
;;;;8253初始化
    ;给送控制字, 使其工作在方式三
    MOV DX,0E08BH    
    MOV AL,00110110B     
    OUT DX,AL
    ;送通道0的计数初值
    MOV DX, 0E088H    
    MOV AX,10000
    ;送低送高
    OUT DX,AL
    MOV AL,AH
    OUT DX,AL

RET  
init_8253 endp


init_8255 proc
    MOV DX,0E083H
    MOV AL,10000001B
    OUT DX, AL
RET  
init_8255 endp

init_send proc
mov ah,0
    mov dx,0
    mov al,10111011b
    int 14h
RET  
init_send endp


CODES ENDS
    END START

上位机

DATAS SEGMENT
    ;此处输入数据段代码  
    str1 db 'Please input! Enter q key exit!',0ah,0dh,'$'
    ;str2 db 'V=:',0ah,0dh,'$'
    errm db 'Error!',0ah,0dh,'$'
    num_L db 0
    num_H db 0
    RESULT DB 40H
    data db 0
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    ;此处输入代码段代码
    mov ah,9
    mov dx,offset str1
    int 21h

    mov ah,0
    mov dx,0
    mov al,10111011b
    int 14h;调用中断

send:
    mov ah,3;读入串行口状态
    mov dx,0
    int 14h
    test ah,00100000b;判断输入缓冲器是否为空
    jz receive;空跳转到接收

    mov ah,0bh;检查标准输入状态
    int 21h
    cmp al,0
    je receive              ;未准备好输入就跳到接收

    mov ah,8
    int 21h                 ;无回显的控制台输入

    mov data,al

    cmp data,'q'
    je exit

receive:
    mov ah,3
    mov dx,0
    int 14h
    test ah,1;判断输入缓冲器是否为满
    jz send;不满跳到发送

    mov ah,2;读入缓冲器的数据
    mov dx,0                ;收字符
    int 14h
    test ah,10001110b
    jnz error



    mov RESULT,al
    call show   

    cmp al,'q'
    je exit

    mov dl,al
    mov ah,2
    int 21h;显示

    jmp send
exit: 
    mov dx,0
    mov ah,1                ;输出字符
    int 14h

    test ah,80h
    jnz error

    mov ax,4c00h
    int 21h

error: mov ah,9
    mov dx,offset  errm
    int 21h
    mov ax,4c00h
    int 21h

show proc
    MOV AL, RESULT
    MOV BL,50

    MUL BL
    MOV AL,AH
    MOV AH,0
    MOV BL,10
    DIV BL
    ;ASCLL码加30
    ADD AL,30H
    MOV num_h,AL

    ADD AH,30H
    MOV num_L,AH


    MOV AH,02H
    MOV DL,num_h
    INT 21H


    MOV AH,02H
    MOV DL,'.'
    INT 21H

    MOV AH,02H
    MOV DL,num_L
    INT 21H

    MOV AH,02H
    MOV DL,'V'
    INT 21H
    call huiche
ret
show endp

;功能:回车换行
huiche proc
  MOV AH,02H
  MOV DL,0AH
  INT 21H

  MOV AH,02H
  MOV DL,0DH
  INT 21H
RET
huiche endp


CODES ENDS
    END START
上一篇:nginx 防御采集和cc


下一篇:Amazon SimpleDB——网络数据存储的新选择