STC89C52单片机程序中的判断无效,输出出现错乱,跪求各位大佬指点
加上“if(i<6)”的判断时,按键不起作用,不加时,按键起作用,但是OLED上的输出位置错乱,恳请各位指点
主要单片机代码如下:
- #include<reg52.h>
- #include<OLED.h>
- #include<intrins.h>
- sbit b1=P2^0;
- sbit b2=P3^3;
- sbit b3=P2^1;
- sbit b4=P2^2;
- sbit b5=P4^2;
- sbit b6=P4^3;
- sbit bee=P2^4;
- sbit b10=P1^0;
- unsigned int keyword[6];
- unsigned int right_word[6]={1,3,1,4,2,1};
- unsigned int location[6]={10,30,50,70,90,105};
- unsigned int t=0;
- void delay(int ms)
- {
- int ii,jj;
- if (ms<1) ms=1;
- for(ii=0;ii<ms;ii++)
- for(jj=0;jj<500;jj++);
- }
- void start()
- {
- bee=0;
- delay(10);
- OLED_Init();
- OLED_CLS();
- OLED_Fill(0x00);
- OLED_P14x16Ch(25,1,0);
- OLED_P14x16Ch(39,1,1);
- OLED_P14x16Ch(53,1,2);
- OLED_P14x16Ch(67,1,3); //显示密码文字//
- OLED_P14x16Ch(81,1,4);
- }
- void beep()
- {
- delay(20);
- bee=1;
- delay(100);
- bee=0;
- }
- void data_input(unsigned int i)
- {
- start();
- while(1)
- {
- if(i<=5)
- {
- if(b1==0)
- {
- delay(20);
- while(!b1);
- beep();
- keyword[i]=1;
- OLED_P6x8Str(location[i],5,"1");
- i++;
- }
-
- if(b5==0)
- {
- delay(20);
- while(!b5);
- beep();
- keyword[i]=2;
- OLED_P6x8Str(location[i],5,"2");
- i++;
- }
-
- if(b2==0)
- {
- delay(20);
- while(!b2);
- beep();
- keyword[i]=3;
- OLED_P6x8Str(location[i],5,"3");
- i++;
- }
-
- if(b6==0)
- {
- delay(20);
- while(!b6);
- beep();
- keyword[i]=4;
- OLED_P6x8Str(location[i],5,"4");
- i++;
- }
- }
- }
- }
- void main()
- {
- data_input(t);
- }
复制代码
|