📄 se.c
字号:
#include<reg51.h>
#define temp P1
unsigned char num0=0;
unsigned char round=14;
sbit servopwm=P2^1;
void init()
{
TMOD=0x21;
EA=1;
ET0=1;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
TR0=1;
servopwm=1;
}
void main()
{
init();
while(1)
{
switch(temp)
{
case 0x7f:round=21;break; //P0:01111111
case 0x3f:round=20;break; //P0:00111111
case 0xbf:round=19;break; //P0:10111111
case 0x9f:round=18;break; //P0:10011111
case 0xdf:round=17;break; //P0:11011111
case 0xcf:round=16;break; //P0:11001111
case 0xef:round=15;break; //P0:11101111
case 0xf7:round=13;break; //P0:11110111
case 0xf3:round=12;break; //P0:11110011
case 0xfb:round=11;break; //P0:11111011
case 0xf9:round=10;break; //P0:11111001
case 0xfd:round=9;break; //P0:11111101
case 0xfc:round=8;break; //P0:11111100
case 0xfe:round=7;break; //P0:11111110
default:break;
}
}
}
void timer0() interrupt 1
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
num0++;
if(num0==round)
servopwm=0;
if(num0==200)
{
servopwm=1;
num0=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -