|
本帖最后由 paulhyde 于 2014-9-15 09:15 编辑
键盘不能控制pwm波,数码管显示也不明显,我4个端口都用完了,能用p3口连接矩阵键盘吗
头文件内容
#include
#include
#define uchar unsigned char
uchar code Matrix_Keyboard[]={0xf7,0xfb,0xfd,0xfe};
void delay_1ms(void) //1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延时函数
{
unsigned int i=0;
for (i=0;i> 4)
{
case 0x07:
return loop_key*4+0;
case 0x0b:
return loop_key*4+1;
case 0x0d:
return loop_key*4+2;
case 0x0e:
return loop_key*4+3;
}
}
}
//5ms去抖
return 16; //表示无输入
}
.c文件内容
//PWM控制LED的亮度,渐灭到渐亮
#include
#include"readkey.h"
#define uchar unsigned char
uchar keynum=16;
uchar code SEG7[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code ACT[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void mdelay(unsigned int m); ///m*1ms的延时子程序
void disp( unsigned char i ,uchar num); ///显示子函数,在第i个数码管显示内容是num
void xianshi(void);////显示主函数。
int high;
unsigned int i=0;
unsigned int number;
unsigned char number1,number2,number3,number4;
void t0(void)interrupt 1 /////////////定时器0中断程序
{
TH0=0xff;
TL0=0xbd;
i++;
if(i0;m--)
{
for(r=0;r<124;r++)
{;}
}
}
void disp( unsigned char i ,uchar num) ////在第i个数码管显示内容是num
{
switch(i)
{
case 1:P1=ACT[7];
P0=SEG7[num];
mdelay(1);
break;
case 2:P1=ACT[6];
P0=SEG7[num];
mdelay(1);
break;
case 3:P1=ACT[5];
P0=SEG7[num];
mdelay(1);
break;
case 4:P1=ACT[4];
P0=SEG7[num];
mdelay(1);
break;
}
}
void xianshi(void)
{
disp(1,number1);
disp(2,number2);
disp(3,number3);
disp(4,number4);
}
|
|