能帮我把这段c语言程序改为汇编语言程序吗 #include"reg51.h" #include"lcd1602.h" unsigned char flag=0,count=0,lenth=60,a=0,c=0; unsigned char str2[16]={"8206210706 "}; unsigned char num[4]={"2101"}; unsigned char table[60]={ 0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00, 0x04,0x1F,0x15,0x1F,0x15,0x1F,0x04,0x07, 0x03,0x04,0x1C,0x04,0x1F,0x04,0x0E,0x15, 0x12,0x0A,0x16,0x0A,0x1F,0x02,0x02,0x02, 0x1F,0x12,0x14,0x12,0x1F,0x10,0x10,0x10, 0x04,0x1F,0x08,0x14,0x1F,0x04,0x0E,0x15, 0x04,0x1F,0x08,0x10,0x0F,0x09,0x0F,0x09}; void delay(unsigned int t) { unsigned int i=0,j=0; for(i=0;i<t;i++) { for(j=0;j<120;j++); } } void writedat(unsigned char dat) { RS=1; RW=0; E=0; E=1; P2=dat; delay(5); E=0; } void writecom(unsigned char com) { RS=0; RW=0; E=0; E=1; P2=com; delay(5); E=0; } void initlcd() { int u=0; writecom(0x38); writecom(0x0c); writecom(0x06); writecom(0x01); writecom(0x40); for(u=0;u<72;u++) { writedat(table[u]); } } void initscon() { SCON=0x50; //0101 0000 TMOD=0x20; //0010 0000 TH1=256-3; TL1=256-3; EA=1; ES=1; TR1=1; IP=0x01; } void initex0() {IT0=1; EX0=1; } void senddat_function() { unsigned char i=0; if(a==1) { SBUF=1; while(!TI); TI=0; a=0; } if(flag==1) { SBUF=2; while(!TI); TI=0; flag=0; } } void Show_txt(unsigned char x,unsigned char i) { writecom(0x80 |x); writedat(i); } void Show_str(unsigned char x,unsigned char y,unsigned char *s) { int i=0; if(y==0) writecom(0x80 |x); if(y==1) writecom(0xc0 |x); for(i=0;i<16;i++) writedat(s[i]); } void display() { int j; writecom(0x80+0x40); delay(1); for(j=0;j<16;j++) { writedat(str2[j]); delay(1); } } void main() { int j; initscon(); initex0(); initlcd(); while(1) {senddat_function(); Show_txt(0,1); Show_txt(1,2); Show_txt(2,3); writecom(0x80|3); delay(1); for(j=0;j<4;j++) { writedat(num[j]); delay(1); } Show_txt(7,4); Show_txt(8,5); Show_txt(9,6); display();} } void ex0_isr() interrupt 0 { int j; c=c+1; if(c==1) {a=1;flag=0; Show_txt(0,1); Show_txt(1,2); Show_txt(2,3); writecom(0x80|3); delay(1); for(j=0;j<4;j++) { writedat(num[j]); delay(1); } Show_txt(7,4); Show_txt(8,5); Show_txt(9,6); } if(c==2) {flag=1; c=0; a=0;} }
时间: 2023-09-10 15:05:08 浏览: 136
gps用51单片机读取时间 c语言
由于您没有指定使用的汇编语言,我将使用汇编语言的伪代码来展示如何将C语言程序转换为汇编语言程序:
```
//定义变量
flag: db 0
count: db 0
lenth: db 60
a: db 0
c: db 0
str2: db "8206210706 ", 0
num: db "2101", 0
table: db 0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x1F,0x15,0x1F,0x15,0x1F,0x04,0x07,0x03,0x04,0x1C,0x04,0x1F,0x04,0x0E,0x15,0x12,0x0A,0x16,0x0A,0x1F,0x02,0x02,0x02,0x1F,0x12,0x14,0x12,0x1F,0x10,0x10,0x10,0x04,0x1F,0x08,0x14,0x1F,0x04,0x0E,0x15,0x04,0x1F,0x08,0x10,0x0F,0x09,0x0F,0x09
//定义函数
delay:
push bp
mov bp, sp
; t次循环
mov ax, [bp+2]
delay_loop:
dec ax
jnz delay_loop
pop bp
ret
writedat:
push ax
push dx
; 设置数据寄存器
mov RS, 1
mov RW, 0
mov E, 0
mov E, 1
; 写入数据
mov al, [bp+4]
mov P2, al
; 延时
call delay
; 关闭使能
mov E, 0
pop dx
pop ax
ret
writecom:
push ax
push dx
; 设置命令寄存器
mov RS, 0
mov RW, 0
mov E, 0
mov E, 1
; 写入命令
mov al, [bp+4]
mov P2, al
; 延时
call delay
; 关闭使能
mov E, 0
pop dx
pop ax
ret
initlcd:
push ax
; 初始化液晶屏
call writecom, 0x38
call writecom, 0x0c
call writecom, 0x06
call writecom, 0x01
call writecom, 0x40
; 显示字符表
mov cx, 72
mov si, offset table
initlcd_loop:
mov al, [si]
call writedat
inc si
loop initlcd_loop
pop ax
ret
initscon:
push ax
; 初始化串口
mov SCON, 0x50
mov TMOD, 0x20
mov TH1, 253
mov TL1, 253
; 开启中断
setb EA
setb ES
setb TR1
mov IP, 0x01
pop ax
ret
initex0:
; 初始化外部中断0
setb IT0
setb EX0
senddat_function:
push ax
; 发送数据
mov al, a
cmp al, 1
jne senddat_function_flag
mov SBUF, 1
wait_senddat_function_ti:
jb TI, wait_senddat_function_ti
clr TI
mov a, 0
jmp senddat_function_end
senddat_function_flag:
cmp flag, 1
jne senddat_function_end
mov SBUF, 2
wait_senddat_function_ti2:
jb TI, wait_senddat_function_ti2
clr TI
mov flag, 0
senddat_function_end:
pop ax
ret
Show_txt:
push ax
push dx
; 显示单个字符
mov al, [bp+4]
mov dl, [bp+6]
add dl, 0x80
call writecom, dl
call writedat, al
pop dx
pop ax
ret
Show_str:
push ax
push bx
push cx
push dx
; 显示字符串
mov bl, [bp+6]
cmp bl, 0
je Show_str_line_1
cmp bl, 1
je Show_str_line_2
jmp Show_str_end
Show_str_line_1:
mov dl, [bp+4]
add dl, 0x80
call writecom, dl
jmp Show_str_loop
Show_str_line_2:
mov dl, [bp+4]
add dl, 0xc0
call writecom, dl
Show_str_loop:
xor cx, cx
mov si, [bp+8]
mov cx, 16
Show_str_loop_next:
mov al, [si]
call writedat
inc si
loop Show_str_loop_next
Show_str_end:
pop dx
pop cx
pop bx
pop ax
ret
display:
push ax
push bx
; 在第二行显示字符串
call writecom, 0x80+0x40
call delay, 1
mov bx, offset str2
mov cx, 16
display_loop:
mov al, [bx]
call writedat
inc bx
loop display_loop
pop bx
pop ax
ret
main:
; 初始化
call initscon
call initex0
call initlcd
main_loop:
; 发送数据
call senddat_function
; 在第一行显示数字
call Show_txt, 0, 1
call Show_txt, 1, 2
call Show_txt, 2, 3
call writecom, 0x80|3
mov cx, 4
mov si, offset num
main_loop_num:
mov al, [si]
call writedat
inc si
loop main_loop_num
; 在第四行显示字符串
call Show_txt, 7, 4
call Show_txt, 8, 5
call Show_txt, 9, 6
; 在第二行显示字符串
call display
jmp main_loop
ex0_isr:
push ax
push bx
; 处理外部中断0
inc c
cmp c, 1
jne ex0_isr_end
mov a, 1
mov flag, 0
call Show_txt, 0, 1
call Show_txt, 1, 2
call Show_txt, 2, 3
call writecom, 0x80|3
mov cx, 4
mov si, offset num
ex0_isr_num:
mov al, [si]
call writedat
inc si
loop ex0_isr_num
call Show_txt, 7, 4
call Show_txt, 8, 5
call Show_txt, 9, 6
jmp ex0_isr_end
ex0_isr_end:
cmp c, 2
jne ex0_isr_exit
mov flag, 1
mov c, 0
mov a, 0
ex0_isr_exit:
pop bx
pop ax
reti
```
请注意,这只是一种伪代码实现,具体的汇编语言实现可能会因为不同的汇编语言语法而有所不同。
阅读全文