微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于CH372的单片机波形采集程序

基于CH372的单片机波形采集程序

时间:11-30 来源:互联网 点击:
电路图:

;*************************************
上位机软件及pcb文件下载地址:http://www.51hei.com/bbs/dpj-19233-1.html
;STC89C51RC单片机,6M晶振
;P0.7为红外输入
;P0.6为无线电信号输入
;P0.5为外部信号输入
;*************************************
CSEQUP0.0
A0EQUP0.1
DXEQUP0.3
CEEQUP0.4
GETEQUP0.2
ORG0000H
LJMPAMIT
ORG0030H
AMIT:MOVSP,#0FBH
MOVP0,#0FFH
MOVP1,#0FFH
MOVP2,#0FFH
MOVP3,#0FFH
MOVR0,#08H
MOVR7,#68
MOVR2,#00H
CLRP0.7
MOVTMOD,#01H
MOVTL0,#00H
MOVTH0,#00H
CLRTR0
;********CH372复位*********
FW:MOVA,#05H
MOVP2,A
CLRCS
SETBA0;写复位命令
CLRDX
NOP
NOP;50NS就可以
SETBDX
LCALLDYL
JSCS:JBGET,$
MOVA,#22H;接受中断数据
ACALLXML;调用CH372写命令
ACALLDSJ;调用CH372读数据
CJNEA,#01H,G1
AJMPOUT1
G1:CJNEA,#0F2H,G2
ACALLOUT2;如果CH372返回0F2则读端口2的命令
AJMPCHKOF
G2:CJNEA,#0F5H,G3
AJMPPEND
G3:CJNEA,#0F6H,G4
AJMPLEEP
G4:CJNEA,#0F9H,G5
ACALLINO
AJMPJSCS
G5:CJNEA,#0FAH,JSCS
ACALLINO
AJMPJSCS
;*******采集子程序********
CHKOF:CJNEA,#0A1H,F1;捕获输入信号。
AJMPTIM
F1:CJNEA,#0A2H,F2;如果收到A2则复位主程序。
AJMPAMIT
F2:CJNEA,#0A3H,F3;红外输入。
AJMPHWX
F3:CJNEA,#0A4H,F4;无线电信号输入。
AJMPWXD
F4:CJNEA,#0A5H,JSCS;外部信号输入。
SETBP0.7
SETBP0.6
CLRP0.5
MOVR2,#02H
AJMPJSCS
HWX:SETBP0.5
SETBP0.6
CLRP0.7
MOVR2,#00H
AJMPJSCS
WXD:SETBP0.5
SETBP0.7
CLRP0.6
MOVR2,#01H
AML:AJMPJSCS
;***********判断输入端***********
TIM:CJNER2,#0F1H,TI1
AJMPWTT
TI1:CJNER2,#0F2H,TI2
AJMPUTT
TI2:CJNER2,#0F0H,AML
;***********数据采集1红外输入************
CT:JNBGET,QH_1
JBP3.7,CT
SETBTR0
THO:JNBP3.7,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
JBP3.7,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
INCR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
INCR0
DJNZR7,THO
CLRTR0
AJMPFZCX
QH_1:AJMPJSCS
;***********数据采集2无线输入************
WTT:JNBGET,QH_2
JBP3.6,WTT
SETBTR0
THA:JNBP3.6,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
JBP3.6,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
INCR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
INCR0
DJNZR7,THA
CLRTR0
AJMPFZCX
QH_2:AJMPJSCS
;************数据采集3外部输入************
UTT:JNBGET,QH_2
JBP3.5,UTT
SETBTR0
THB:JNBP3.5,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
JBP3.5,$
CLRTR0
MOVA,TH0
MOVR1,TL0
MOVTL0,#01H
MOVTH0,#00H
SETBTR0
INCR0
MOV@R0,A
INCR0
MOVA,R1
MOV@R0,A
INCR0
DJNZR7,THB
CLRTR0
;*************数据发送***********
FZCX:MOVR7,#122
MOVR0,#08H
ZDDS:MOVA,#2AH;CH372中断命令通知PC机
ACALLXML
NOP
NOP
MOVA,#02H;可输入8个字节
ACALLXSJ
MOVA,@R0;送入要上传的数据
ACALLXSJ
INCR0
MOVA,@R0;送入要上传的数据
ACALLXSJ
INCR0
ACALLFYL
MOVA,#22H;接受中断数据
ACALLXML
ACALLDSJ
ACALLFYL
ACALLINO
DJNZR7,ZDDS
MOVR0,#08H
MOVR7,#61
AJMPJSCS
;********CH372读出数据**********
OUT2:MOVA,#28H;读端口2的命令
ACALLXML
ACALLDSJ
NOP
ACALLDSJ
NOP
RET
;****************
OUT1:NOP
PEND:NOP
LEEP:NOP
AJMPAMIT
;******释放缓冲区子程序*****
INO:MOVA,#2BH;释放当前USB缓冲区
ACALLXML
NOP
NOP
RET
;*******写入数据子程序*******
XSJ:CLRA0;写入数据
NOP
NOP;延时2US,根据主频来确定NOP的值
MOVP2,A
NOP
NOP;50NS就可以
SETBDX
NOP
NOP;延时1.2US根据主频调整
RET
;*********延时子程序******
DYL:MOVR6,#100
D1:MOVR5,#50
DJNZR5,$
DJNZR6,D1
RET
FYL:MOVR6,#2
FD1:MOVR5,#68
DJNZR5,$
DJNZR6,FD1
RET
END

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top