3、>charled_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};voiddelay(unsignedinttime){unsignedintj=0;for(;time>0;time--)for(j=0;j<125;j++);}voidmain(void){chari=0;while(1){for(i=0;i<=9;i++);delay(500);}}}实例5:#includesbitP3_7=P3^7;unsignedcharcodetable[]={0x3f,0x06,0x
4、5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsignedcharcount;voiddelay(unsignedinttime){unsignedintj=0;for(;time>0;time--)for(j=0;j>125;j++);}voidmain(void){count=0;P0=table[count/10];P2=table[count%10];while(1){if(P3_7==0){delay(10);if(P3_7==0){count++;if(count==100)count=0;P0=table[cou
5、nt/10];P2=table[count%10];while(P3_7==0);}}}}实例7:行列式键盘编程#includecharled_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};charkey_buf[]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,0xeb,0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77};voidgetKey(void){ch
6、arkey_scan[]={0xef,0xdf,0xbf,0x7f};chari=0,j=0;for(i=0;i<4;i++){P3=key_scan[i];if(P3!=0xff){for(j=0;j<16;j++){if(key_buf[j]==P3)returnj;}}}return=-1;}voidmain(void){charkey=0;P2=0x00;while(1){key=getKey();if(key!=-1)P2=led_mod[key];}}第五章实例1单片机开关状态检测在单片机的INT0端口接一开关,P1.0口接一发光二极管。每次开关闭合
7、(接地)时,发光二极管改变一次状态。程序如下#includesbitP1_0=P1^0;int0_srv()interrupt0{P1_0=!P1_0;}voidmain(){IT0=1;EX0=1;EA=1;while(1);}实例2中断扫描法行列式键盘#includecharled_mod[]={0x3f,0x06,0x5b,};charkey_buf[]={0x11,……};voidgetKey()interrupt0{charkey_scan[]={0xef,0xdf,0xbf,0x7f};chari=0,j=0;fo
8、r(i=0;i<4;i+