#include#define uint unsigned int#define uchar unsigned charsbit rck=P0^0;sbit sck=P0^1;sbit si=P0^2;sbit key1=P1^0;//按鍵接在P1^0口sbit key2=P1^1;//按鍵接在P1^1口uint b=0,a=0,c=0;//全局定義并賦初值uchar code num[]={0x80,0xed,0x42,0x48,0x2c,0x18,0x10,0xcc,0x00,0x08};void write_date(uchar temp){uint i;for(i=0;i<8;i++){temp>>=1;sck=0;si=CY;sck=1;}}void key(){if(key1==0)//如果按鍵1被拉為低電平{ while(!key1);//由低電平變?yōu)楦唠娖剑词炙砷_),則執(zhí)行下面語句b++; if(b==9)b=0;//如果b=0,則重新調(diào)零 }else if(key2==0)//分析方法同key1{while(!key2);a++;if(a==9)a=0;}write_date(num[b]);write_date(num[a]); rck=0;rck=1;}void main(){ write_date(num[0]);write_date(num[0]); while(1)//掃描按鍵是否被按,如果其中的一個(gè)被按或兩個(gè)同時(shí)被按,則執(zhí)行{ key();//調(diào)用key函數(shù) } }
評(píng)論