在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2588|回复: 0

求救!关于嵌入式密码锁程序的警告!大家来帮忙!

[复制链接]
发表于 2008-2-16 18:37:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
我已经找了好久都不知道我为什么会有17个警告啊!到底程序有什么问题呢!#include<REGX51.H>
#include<intrins.h>
#define   TwoLine_8bit   56
#define   CLEAR          1
#define   CURSOR_HOME    2
#define   CURSOR_LEFT    4
#define   CURSOR_RIGHT   6
#define   CURSOR_OFF     12
#define   CURSOR_ON      14
#define   CURSOR_BLINK   15
#define   GOTO_LINE_2    192
#define   GOTO_LINE_1    128
#define   ENABLE         1
#define   DISABLE        0
#define   READ           1
#define   WRITE          0
#define   COMMAND        0
#define   DATA           1
#define   rs             P3_5
#define   rw             P3_4
#define   enable         P3_3
#define   XTAL   11059200
#define   TIMER0_COUNT  0xD8F0
#define   DEFAULT        0
#define   UNLOCK         1
#define   INPUT_PASSWORD  10
#define   SET_TIME        11
#define   SET_PASSWORD     12
#define   TRUE            1
#define   FALSE           0
#define   putchar         write_LCD_data
#define   LOCK            P3_7
void        delay100us(unsigned);
void        write_LCD_command(unsigned);
void        write_LCD_data(unsigned);
void        init_LCD(void);
void        clear_LCD(void);
void        display_LCD_string(char*);
void        gotoxy(unsigned,unsigned);
void        display_LCD_number(char);
typedef struct{
  char   hour;
  char   minute;
  char   second;
} time;
typedef struct {
  char   year;
  char   month;
  char   day;
} date;
time now={23,59,0},display;
date today={04,12,31},tmpday;
static unsigned timer0_tick=100,mode=0,operation;
char code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
char code
weekday[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
char code int2char[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
unsigned char password[4]={'1','2','3','4'};
unsigned char code always[4]={'1','2','2','7'};
char code prompt[]="Input password:";
char code old_password[]="Old Password:";
char code new_password[]="New Password:";
char code confirm[]="Confirm Again:";
unsigned char guess[4]={'0','0','0','0'};
unsigned char temp[4]={'0','0','0','0'};
unsigned char txok,c,unlock=0,address;
/*KSYPAN*/
code char key_code[]={0x7E,0xBE,0xBD,0xBB,0xDE,0xDD,0xDB,0xEE,0xED,0xEB,0x7D,0x7B,0xE7,0xD7,0xB7,0x77};
code ksp[4]={0x7E,0xBF,0xDF,0xEF};
void delay (void)
{
   unsigned  char  i,j;
  for(i=0;i<5;i++)
      for(j=0;j<255;j++)
     ;
}
char  keypad_scan()
{
   char key,i;
   P2=0xF0;
   while (P2!=0xF0);
     do{
      for(i=0;i<=3;i++)
      {
      P2=ksp;
         if(P2!=ksp)
         {
           delay();
           key=P2;
           if(key!=ksp)
           {
              return(key);
           }
          }
       }
    }while(1);
}  
char  gotkey()
{
    char  temp,i;
    temp=keypad_scan();
    for (i=0;i<=15;i++)
    {
       if(temp==key_code) return(i);
     }
     return(16);
}
/*DISPLAY*/
char      int2charLCD[]="0123456789";
void      write_LCD_command(unsigned command)
{
   rw=WRITE;
   rs=COMMAND;
   enable=ENABLE;
   P1=command;
   delay100us(0xF060);
   enable=DISABLE;
   rw=1;
}
void  write_LCD_date(unsigned LCDdata)
{
  rw=WRITE;
  rs=DATA;
  enable=ENABLE;
  P1=LCDdata;
  delay100us(0xFF9C);
  enable=DISABLE;
  rw=1;
}
void   init_LCD(void)
{
  write_LCD_command(TwoLine_8bit);
  write_LCD_command(CURSOR_OFF);
  write_LCD_command(CURSOR_RIGHT);
}
void  clear_LCD()
{
  write_LCD_command(CLEAR);
  write_LCD_command(CURSOR_HOME);
}
void  display_LCD_string(char *p)
{
   while(*p)
   {
      write_LCD_data(*p);
      p++;
    }
}
void  display_LCD_number(char unmber)
{
  unsigned char x,y;
  x=unmber/10;
  y=unmber-10*x;
  write_LCD_data(int2charLCD[x]);
  write_LCD_data(int2charLCD[y]);
}
void  gotoxy(unsigned x,unsigned y)
{
  if(x==1)
      write_LCD_command(GOTO_LINE_1+y);
  else
      write_LCD_command(GOTO_LINE_2+y);
}
/*delay100us()*/
void delayt1(unsigned m)
{
TR1=0;
TL1=(m&0x00FF);
TH1=(m>>8);
TR1=1;
while(!TF1);
TF1=TR1=0;
}  
//XIANSHIGONGNEN//
     
char      gotkey();
unsigned  char  read_byte(int);
void      write_byte(int,unsigned char);
void      write_LCD_data(unsigned);
void display_time(void)
{
   gotoxy(1,0);
   display_LCD_number(display.hour);
   display_LCD_string(":");
   display_LCD_number(display.minute);
   display_LCD_string(":");
   display_LCD_number(display.second);
}
void display_date()
{
   char i,days=4;
     gotoxy(2,2);
  display_LCD_number(today.year);
  display_LCD_string("/");
  display_LCD_number(today.month);
  display_LCD_string("/");
  display_LCD_number(today.day);
  display_LCD_string(" ");
  if(today.month>1)
      for(i=0;i<=today.month-2;i++)
       days+=(dayofmonth%7);
   if(tmpday.year !=0 ) days+=((tmpday.year-1)/4)+tmpday.year+1;
   if(today.year%4==0 && today.month >2)  days++;
   days=(days+today.day) %7;
   display_LCD_string(&weekday[days][0]);
}
int getdigit(unsigned char x, unsigned char y)
{
    char  keys;
do{
      gotoxy(x,y);
   putchar('_');
   keys=gotkey();
   gotoxy(x,y);
   putchar(int2char[keys]);
  } while(keys>9);
  return(keys);
}
int getsecret(unsigned char x,unsigned char y)
{
     char   keys;
  do{
   gotoxy(x,y);
   putchar('_');
   keys=gotkey();
   gotoxy(x,y);
   putchar('*');
  }while(keys>9);
  return(keys);
}
void get_password()
{
   char i;
   for(i=0;i<4;i++)
      guess=getsecret(2,i);
}
int check_password()
{
   char i;
   i=0;
   while ((guess==always) && (i < 4)) i++;
   if (i==4)return(TRUE);
   while ((guess==password) && (i < 4)) i++;
   if (i==4)return(TRUE);
   else return(FALSE);
}
int input_new_password()
{
     unsigned char i,j;
  clear_LCD();
  gotoxy(1,0);
  display_LCD_string(new_password);
  for(i=0;i<4;i++)
  temp=getsecret(2,i);
  clear_LCD();
  gotoxy(1,0);
  display_LCD_string(confirm);
  for(i=0; i<4;i++)
  guess=getsecret(2,i);
  i=0;
  while((guess==temp) && (i<4)) i++;
  if (i==4) {
      for (j=0;j<4;j++){
   password[j]=temp[j];
      write_byte(j,password[j]);
  }
  return(TRUE);
}
else return(FALSE);
}      
int gettime()
{
char temp;
do{
while((temp=getdigit(1,0))>2);
     temp=temp*10+getdigit(1,1);
  if (temp >23) display_time();
}while (temp>23);
display.hour=temp;
while((temp=getdigit(1,3))>5);
display.minute=temp*10+getdigit(1,4);
return(TRUE);
}
char monthday(char year,char month)
{
if(month==2 && year%4==0)
return(29);
else
return(dayofmonth[month-1]);
}
int getdate()
{
   char temp,days;
   temp=getdigit(2,3);
   tmpday.year=temp*10+getdigit(2,3);
   do{
   while((temp=getdigit(2,8))>3);
         temp=temp*10+getdigit(2,9);
   days=monthday(tmpday.year,tmpday.month);
if(temp>days||temp==0) display_date();
  }while(temp > days || temp==0);
tmpday.day=temp;
return(TRUE);
}
static void timer0_isr(void) interrupt TF0_VECTOR using 1
{
     TR0=0;
  TL0=(TIMER0_COUNT & 0x00FF);
  TH0=(TIMER0_COUNT >>8);
  TR0=1;
  if(--timer0_tick) return;
  timer0_tick=100;
  if(unlock==1) P3_5=!P3_5;
  now.second++;
  if(now.second==60)
  {
     now.second=0;
  now.minute++;
  if(now.minute==60)
  {
     now.minute=0;
     now.hour++;
     if(now.hour==24)
     {
       now.hour=0;
    today.day++;
  if(today.day>monthday(today.year,today.month))
  {
            today.day=1;
      today.month++;
      if(today.month==13)
      {
         today.month=1;
      today.year++;
    }
}   
     if(operation==DEFAULT)display_date();
     }
  }
  }
if (operation==SET_TIME ) return;
display=now;
if(operation==DEFAULT) display_time();
}
static void timer0_initialize(void)
{
  EA=0;
  TR0=0;
  TMOD &= 0xF0;
  TMOD |=0x01;
  TL0=(TIMER0_COUNT & 0x00FF);
  TH0=(TIMER0_COUNT >> 8);
  PT0=0;
  ET0=1;
  TR0=1;
  EA=1;
}
void main (void)
{
   char keys;
   int i;

   LOCK=1;
   txok=1;
   init_LCD();
   clear_LCD();
   gotoxy(2,0);
   display_LCD_string("20");
   display=now;
   display_time();
   display_date();
   EA=1;
   timer0_initialize();
   IT0=1;
   EX0=1;
   read_byte(0);
   gotoxy(1,8);
   for(i=0;i<4;i++)
           password=read_byte(1);
   do
   {
    keys=gotkey();
       switch (keys)
    {
        case SET_TIME :
          operation=SET_TIME;
    if (gettime()) now=display;
    if (getdate()) {
     today=tmpday;
     display_date();
    }
    operation=0;
    break;
   case INPUT_PASSWORD :
        clear_LCD();
     gotoxy(1,0);
     display_LCD_string(prompt);
     operation=INPUT_PASSWORD;
     get_password();
     clear_LCD();
     gotoxy(1,10);
     if ( check_password())
     {
           LOCK=0;
        display_LCD_string("Right");
    }
    else
        display_LCD_string("Wrong");
    operation=0;
    gotoxy(2,0);
    display_LCD_string("20");
    display_time();
    display_date();
    break;
   case SET_PASSWORD :
        clear_LCD();
     gotoxy(1,0);
     display_LCD_string(old_password);
     operation=SET_PASSWORD;
     get_password();
     if ( check_password())
        if (input_new_password())
     {
       clear_LCD();
       gotoxy(1,10);
       display_LCD_string("OK");
      }
      else
        {
       clear_LCD();
       gotoxy(1,10);
       display_LCD_string("Fail");
      }
            
    else clear_LCD();
    operation=0;
    gotoxy(2,0);
    display_LCD_string("20");
    display_time();
    display_date();
    break;
    }
   }while(1)  ;
}
/*93c66*/
#include  <intrins.h>
#include  <Regx51.h>
//
#define   READ    0x0C00
#define   EWEN    0x0980
#define   WRITE   0x0A00
#define   EWDS    0x0800
//
#define   ShiftBit     4
//
#define   CS      P0_3
#define   SK      P0_2
#define   DI   P0_1
#define   DO   P0_0
//
char code int2charx[]="0123456789ABCDEF";
void         write_command(int);
unsigned char   read_byte(int);
void         check_busy(void);
void         write_LCD_data(unsigned);
//
unsigned char read_byte(int address)
{
   int i,command;
   unsigned char temp;
   CS=1;
   command=(READ|address);
   write_command(command);
   for(i=0;i<8;i++)
   {
   SK=1;
   SK=0;
   temp= (temp << 1);
   if(DO==1)
      temp=(temp| 0x01);
}
CS=0;
return(temp);
}
void write_enable()
{
   int command;
   CS=1;
   command=EWEN;
   write_command(command);
   CS=0;
}  
void write_disable()
{
   int command;
   CS=1;
   command=EWDS;
   write_command(command);
   CS=0;
}      
void write_byte(int address,unsigned char write_data)
{
   int i,command;
   write_enable();
   CS=1;
   command=(WRITE|address);
   write_command(command);
   for(i=0;i<8;i++)
   {
    if(write_data & 0x80)
            DI=1;
    else
            DI=0;
    SK=1;
    SK=0;
    write_data=(write_data<<1);
    }
check_busy();
write_disable();
}
//
void write_command(int command)
{
    int i;
command=(command<<ShiftBit);
for(i=0;i=12;i++)
{
    if(command & 0x8000)
             DI=1;
    else
             DI=0;
    SK=1;
    SK=0;
    command=(command<<1);
}   
}  
//
void check_busy(void)
{
   CS=0;
   CS=1;
   while(DO==0);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-2-8 23:48 , Processed in 0.029059 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表