[求助]各位老师,帮我写一段主程序调用一段汇编程序和一段C语言程序。坐等结果
求助各位老师帮我写一段主程序调用一下汇编程序和C语言程序。单片机中用的,谢谢了,坐等答案!1.超声波发射接收程序:
VOUT EQU P1.0 ;脉冲输出端口
*中断入口程序*
ORG 0000H
LJMP START
ORG 0003H
LJMP PINT0
ORG 000BH
LJMP INTT0
ORG 0013H
RETI
ORG 001BH
LJMP INTT1
ORG 0023H
RETI
ORG 002BH
RETI
*主程序*
START: MOV SP, #4FH
MOV R0, #40H ;40~43H为显示数据存放单元(40为最高位)
MOV R7,#0BH
CLEARDISP:MOV @R0, #00H
INC R0
DJNZ R7, CLEARDISP
MOV 20H, #00H
MOV TMOD, #21H ;T1为8位自动重装模式,T0为16位定时器
MOV TH0, #00H ;65ms初值
MOV TL0, #00H ;40KHz初值
MOV TH1, #0F2H
MOV TL1, #0F2H
MOV P0, #0FFH
MOV P1, #0FFH
MOV P2, #0FFH
MOV P3, #0FFH
MOV R4, #04H ;超声波脉冲个数控制(为赋值的一半)
SETB PX0
SETB ET0
STEB EA
CLR 00H
SETB TR0 ;开启测距定时器
START1: LCALL DISPLAY
JNB 00H, START1 ;收到反射信号时标志位为1
CLR EA
LCALL WORK ;计算距离子程序
SETB EA
CLR 00H
SETB TR0 ;重新开启测距定时器
MOV R2, #64H ; 测量间隔控制(约4*100=400ms)
LOOP: LCALL DISPLAY
DJNZ R2, LOOP
SJMP START 1
*中断程序*
;T0中断,65ms中断一次
INTT0: CLR EA
CLR TR0
MOV TH0, #00H
MOV TL0, #00H
SETB ET1
SETB EA
SETB TR0 ;启动计时器T0,用以计算超声波来回时间
SETB TR1 ;开启发超声波用定时器T1
OUT: RETI
;T1中断,发超声波用
INTT1: CPL VOUT
DJNZ R4,RETIOUT
CLR TR1 ;超声波发送完毕,关T1
CLR ET1
MOV R4,#04H
SETB EX0 ;开启接收回波中断
RETIOUT: RETI
;外中断0,收到回波时进入
PINT0: CLR TR0 ;关计数器
CLR TR1
CLR ET1
CLR EA
CLR EX0
MOV 44H, TL0 ;将计数值移入处理单元
MOV 45H, TH0
SETB 00H ;接收成功标志
RETI
*延时程序*
DL1MS: MOV R6, #14H
DL1: MOV R7, #19H
DL2: DJNZ R6, DL2
DJNZ R6, DL1
RET
*显示程序*
;40H为最高位,43H为最低位,先扫描高位
DISPLAY: MOV R1, #40H;G
MOV R5,#0F7H;G
PLAY: MOV A, R5
MOV P0, #0FFH
MOV P2, A
MOV A, @R1
MOV DPTR, #TAB
MOVC A, @A+DPTR
MOV P0, A
LCALL DLIMS
INC R1
MOV A, R5
JNB ACC.0, ENDOUT;G
RR A
MOV R5, A
AJMP PLAY
ENDOUT: MOV P2, #0FFH
MOV P0, #0FFH
RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH,88H,0BFH
;共阳数码管 0 ,1, 2,3,4,5,6,7,8,9,不亮,A, —
*距离计算程序 (=计算值×17/1000cm) 近似
WORK: PUSH ACC
PUSH PSW
PUSH B
MOV PSW, #18H
MOV R3, 45H
MOV R2, 44H
MOV R1, #00D
MOV R0, #17D
LCALL MUL2BY2
MOV R3, #03H
MOV R2, #0E8H
LCALL DIV4BY2
LCALL DIV4BY2
MOV 40H, R4
MOV A, 40H
JNZ JJ0
MOV 40H, #0AH ;最高位为0,不点亮
JJ0: MOV A R0
MOV R4, A
MOV A R1
MOV R5 A
MOV R3, #00D
MOV R2, #100D
LCALL DIV4BY2
MOV 41H, R4
MOV A, 41H
JNZ JJ1
MOV A, 40H ;此高位为0,先看最高位是否为不亮
SUBB A, #0AH
JNZ JJ1
MOV 41H, #0AH ; 最高位不亮,次高位也不亮
JJ1: MOV A, R0
MOV R4, A
MOV A, R1
MOV R5, A
MOV R3, #00D
MOV R2, #10D
LCALL DIV4BY2
MOV 42H, R4
MOV A 42H
JNZ JJ2
MOV A, 41H ;次高位为0,先看次高位是否为不亮
SUBB A, #0AH
JNZ JJ2
MOV 42H, #0AH ;次高位不亮,次高位也不亮
JJ2: MOV 43H, R0
POP B
POP PSW
POP ACC
RET
*两字节无符号数乘法程序
MUL2BY2: CLR A
MOV R7, A
MOV R6, A
MOV R5, A
MOV R4, A
MOV 46H, #10H
MULLOOP1: CLR C
MOV A, R4
RLC A
MOV R4, A
MOV A, R5
RLC A
MOV R5, A
MOV A, R6
RLC A
MOV R6, A
MOV A, R7
RLC A
MOV R7, A
MOV A, R0
RLC A
MOV R0, A
MOV A, R1
RLC A
MOV R1, A
JNC MULLOOP2
MOV A, R4
ADD A, R2
MOV R4, A
MOV A, R5
ADDC A, R3
MOV R5, A
MOV A, R6
ADDC A, #00H
MOV R6, A
MOV A, R7
ADDC A, #00H
MOV R7, A
MULLOOP2: DJNZ 46H, MULLOOP1
RET
*四字节/两字节无符号数除法程序*
DIV4BY2: MOV 46H, #20H
MOV R0, #00H
MOV R1, #00H
DIVLOOP1: MOV A, R4
RLC A
MOV R4, A
MOV A, R5
RLC A
MOV R5, A
MOV A, R6
RLC A
MOV R6, A
MOV A, R7
RLC A
MOV R7, A
MOV A, R0
RLC A
MOV R0, A
MOV A, R1
RLC A
MOV R1, A
CLR C
MOV A, R0
SUBB A, R2
MOV B, A
MOV A, R1
SUBB A, R3
JC DIVLOOP2
MOV R0, B
MOV R1, A
DIVLOOP2: CPL C
DJNZ 46H, DIVLOOP1
MOV A, R4
RLC A
MOV R4, A
MOV A, R5
RLC A
MOV R5, A
MOV A, R6
RLC A
MOV R6, A
MOV A, R7
RLC A
MOV R7, A
RET
END
2.振动传感器及报警部分:
#include<zdbj.h> //库文件
#define uchar unsigned char//宏定义无符号字符型
#define uint unsigned int //宏定义无符号整型
sbit SOUND=P1^1; //定义单片机P1口的第2位 (即P1.1)为指示端
sbit DOUT=P3^3; //定义单片机P3口的第4位 (即P3.3)为传感器的输入端
void delay()//延时程序
{
uchar m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
void main()
{
while(1) //无限循环
{
SOUND=1; //停止P1.1报警装置
if(DOUT==0)//当振动高于设定值时 ,执行条件函数
{
delay();//延时抗干扰
if(DOUT==0)//确定振动高于设定值时 ,执行条件函数
{
SOUND=0; //使得P1.1报警装置启动
}
}
}
}