本帖最后由 gdqinci 于 2010-5-21 22:50 编辑
枚举类型实验
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
//----------------------------------------------------------------------
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(uint k);
//----------------------------------------------------------------------
enum week_day{mon=1,tue,wed,thu,fri,sat,sun};
enum week_day day;
//---------------------------------------------------------
void key_scan(void)
{
uchar temp;
P3=0xff;
temp=P3;
if(temp!=0xff)
{
switch(temp)
{
case 0xfb:day=mon;break;
case 0xf7:day=tue;break;
case 0xf3:day=wed;break;
case 0xef:day=thu;break;
case 0xeb:day=fri;break;
case 0xe7:day=sat;break;
case 0xe3:day=sun;break;
default:break;
}
}
}
//==================================
void main(void)
{
for(;;)
{
key_scan();
P0=SEG7[day];
P2=ACT[0];
delay(300);
}
}
//========================================
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<121;j++)
{;}
}
} |