根据下列c语言写出功能相同的汇编代码#include<reg52.h> #include<stdio.h> #include"delay.h" #include"LCD1602.h" sbit DCOUT = P2^5; sbit key1=P1^0; sbit key2=P1^1; sbit key3=P1^2; sbit key4=P1^3; sbit m=P2^0; sbit n=P2^1; unsigned char PWM_ON,S; #define CYCLE 12 void Init_Timer0(void); void main (void) { int S=0; char displaytemp[16]; PWM_ON=0; LCD_Init(); Init_Timer0(); LCD_Write_String(2,1,"V:"); while (1) { if(key3==0) { DelayMs(10); if(key3==0) { if(PWM_ON<CYCLE) PWM_ON++; S++; if(S>=12)S=12; } while(!key3); } else if(key4==0) { DelayMs(10); if(key4==0) { if(PWM_ON>0) PWM_ON--; S--; if(S<=0)S=0; } while(!key4); } if(key1==0) { DelayMs(10); if(key1==0) { m=1;n=0; LCD_Write_String(0,0,"T"); } while(!key1); } else if(key2==0) { DelayMs(10); if(key2==0) { m=0;n=1; LCD_Write_String(0,0,"N"); } while(!key2); } sprintf(displaytemp,"%3d",S); LCD_Write_String(4,1,displaytemp); } } void Init_Timer0(void) { TMOD |= 0x01; //TH0=0x00; //TL0=0x00; EA=1; ET0=1; TR0=1; } void Timer0_isr(void) interrupt 1 { static unsigned char count; TH0=(65536-2000)/256; TL0=(65536-2000)%256; if (count==PWM_ON) { DCOUT = 0; } count++; if(count == CYCLE) { count=0; if(PWM_ON!=0) DCOUT = 1; } }
时间: 2024-02-14 14:17:01 浏览: 66
以下是功能相同的汇编代码:
```
#include <reg52.h>
sbit DCOUT = P2^5;
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit key3 = P1^2;
sbit key4 = P1^3;
sbit m = P2^0;
sbit n = P2^1;
unsigned char PWM_ON, S;
#define CYCLE 12
void Init_Timer0(void);
void main (void) {
int S = 0;
char displaytemp[16];
PWM_ON = 0;
LCD_Init();
Init_Timer0();
LCD_Write_String(2, 1, "V:");
while (1) {
if (key3 == 0) {
DelayMs(10);
if (key3 == 0) {
if (PWM_ON < CYCLE) {
PWM_ON++;
S++;
if (S >= 12) S = 12;
}
while (!key3);
}
} else if (key4 == 0) {
DelayMs(10);
if (key4 == 0) {
if (PWM_ON > 0) {
PWM_ON--;
S--;
if (S <= 0) S = 0;
}
while (!key4);
}
}
if (key1 == 0) {
DelayMs(10);
if (key1 == 0) {
m = 1;
n = 0;
LCD_Write_String(0, 0, "T");
}
while (!key1);
} else if (key2 == 0) {
DelayMs(10);
if (key2 == 0) {
m = 0;
n = 1;
LCD_Write_String(0, 0, "N");
}
while (!key2);
}
sprintf(displaytemp, "%3d", S);
LCD_Write_String(4, 1, displaytemp);
}
}
void Init_Timer0(void) {
TMOD |= 0x01;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Timer0_isr(void) interrupt 1 {
static unsigned char count;
TH0 = (65536 - 2000) / 256;
TL0 = (65536 - 2000) % 256;
if (count == PWM_ON) {
DCOUT = 0;
}
count++;
if (count == CYCLE) {
count = 0;
if (PWM_ON != 0) DCOUT = 1;
}
}
```
阅读全文