回复 10# McuPlayer2013
嗯,谢谢,真值表已经弄清楚了。
这是按键0-9累加程序,但是显示的很暗,不知道为什么
#include<c:\Keil\C51\INC\STC\STC12c5a60S2.H>
#define uchar unsigned char
#define uint unsigned int
sbit COM4=P2^3;
sbit COM3=P2^2;
sbit COM2=P2^1;
sbit COM1=P2^0;
sbit COMG=P3^2;
sbit SEGG=P3^3;
sbit key1=P2^7;
sbit key2=P2^6;
unsigned char i=0,j=9;
unsigned char C1[10]={0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01};
unsigned char C2[10]={0x03,0x02,0x02,0x02,0x03,0x01,0x01,0x02,0x03,0x03};
unsigned char C3[10]={0x01,0x00,0x03,0x02,0x02,0x02,0x03,0x00,0x03,0x02};
unsigned char C4[10]={0x03,0x02,0x01,0x03,0x02,0x03,0x03,0x02,0x03,0x03};
/****************????******************/
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/************??????********************/
key()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
i++;
if(i>9)
i=0;
while(key1==0);
}
}
}
keyz()
{
if(key2==0)
{
delay(10);
if(key2==0)
{
i--;
if(j<0)
i=9;
while(key2==0);
}
}
}/************???********************/
void main(void)
{
P0=i;
while(1)
{
key(); //??????
keyz();
/******************??????******************/
P2=0x0e; //COM????
P0= C1; //seg???
COMG=0; //com???
SEGG=1; //seg???
delay(3);
P2=~0x0e;
P0=~ C1;
COMG=1;
SEGG=0;
delay(3);
P2=0x0D;
P0= C2;
COMG=0;
SEGG=1;
delay(3);
P2=~0x0D;
P0=~ C1;
COMG=1;
SEGG=0;
delay(3);
P2=0x0B;
P0= C3;
COMG=0;
SEGG=1;
delay(3);
P2=~0x0B;
P0=~ C3;
COMG=1;
SEGG=0;
delay(3);
P2=0x07;
COMG=0;
P0= C4;
SEGG=1;
delay(3);
P2=~0x07;
P0=~C4;
COMG=1;
SEGG=0;
delay(3);
}
} |