汇编语言到C语言的转换
有没有人能帮忙把下面的程序用C语言翻译啊?源程序:
**************************************
TEMP EQU 30H
TEMP1 EQU 40H
TEMP2 EQU 41H
COM EQU 50H
COM1 EQU 51H
LED4 EQU 52H
LED3 EQU 53H
LED2 EQU 54H
LED1 EQU 55H
LED44 EQU 56H
LED33 EQU 57H
LED22 EQU 58H
LED11 EQU 59H
K1 BIT P1.1
K2 BIT P1.2
K3 BIT P1.3
K4 BIT P1.4
FM BIT P3.7
;**************************************
ORG 00 00H
CLR 00H
CLR 01H
CLR 02H
CLR 03H
CLR 04H
CLR 05H
CLR 06H
MOV DPTR,#TAB
MOV R7,#32
MOV R0,#50H
QINGLING:MOV @R0,#00H
INC R0
DJNZ R7,QINGLING
MAIN:JB 06H,MAIN1
LCALL W1820
ACALL DISP
ACALL BIJIAO1
AJMP MAIN2
MAIN1:JB 01H,UPSET
JNB 02H,EE1
MOV 63H,#10
MOV 62H,LED2
MOV 61H,LED3
MOV 60H,LED4 ;
EE1:JNB 03H,EE2
MOV 63H,LED1
MOV 62H,#10
MOV 61H,LED3
MOV 60H,LED4
EE2:JNB 04H,EE3
MOV 63H,LED1
MOV 62H,LED2
MOV 61H,#10
MOV 60H,LED4
EE3:JNB 05H,EE4
MOV 63H,LED1
MOV 62H,LED2
MOV 61H,LED3
MOV 60H,#10
EE4:MOV R0,#63H
ACALL DIS
ACALL DELAY300
MOV R0,#LED1
ACALL DIS
ACALL DELAY300
AJMP MAIN2
;**************************************
UPSET:JNB 02H,FF1 MOV 73H,#10
MOV 72H,LED22
MOV 71H,LED33
MOV 70H,LED44
FF1:JNB 03H,FF2
MOV 73H,LED11
MOV 72H,#10
MOV 71H,LED33
MOV 70H,LED44
FF2:JNB 04H,FF3
MOV 73H,LED11
MOV 72H,LED22
MOV 71H,#10
MOV 70H,LED44
FF3:JNB 05H,FF4
MOV 73H,LED11
MOV 72H,LED22
MOV 71H,LED33
MOV 70H,#10
FF4:MOV R0,#73H
ACALL DIS
ACALL DELAY300
MOV R0,#LED11
ACALL DIS
ACALL DELAY300
MAIN2:JB K1,KEY1
ACALL DELAY10
JB K1,KEY1
SETB FM
JNB K1,$
CLR FM
INC COM
MOV A,COM
CJNE A,#1,AA1
SETB 00H
SETB 06H
AA1:CJNE A,#2,AA2
SETB 01H
AA2:CJNE A,#3,KEY1
MOV COM,#00H
CLR 00H
CLR 01H
CLR 06H
AA3:AJMP MAIN
KEY1:JNB 00H,AA3
JB K2,KEY2
ACALL DELAY10
JB K2,KEY2
SETB FM
JNB K1,$
CLR FM
INC COM1
MOV A,COM1
CJNE A,#1,BB1
SETB 02H
CLR 05H
BB1:CJNE A,#2,BB2
SETB 03H
CLR 02H
BB2:CJNE A,#3,BB3
SETB 04H
CLR 03H
BB3:CJNE A,#4,KEY2
MOV COM1,#00H
SETB 05H
CLR 04H
KEY2:JB K3,KEY3
ACALL DELAY10
JB K3,KEY3
SETB FM
ACALL DELAY10
;JNB K1,$
CLR FM
ACALL DELAY10
JB 01H,ONPLUS
JNB 02H,CC1
INC LED1
MOV A,LED1
CJNE A,#10,CC4
MOV LED1,#00H
CC1:JNB 03H,CC2
INC LED2
MOV A,LED2
CJNE A,#10,CC4
MOV LED2,#00H
CC2:JNB 04H,CC3
INC LED3
MOV A,LED3
CJNE A,#10,CC4
MOV LED3,#00H
CC3:JNB 05H,CC4
INC LED4
MOV A,LED4
CJNE A,#10,CC4
MOV LED4,#00H
CC4:AJMP KEY3
ONPLUS:JNB 02H,DD1
INC LED11
MOV A,LED11
CJNE A,#10,KEY3
MOV LED11,#00H
DD1:JNB 03H,DD2
INC LED22
MOV A,LED22
CJNE A,#10,KEY3
MOV LED22,#00H
DD2:JNB 04H,DD3
INC LED33
MOV A,LED33
CJNE A,#10,KEY3
MOV LED33,#00H
DD3:JNB 05H,KEY3
INC LED44
MOV A,LED44
CJNE A,#10,KEY3
MOV LED44,#00H
KEY3:JB K4,KEY4
ACALL DELAY10
JB K4,KEY4
SETB FM
ACALL DELAY10
;JNB K1,$
CLR FM
ACALL DELAY10
JB 01H,ONDEC
JNB 02H,GG1
DEC LED1
MOV A,LED1
CJNE A,#0FFH,KEY4
MOV LED1,#9
GG1:JNB 03H,CC2
DEC LED2
MOV A,LED2
CJNE A,#0FFH,KEY4
MOV LED1,#9
GG2:JNB 04H,CC3
DEC LED3
MOV A,LED1
CJNE A,#0FFH,KEY4
MOV LED1,#9
GG3:JNB 05H,CC4
DEC LED4
MOV A,LED1
CJNE A,#0FFH,KEY4
MOV LED1,#9
KEY4:AJMP MAIN
ONDEC:JNB 02H,HH1
DEC LED11
MOV A,LED11
CJNE A,#0FFH,HH4
MOV LED1,#9
HH1:JNB 03H,HH2
DEC LED22
MOV A,LED22
CJNE A,#0FFH,HH4
MOV LED1,#9
HH2:JNB 04H,HH3
DEC LED33
MOV A,LED33
CJNE A,#0FFH,HH4
MOV LED1,#9
HH3:JNB 05H,HH4
DEC LED44
MOV A,LED44
CJNE A,#0FFH,HH4
MOV LED1,#9
HH4:AJMP MAIN
;***************************************
BIJIAO1:MOV A,42H
CJNE A,LED1,BIJIAO2
MOV A,41H
CJNE A,LED2,BIJIAO2
MOV A,40H
CJNE A,LED3,BIJIAO2
MOV A,39H
CJNE A,LED4,BIJIAO2
CLR FM
AJMP BACK
BIJIAO2:MOV A,42H
CJNE A, LED11,BACK
MOV A,41H
CJNE A,LED22,BACK
MOV A,40H
CJNE A,LED33,BACK
MOV A,39H
CJNE A,LED44,BACK
CLR FM
BACK:RET
;**************************************
W1820:LCALL RESET ;ds18b20复位
MOV A,#0CCH ;发SKIP ROM命令
LCALL WRITE
MOV A,#44H
LCALL WRITE
LCALL DLY1S ;延时
LCALL RESET
MOV A,#0CCH
LCALL WRITE
MOV A,#0BEH
LCALL WRITE
LCALL READ ;读出温度值1
MOV TEMP2,TEMP ;温度低8位存放41H
LCALL READ ;读出温度值2
MOV TEMP1,TEMP ;温度高8位存放在40H
;**************************开始数值转换
MOV A,41H
RR A
RR A
RR A ;把D3位右移到D0
ANL A,#01H ;除D0位,其他全部置零
MOV B,#5
MUL AB ;由于原D3位权值为0.5,故扩大10倍乘5后放十分位
MOV 42H,A ;十分位转换结束,送42H保存
NOP ;设置断点,方便修改和查阅
MOV A, 40H
ANL A, #0FH ;把40H中高四位置零
RL A
RL A
RL A
RL A ;40H左移4位
MOV 40H, A ;40H中低四位移到高四位,低四位为零
;***************************************
MOV A, 41H
ANL A, #0F0H ;把41H中小数点后的值全部置零
RR A
RR A
RR A
RR A ;41H右移4位
MOV 41H, A ; 把41H中高四位移到低四位,高四位置零
MOV A, 40H
ORL A, 41H ;组成新的带符号无小数点的八位数字温度,最高位为符号位
MOV 43H,A ;暂存温度值,原41H的高4位做43H的低4位,原40H的低4位做43H的高4位
;***************************************
ANL A,#80 ; 除最高位有效,其他置零
RR A
RR A
RR A
RR A
MOV 44H,A ;判断温度值的符号位,把结果放44H,44H中要只有0和8。
NOP
MOV A,43H ;恢复带符号八位无小数点温度
ANL A,#7FH ;屏蔽符号位
MOV B, #0AH
DIV AB ;无符号温度值除以10
MOV 40H, A ;商送40H暂存
MOV A, B ;余数通过A送41H保存
MOV 41H, A ;存个位十进制温度值
MOV A,40H
MOV B,#0AH
DIV AB ;商作为被除数再除以10
MOV 39H,A ;商存入39H,存百位十进制温度值
MOV A,B ;余数通过A送40H保存
MOV 40H,A ;存十位十进制温度值
RET
;************************;初始化,复位操作
RESET:
L0: CLR P1.0
MOV R2, #120
L1: NOP
DJNZ R2,L1
SETB P1.0 ;主机发置位脉冲持续600us
MOV R2,#15
L4: DJNZ R2,L4 ;等待60us
CLR C
ORL C, P1.0 ;数据线应变低
JC L0 ;没准备好,重来
MOV R6,#24
L5: ORL C, P1.0
JC L3 ;数据线变高初始化成功
DJNZ R6,L5 ;数据线低电平可持续240us
SJMP L0 ;初始化失败,重来
L3: MOV R2, #125
L2: DJNZ R2,L2 ;应答过程最少480us
RET
;***********************把从P1.0口数据读入寄存器
READ: MOV R6,#8
RE1: CLR P1.0
MOV R4, #4
LCALL DELAY4US ;低电平持续4us
SETB P1.0 ;P1.0开始输入
RE2: DJNZ R4,RE2 ;等待12us
MOV C, P1.0
RRC A ;按位读入
MOV R5, #15
RE3: DJNZ R5, RE3 ;保证读过程持续60us
DJNZ R6, RE1
MOV TEMP, A
SETB P1.0
RET
把寄存器数据通过P1.0口送给DS18B20
WRITE: MOV R3, #8
WR1: SETB P1.0
MOV R4, #5
RRC A
CLR P1.0
WR2: DJNZ R4,WR2 ;数据线变低16us
MOV P1.0, C ;命令字按位送
MOV R4, #15
WR3: DJNZ R4,WR3 ;保证整个写过程持续60us
DJNZ R3,WR1
SETB P1.0
RET
DISP:MOV DPTR,#TAB
MOV R0,#42H
DIS:MOV R7,#4
DISP1:MOV A,@R0
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI
DEC R0
DJNZ R7,DISP1
RET
;***************************************
DELAY:MOV R6,#255 ;延时
DEL2:MOV R5,#255
DEL3:NOP
NOP
DJNZ R5,DEL3
DJNZ R6, DEL2
RET
;*************10MS*********************
DELAY10: MOV R7, #10H
DS1: MOV R6, #0FFH
DS2: DJNZ R6, DS2
DJNZ R7, DS1
RET
;*************300MS********************
DELAY300: MOV R7, #2
DSS1: MOV R6, 0C8H
DSS2: MOV R5, #0E5H
DSS3: DJNZ R5, DSS3
DJNZ R6, DSS2
DJNZ R7, DSS1
RET
;*************100MS*******************
DELAY100: MOV R7, #0C8H
SS1: MOV R6, #0E5H
SS2: DJNZ R6, SS2
DJNZ R7, SS1
RET
DLY1S: MOV R7,#255
MOV R6,#0
DLYB: NOP
DJNZ R7,DLYB
DJNZ R6,DLYB
RET
TAB:DB 11H,7DH,32H,92H,0D4H,98H,18H,0D3H,10H,90H,0FFH
END