如何把汇编的程序改为c语言
以下是我的汇编程序,主要是交通灯控制,能够倒计时,用到了8255,8254和数码管显示,基于唐都试验平台,如何把他改为c语言啊;*****************************************************************
I0Y0 EQU 0E400H ;片选IOY0对应的端口始地址
I0Y2 EQU 0E480H ;片选IOY1对应的端口始地址
;*****************************************************************;8255 端口地址 IYO0
ADDR8255_A EQU I0Y0+00H*4 ;A口
ADDR8255_B EQU I0Y0+01H*4 ;B口
ADDR8255_C EQU I0Y0+02H*4 ;C口
ADDR8255 EQU I0Y0+03H*4 ;控制口
;8254 端口地址 IYO2
ADDR8254 EQU I0Y2+03H*4
ADDR8254_0 EQU I0Y2+00H*4 ;8254计数器口地址
ADDR8254_1 EQU I0Y2+01H*4
;数字段
DATA SEGMENT
RUN DB 'JIAO TONG DENG IS RUNNING.......',0AH,0DH,'$' ;提示信息
MESS DB 'PRESS ESC KEY TO DOS.$'
E_W DB 'P7-E_W_RED,P6-E_W_GREAD,P5-E_W_YELLOW',0AH,0DH,'$'
S_N DB 'P3-S_N_RED,P2-S_N_GREAD,P1-S_N_YELLOW',0AH,0DH,'$'
LEDBUF DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
DATA ENDS
;代码段
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET RUN ;显示提示信息
MOV AH,09H
INT 21H
MOV DX,OFFSET MESS
MOV AH,09H
INT 21H
MOV DX,OFFSET E_W
MOV AH,09H
INT 21H
MOV DX,OFFSET S_N
MOV AH,09H
INT 21H
;8255初始化 A口接发光二极管;B口接数码管;C4-7 out,C0-3 in
CALL INITIAL_8255
;8254初始化 初值1000 CLKO接1KH OUT0 接C0 GATE0 接+5V
;计数通道0 方式0 先低8位后高8位 BCD方式 控制字: 00110001B
CALL INITIAL_8254
;-------------------------------------------------
E_W_RED_S_N_GRE:
;在发光二极管上显示东西红灯亮,南北绿灯亮
MOV DX,ADDR8255_A
MOV AL,10000100B
OUT DX,AL
;计时秒
MOV CX,31
CALL DELAY_MIN1
MOV DX,ADDR8255_A ;从的A口读出灯的状态
IN AL,DX
CMP AL,10000100B
JE E_W_RED_S_N_YEL
CMP AL,10000010B
JE E_W_GRE_S_N_RED
CMP AL,01001000B
JE E_W_YEL_S_N_RED
CMP AL,00101000B
JE E_W_RED_S_N_GRE ;查灯的状态
;-------------------------------------------------
E_W_RED_S_N_YEL:
;在发光二极管上显示东西红灯亮,南北黄灯亮
MOV DX,ADDR8255_A
MOV AL,10000010B
OUT DX,AL
;计时秒
MOV CX,6
CALL DELAY_MIN2
MOV DX,ADDR8255_A ;从的A口读出灯的状态
IN AL,DX
CMP AL,10000100B
JE E_W_RED_S_N_YEL
CMP AL,10000010B
JE E_W_GRE_S_N_RED
CMP AL,01001000B
JE E_W_YEL_S_N_RED
CMP AL,00101000B
JE E_W_RED_S_N_GRE ;查灯的状态
;-------------------------------------------------
E_W_GRE_S_N_RED:
;在发光二极管上显示东西绿灯亮,南北红灯亮
MOV DX,ADDR8255_A
MOV AL,01001000B
OUT DX,AL
;计时秒
MOV CX,31
CALL DELAY_MIN1
MOV DX,ADDR8255_A ;从的A口读出灯的状态
IN AL,DX
CMP AL,10000100B
JE E_W_RED_S_N_YEL
CMP AL,10000010B
JE E_W_GRE_S_N_RED
CMP AL,01001000B
JE E_W_YEL_S_N_RED
CMP AL,00101000B
JE E_W_RED_S_N_GRE ;查灯的状态
;-------------------------------------------------
E_W_YEL_S_N_RED:
;在发光二极管上显示东西黄灯亮,南北红灯亮
MOV DX,ADDR8255_A
MOV AL,00101000B
OUT DX,AL
;计时秒
MOV CX,6
CALL DELAY_MIN2
MOV DX,ADDR8255_A ;从的A口读出灯的状态
IN AL,DX
CMP AL,10000100B
JE E_W_RED_S_N_YEL
CMP AL,10000010B
JE E_W_GRE_S_N_RED
CMP AL,01001000B
JE E_W_YEL_S_N_RED
CMP AL,00101000B
JE E_W_RED_S_N_GRE ;查灯的状态
EXIT:
MOV AH,4CH
INT 21H
;******************************************************************
;数码管显示
DISP PROC
PUSH AX
PUSH BX
PUSH DX
PUSH CX
DEC CX
;将CL中进制数转化为十进制数
MOV DX,ADDR8255_C
MOV AL,11101111B
OUT DX,AL
MOV AX,CX
MOV CL,0AH
DIV CL
PUSH AX
MOV BX,OFFSET LEDBUF
XLAT
;显示十位码
MOV DX,ADDR8255_B
;将AL中位码输出到B口,给LED显示器
OUT DX,AL
MOV CX,04FFFH
DELAY:
NOP
LOOP DELAY
MOV DX,ADDR8255_C
MOV AL,11011111B
OUT DX,AL
POP AX
MOV AL,AH
MOV BX,OFFSET LEDBUF
XLAT
;显示个位码
MOV DX,ADDR8255_B ;将AL 中位码输出到B口,给LED显示器
OUT DX,AL
POP CX
POP DX
POP BX
POP AX
RET
DISP ENDP
;***************************************************************
DELAY_MIN1 PROC
PUSH AX
PUSH DX
PUSH CX
LOOP1:
CALL INITIAL_8254
LOOP2:
MOV AH,0BH ;判断有无键按下
INT 21H
CMP AL,0
JNZ EXIT ;有键入则返回DOS
MOV DX,ADDR8255_C
IN AL,DX
TEST AL,00001100B ;检测是否有紧急键按下
JZ L1
CALL EMERGECY ;有紧急键则转到紧急键处理
JMP L2
L1: CALL DISP
L2: MOV DX,ADDR8255_C ;检测1s是否计完
IN AL,DX
TEST AL,000000001B
JE LOOP2 ;若1s没计数完,继续
LOOP LOOP1 ;30s或1s计数完全?若没计数完,继续
POP CX
POP DX
POP AX
RET
DELAY_MIN1 ENDP
;****************************************************************
DELAY_MIN2 PROC
PUSH AX
PUSH DX
PUSH CX
LOOP3:
CALL INITIAL_8254
LOOP4:
MOV AH,0BH ;有键盘输入,退出
INT 21H
CMP AL,0
JNZ EXIT
MOV DX,ADDR8255_C
IN AL,DX
TEST AL,00001100B ;检测是否有紧急键按下
JZ NEXT
CALL EMERGECY ;有紧急键则转到紧急键处理
JMP NEXT1
NEXT:
CALL DISP
NEXT1:
MOV DX,ADDR8255_C ;检测1s是否计完
IN AL,DX
TEST AL,00000001B
JE LOOP4 ;若1s没计数完,继续
MOV DX,ADDR8255_A
IN AL,DX
CMP AL,10000010B
JZ SHAN1
CMP AL,10000000B
JZ SHAN1
CMP AL,00101000B
JZ SHAN2
CMP AL,00001000B
JZ SHAN2
L5: LOOP LOOP3 ;30s或1s计数完全?若没计数完,继续
POP CX
POP DX
POP AX
RET
SHAN1:
CMP AL,10000010B
JZ OFF1
MOV AL,10000010B
OUT DX,AL
JMP CHU1
OFF1: MOV AL,10000000B
OUT DX,AL
CHU1: JMP L5
SHAN2:
CMP AL,00101000B
JZ OFF2
MOV AL,00101000B
OUT DX,AL
JMP CHU2
OFF2:
MOV AL,00001000B
OUT DX,AL
CHU2: JMP L5
DELAY_MIN2 ENDP
;***************************************************************
INITIAL_8255 PROC
MOV DX,ADDR8255 ;8255,IOY0
MOV AL,10000001B ; A口接发光二极管;B口接数码管;C4-7 OUT,C0-3 IN
OUT DX,AL
RET
INITIAL_8255 ENDP
;***************************************************************
INITIAL_8254 PROC
PUSH AX
PUSH DX
MOV DX,ADDR8254
MOV AL,00110111B ;8253 初始化方式,BCD方式计数,给计数初值1000H
OUT DX,AL
MOV DX,ADDR8254_0
MOV AL,00H
OUT DX,AL
MOV AL,10H ;8254 1KHZ
OUT DX,AL
MOV AL,01110001B
OUT DX,AL
MOV DX,ADDR8254_1
MOV AL,00H
OUT DX,AL
MOV AL,10H
OUT DX,AL
POP DX
POP AX
RET
INITIAL_8254 ENDP
;***************************************************************
EMERGECY PROC ;紧急键处理
PUSH AX
PUSH DX
PUSH CX
MOV DX,ADDR8255_C ;从的C口读出紧急键状态
IN AL,DX
TEST AL,00001000B ;若为东西紧急,则转EW
JNZ EW
TEST AL,00000100B ;若为南北紧急,则转SN
JNZ SN
JMP QUIT
EW: MOV DX,ADDR8255_A ;东西紧急处理,东西绿,南北红
MOV AL,10001000B
OUT DX,AL
MOV DX,ADDR8255_B
MOV AL,00000000B
OUT DX,AL
JMP QUIT
SN: MOV DX,ADDR8255_A ;南北紧急处理,东西红,南北绿
MOV AL,10001000B
OUT DX,AL
MOV DX,ADDR8255_B
MOV AL,00000000B
OUT DX,AL
JMP QUIT
QUIT: POP CX
POP DX
POP AX
RET
EMERGECY ENDP
;****************************************************************
CODE ENDS
END START
请高手帮忙转换以下,,是课程设计,,汇编我搞出来了,但又要用c语言实现,,真是烦人