为什么我的pwm信号传不到中断里面
是switch case函数有问题吗??
#include<reg52.h>
#include "control.h"
#include "12864.h"
#define uchar unsigned char
#define uint unsigned int
sbit A1=P2^2;
sbit A2=P2^3;
sbit ENA=P2^4;
signed int count=0;
unsigned char pwm=100;
unsigned char anjian=0;
uchar numshi=0;
uchar numge=0;
void anjian_dis()
{
numshi=anjian/10;
numge=anjian%10;
write_12864_data(0x30+numshi);
write_12864_data(0x30+numge);
}
void delayms(unsigned int xms)
{
unsigned int i,j;
for(i=0;i<xms;i++)
for(j=0;j<110;j++);
}
void keyscan_1()
{
unsigned char dat=0;
unsigned char num=0;
P1=0xfe;
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
delayms(10);
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
dat=P1;
switch(dat)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(dat!=0xf0)
{
dat=P1;
dat=dat&0xf0;
}
}
}
P1=0xfd;
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
delayms(10);
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
dat=P1;
switch(dat)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(dat!=0xf0)
{
dat=P1;
dat=dat&0xf0;
}
}
}
P1=0xfb;
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
delayms(10);
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
dat=P1;
switch(dat)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=11;
break;
case 0x7b:num=12;
break;
}
while(dat!=0xf0)
{
dat=P1;
dat=dat&0xf0;
}
}
}
P1=0xf7;
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
delayms(10);
dat=P1;
dat=dat&0xf0;
while(dat!=0xf0)
{
dat=P1;
switch(dat)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(dat!=0xf0)
{
dat=P1;
dat=dat&0xf0;
}
}
}
switch(num)
{
case 1:write_12864_addr(1,3);
anjian=0;
pwm=0;
anjian_dis();
break;
case 2:write_12864_addr(1,3);
anjian=10;
pwm=100;
anjian_dis();
break;
case 3:write_12864_addr(1,3);
anjian=20;
pwm=20;
anjian_dis();
break;
case 4:write_12864_addr(1,3);
anjian=30;
pwm=30;
anjian_dis();
break;
case 5:write_12864_addr(1,3);
anjian=40;
pwm=40;
anjian_dis();
break;
case 6:write_12864_addr(1,3);
anjian=50;
pwm=50;
anjian_dis();
break;
case 7:write_12864_addr(1,3);
anjian=60;
pwm=60;
anjian_dis();
break;
case 13:pwm=pwm+5;
break;
case 14:pwm=pwm-5;
break;
case 15:pwm=pwm+1;
break;
case 16:pwm=pwm-1;
break;
default:break;
}
}
void timer0() interrupt 3
{
TH1=(65535-1000)/256;
TL1=(65535-1000)%256;
count++;
if(count>=100)
count=0;
if(count<=pwm)
{
ENA=1;
A1=0;
A2=1;
}
else
{
ENA=0;
A1=0;
A2=1;
}
TR1=1;
}
|