當按鍵按下 0329的時候,正確顯示。為什么一樣的代碼,輸入1129卻不行?永遠無法和RecordDate_2匹配上
單片機源程序如下:
- #include <stc15.h>
- #include <string.h>
- #include "LCD1602.h"
- #include "delay.h"
- #include "MatrixKey.h"
- //#include "timer0.h"
- //#include "key.h"
- void main(void)
- {
- unsigned char Key_Number='x';
- // extern unsigned char Key_Flag;
- // char RecordDate[6]="xxxxx";
- // const char RecordDate_1[6]="03-29";
- // const char RecordDate_2[6]="11-19";
- char RecordDate[6]={'\0','\0','\0','\0','\0','\0'};
- const char RecordDate_1[6]={'0','3','-','2','9','\0'};
- const char RecordDate_2[6]={'1','1','-','2','9','\0'};
- unsigned char i=0,j=0,k=0;
- P0M0=0X00;
- P0M1=0X00;
- P1M0=0X00;
- P1M1=0X00;
- P2M0=0X00;
- P2M1=0X00;
- P3M0=0X00;
- P3M1=0X00;
- // Timer0_Init();
- LCD_Init();
- LCD_ShowString(1,1," Enter a Date:");
- while(1)
- {
- for(i=0;i<6;)
- {
- if(i==2)
- {
- RecordDate[i]='-';
- LCD_ShowChar(2,i+1,RecordDate[i]);
- Key_Number='x';
- i++;
- continue;
- }
- if(i==5)
- {
- RecordDate[i]='\0';
- Key_Number='x';
- i++;
- break;
- }
-
- Key_Number=MatrixKey();
-
- if('0'<=Key_Number&&Key_Number<='9'&&Key_Number!='*'&&Key_Number!='#') //如果按下的按鍵編碼為0-9(ASCII碼),輸入日期
- {
- RecordDate[i]=Key_Number;
- Key_Number='x';
- LCD_ShowChar(2,i+1,RecordDate[i]);
- i++;
- }
- if(Key_Number=='*')
- {
- LCD_ShowString(2,1," ");
- Key_Number='x';
- i=0;
- }
- if(Key_Number=='#')
- {
- if(!strcmp(RecordDate,RecordDate_1)||!(RecordDate,RecordDate_2))
- {
- LCD_ShowString(2,1," OK");
- delay(5000);
-
- if(!strcmp(RecordDate,RecordDate_1))
- {
- LCD_ShowString(1,1,"Date: ");
- LCD_ShowString(1,6,RecordDate);
- LCD_ShowString(2,1," Playing");
- delay(50000);
- LCD_ShowString(1,1,"Enter a Date: ");
- LCD_ShowString(2,1," ");
-
- //動作1-P30=1;
-
- Key_Number='x';
- i=0;
- for(j=0;j<6;j++)
- {
- RecordDate[j]='\0';
- }
- }
- if(!strcmp(RecordDate,RecordDate_2))
- {
- LCD_ShowString(1,1,"Date: ");
- LCD_ShowString(1,6,RecordDate);
- LCD_ShowString(2,1," Playing");
- delay(50000);
- LCD_ShowString(1,1,"Enter a Date: ");
- LCD_ShowString(2,1," ");
-
- //動作2-P31=1;
-
- Key_Number='x';
- i=0;
- for(j=0;j<6;j++)
- {
- RecordDate[j]='\0';
- }
- }
-
- }
- else
- {
- LCD_ShowString(2,1," Error");
- delay(5000);
- LCD_ShowString(2,1," ");
- Key_Number='x';
- i=0;
- for(k=0;k<6;k++)
- {
- RecordDate[k]='\0';
- }
- }
- }
- }
- }
- }
復制代碼
|