51核心板上面遇到一个问题,打算将用key1,key2,控制led灯的功率,外加将占空比在数码管上输出,代码如下,但没办法正常运行,数码管闪烁,led灯不亮,究竟是什么问题,我找不到问题出在那里
#include <reg52.h>
sbit led1=P2^4;
sbit BEEP=P1^0;
sbit SEL0=P2^0;
sbit SEL1=P2^1;
sbit SEL2=P2^2;
sbit SEL3=P2^3;
sbit key1=P3^2;
sbit key2=P3^3;
static arrshumagaun[]={0x03 , 0x9f , 0x25 , 0x0d , 0x99 , 0x49 , 0x41 , 0x1f , 0x01 , 0x09};
static int i=0,s=0,k=0,m;
static void delay(int nms);
static unsigned int s_iDuty = 50;
static void delay(int nms)
{
int i,j;
for (i=0;i<nms;i++)
{
for (j=0;j<123;j++){}
}
}
static void InitInterrupt(void);
static void InitTimer0(void);
static void InitInterrupt()
{
ET0 = 1;
EA = 1;
}
static void InitTimer0()
{
TMOD = 0x02;
TH0 = 0xFF;
TL0 = 0x9C;
TR0 = 1;
}
void main()
{
InitInterrupt();
InitTimer0();
while (1)
{
if (key1==0)
{
s_iDuty+=10;
}
if (key2==0)
{
s_iDuty-=10;
}
P0=arrshumagaun[s_iDuty];
SEL0=0;
delay(3);
SEL0=1;
P0=arrshumagaun[s_iDuty];
SEL1=0;
delay(3);
SEL1=1;
P0=arrshumagaun[s_iDuty];
SEL2=0;
delay(3);
SEL2=1;
}
}
void Timer0_Handler () interrupt 1
{
static unsigned int s_iCnt1 = 0;
s_iCnt1++;
if(s_iCnt1 >= 100)
{
s_iCnt1 = 0;
}
if(s_iCnt1 <= s_iDuty)
{
led1 = 1;
}
else
{
led1 = 0;
}
}