仿真电路四-独立按键123456789101112131415161718192021222324252627282930313233343536#include "reg51.h"sbit key=P0^0;char num[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};int n=0;void delay(unsigned int n){ int i,j; for(i=0;i<n;i++) for(j=0;j<500;j++);}void keyfun(){ if(key==0) { delay(50); if(key==0) n++; } if(n==10) n=0;}void smg(){ P2=num[n];}int main(){ while(1) { keyfun(); smg(); }} 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include "reg51.h"sbit key=P0^0;char num[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};int n=0,sign=0;void delay(unsigned int n){ int i,j; for(i=0;i<n;i++) for(j=0;j<500;j++);}void keyfun(){ if(key==0&&sign==0) { delay(10); if(key==0&&sign==0) { sign=1; n++; } } if(key==1&&sign==1) { delay(10); if(key==1&&sign==1) { sign=0; } } if(n==10) n=0;}void smg(){ P2=num[n];}int main(){ while(1) { keyfun(); smg(); }}