#include <reg51.H> #include <STDIO.H> //输入输出库函数头文件 #include <CTYPE.H> //字符操作函数头文件 #include <STRING.H> //串操作函数头文件 #include <INTRINS.H> //内联函数头文件 #include <STDLIB.H> //杂函数头文件 sfr p4 = 0xe8; sbit p4_0 = 0xe8;//DATA sbit p4_1 = 0xe9;//PLUS sbit key1 = P0^2; sbit key2 = P0^3; sbit key3 = P0^4; #define uchar unsigned char #define uint unsigned int uchar code sseg[]={0xee, 0x28, 0xcd, 0x6d, 0x2b, 0x67, 0xe7, 0x2c, 0xef, 0x6f, 0xaf, 0xe3, 0xc6, 0xe9, 0xc7, 0x87, 0x00 }; uchar dispsbuff[]={16,16, 16, 16,16,16,0,0,0,0}; uchar fengji[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf}; void Delay10us(uchar us) //延时10us {do { _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); }while(--us); }
void Delay1ms(void) //延时1ms { Delay10us(100); } void Delay10ms(void) //延时10ms { uint i; for(i=0;i<=9;i++) { Delay1ms(); } } void Delay500ms(void) //延时500ms { uint i; for(i=0;i<50;i++) { Delay10ms(); } } void send(uchar ch)//send { uchar j; for(j=0;j<8;j++) { p4_0=ch&0x01; p4_1 =0; p4_1 = 1; ch >>= 1; } } void dis(void) { uchar j; for(j=0;j<10;j++) { send(sseg[dispsbuff][j]]); } }
bit judge_k() { bit y; if(key1==0) Delay10ms(); if(key1==0) y=~y; return y; }
main() {bit k; uchar keyvalue=1; uchar i; Delay500ms(); dis(); k=judge_k(); if(k==1) { while(k==1) { for(i=0;i<=5;i++) { Delay500ms(); P1=fengji; dispsbuff[6]=keyvalue; dis(); k=judge_k(); if(k==0) break; //如果此处跳出i=3,keyvalue=4 ++keyvalue; if(i>=5) keyvalue=1; } continue; } } if(k==0) { P1=fengji;// i=3,keyvalue=4为啥传不到这呢? dispsbuff[6]=keyvalue;//要想实现,咋办呢? dis(); if(key2==0) Delay10ms(); if(key2==0) { if(i<=5) { ++i; ++keyvalue; P1=fengji; dispsbuff[6]=keyvalue; dis(); }else { i=0; keyvalue=1; } } if(key3==0) Delay10ms(); if(key3==0) { if(i<=5) { --i; --keyvalue; P1=fengji; dispsbuff[6]=keyvalue; dis(); }else { i=0; keyvalue=1; } }
}
}
|