C语言正确,我想把它转变成汇编的形式,但没转换成,出错了,求赐教
程序代码:
#include<reg51.h> #define uint unsigned int #define uchar unsigned char uchar shi,ge,aa,keycount=0,temp; sbit anjian=P1^7; uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void display(shi,ge); void key (); void init(); void delay(uint z); /*-----主程序-----*/ void main() { init(); //初始化 while(1) { key (); if(keycount==1) TR0=1; //开中断 if(keycount==2) TR0=0; if(keycount==3) { temp=0; keycount=0; } if(aa==10){aa=0; if(temp<=99) { temp++;display(shi,ge); } else temp=0;} } } /*------初始化程序-------*/ void init() { keycount=0; temp=0; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; //TR0=0; } /*-----定时器中断-----*/ void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; aa++; } /*-----显示子程序-----*/ void display(shi,ge) { shi=temp/10; ge=temp%10; P0=table[shi];;delay(70); P2=table[ge]; ;delay(70); } /*-----按键检测子程序-----*/ void key () { if(anjian==0) { delay(5); //消抖 if(anjian==0) keycount++; } //while(anjian==0); //display(shi,ge); //等待按键弹起 } /*-----延时子程序-----*/ void delay(uint z) //延时约1ms { uint x,y; for(x=z;x>0;x--) for(y=100;y>0;y--); }
程序代码:
ORG 0000H ajmp START org 000bh ajmp timer0 anjian equ P1.7 keycount equ 40h shi equ 41h gewei equ 42h aa equ 43h temp equ 44h tab: db 3fh,6h,5bh,4fh,66h db 6dh,7dh,7h,7fh,6fh acall init START: //位为1转移 key 按键判断 acall key //加1指令 JNB keycount,F1 // SETB TR0 F1: mov r0,keycount cjne r0,#2,F2 clr TR0 F2: mov r0,keycount cjne r0,#3,F3 mov temp,#0 mov keycount,#0 F3: mov r0,aa cjne r0,#10,F4 mov aa,#0 mov r0,temp cjne r0,#100,F5 AJMP F4 F5: inc temp acall display F4: mov temp,#0 key: jb anjian,F6 ACALL delay5 jb anjian,F6 inc keycount F6: ret init: mov keycount,#0 mov temp,#1 mov tmod,#01h mov TH0,#60 mov TL0,#176 setb EA setb ET0 ret display: mov a,temp mov b,#10 div ab mov r2,A //r2 十位 r3 个位 查表 mov r3,B mov dptr,#tab mov a,r2 movc a,@a+dptr mov P0,a acall delay70 nop nop mov a,r3 movc a,@a+dptr mov P2,a nop nop acall delay70 reti delay70: mov r6,#70 D2: mov R7,#248 d1: djnz R7,d1 djnz R6,D2 ret delay5: mov r6,#5 F7: mov R7,#248 F8: djnz r7,F8 djnz r6,F7 ret timer0: mov TH0,#60 mov TL0,#176 cpl p1.0 inc aa //中断函数 ret end
就是这样子,