这是代码在附件里这是要求
原理图也在附件里了
麻烦大佬们看看我的错误在哪
谢谢了
#include "reg52.h" #define uchar unsigned char #define uint unsigned int sbit dula=P2^6; sbit wela=P2^7; char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; uint num; void delayms(uint); int apple,pear,a; void knowledge(int,int,int); uchar num1,ge,shi,bai,qian; void display(uchar,uchar,uchar,uchar);
void display(uchar ge,uchar shi,ucharbai,uchar qian) //计时器部分 {
dula=1; P0=table[qian]; dula=0; P0=0xff; wela=1; P0=0XFE; wela=0; delayms(5);
dula=1; P0=table[bai]; dula=0; P0=0XFd; wela=1; P0=0XFd; wela=0; delayms(5);
dula=1; P0=table[shi]; dula=0; P0=0xff; wela=1; P0=0XFb; wela=0; delayms(5);
dula=1; P0=table[ge]; dula=0; P0=0xff; wela=1; P0=0XF7; wela=0; delayms(5);
}
void delayms(uint times) { uinti,j; for(i=0;i<60;i++) for(j=0;j>times;j++); }
void T1_time() interrupt 1 { TH0=(65536-18432)/256; TL0=(65536-18432)%256; num1++; if(num1==50) { num1=0; num++; if(num ==1000) TR0=0; qian= num/1000%10; bai=num/100%10; shi= num/10%10; ge=num%10;
}
}
void knowledge(int apple,pear,a) //矩阵按键部分 { P3= 0xf0; apple = P3&0xf0;
if(apple!=0xf0) { P3 = 0xf0; apple = P3&0xf0; delayms(10); if(apple!=0xf0) { P3= 0xf0; apple = P3&0xf0; switch(apple) { case(0xe0):pear ==0;break; case(0xd0):pear= 1;break; case(0xb0):pear= 2;break; case(0x70):pear= 3;break; } P3 = 0x0f; apple =P3; switch(apple) { case(0x0e):pear =pear;break; case(0x0d):pear=pear+4;break; case(0x0b):pear=pear+8;break; case(0x07):pear=pear+12;break; }
delayms(50); dula=1; P0=table[pear]; dula=0; P0=0xff; wela=1; P0=0X7f; wela=0; delayms(5); P0=0xff;
} } } void main() { TMOD=0X01; ET0=1; TR0=1; TH0=(65536-18432)/256; TL0=(65536-18432)%256; EA=1; dula= 0; while(1) { knowledge(apple,pear,a); display(ge,shi, bai, qian); } } ...
|