⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一体化锁主程序
💻 C
字号:
/*
+---------------------------------------------------+
| Project: MAIN with STC89C5X                       |
| File:    MAIN.c                                   |
| Data:    2008-12-04                               |
| Version: V 1.0                                    |
| Initial Editor: Li Jifeng                         |
+---------------------------------------------------+
| following environments are supported              |
| Processor: STC89C5X                               |
| Compiler: WAVE V                                  |
| hardware: JF-2008                                 |
+---------------------------------------------------+
|    Copyright (C) JF Ltd, 2008                     |
|       All Rights reserved                         |
+---------------------------------------------------+
| 功能简介: the main function                       |
+---------------------------------------------------+
*/

#include "system.h"

extern bit timer_flag,timer2_out;
extern bit uart_rcv_finish,D0_flag;
extern UINT8 data card[14];
extern UINT16 data LOADP,LOADPP;
extern UINT16 data SAVEP,timer2_tick;
extern UINT8 data I2C_rcv[16];
extern UINT16  Rxsum;
extern UINT16  Rxsum1;
extern UINT8 xdata addr;
extern UINT8 data rec_buf[8];
//extern bit timer0_out;
UINT8 idata card1[12];
bit getspi_flag,open_flag,nopen_flag;

main()
{
    UINT8 i;
    sys_init();
    while (1)
    {
       //WDT_CONTR = 0x3C;             //喂狗
       if (uart_rcv_finish)
       {
          uart_rcv_finish = 0;
          control();
       }
       if(!timer_flag)
         if(!MCLK)
         {
           if(!getspi(card1,12))
             getspi_flag = 1;
              //control2();
              //uart_send1(card,12);
         }
       if (uart_rcv_finish)
       {
          uart_rcv_finish = 0;
          control();
       }
       if(getspi_flag == 1)
       {
          getspi_flag = 0;
          control2();
       }
       if(timer2_out)
       {
          if(!P2_7)
          {
             for(i=0;i<80;i++);
             if(!P2_7)
             {
                open_flag = 1;
             }
          }
          else
          {
             if(open_flag)
             {
                open_flag = 0;
                card[0] = 0;
                card[1] = 0;
                card[2] = 0;
                card[3] = 0;
                card[4] = 0;
                card[5] = 0x20;
                card[6] = read_time_byte(0x8d);//sys_year;       //读系统时间 --- 年
                card[7] = read_time_byte(0x89);//sys_mon;       //读系统时间 --- 月
                card[8] = read_time_byte(0x87);//sys_date;       //读系统时间 --- 日
                card[9] = read_time_byte(0x85);//sys_hour;       //读系统时间 --- 时
                card[10] = read_time_byte(0x83);//sys_min;      //读系统时间 --- 分
                card[11] = read_time_byte(0x81);//sys_second;      //读系统时间 --- 秒
                card[12] = 0x40;
                card[13] = 0x04;
                if(D0_flag)
                {
                   if(SAVEP == LOADP)
                   {
                      LOADP++;
                      SAVEP++;
                      if(SAVEP > 0x1FF)
                      {
                         LOADP = 0;
                         SAVEP = 0;
                         I2C_rcv[1] = 0;
                         I2C_rcv[2] = 0;
                         I2C_rcv[3] = 0;
                         I2C_rcv[4] = 0;
                         AT24C128_write(0x01,I2C_rcv+1,4);
                         AT24C128_write(0x2000 + 0x1FF*16,card,14);
                      }
                      else
                      {
                         I2C_rcv[3] = (SAVEP >> 8) & 0x00ff;
                         I2C_rcv[4] = SAVEP& 0x00ff;
                         AT24C128_write(0x03,I2C_rcv+3,2);
                         AT24C128_write(0x2000 + (SAVEP-1)*16,card,14);
                      }
                   }
                   else
                   {
                      SAVEP++;
                      if(SAVEP > 0x1FF)
                      {
                         SAVEP = 0;
                         D0_flag = 1;
                         I2C_rcv[3] = (SAVEP >> 8) & 0x00ff;
                         I2C_rcv[4] = SAVEP& 0x00ff;
                         I2C_rcv[5] |= 0x01;
                         AT24C128_write(0x03,I2C_rcv+3,3);
                         AT24C128_write(0x2000 + (SAVEP-1)*16,card,14);
                      }
                      else
                      {
                         I2C_rcv[3] = (SAVEP >> 8) & 0x00ff;
                         I2C_rcv[4] = SAVEP& 0x00ff;
                         AT24C128_write(0x03,I2C_rcv+3,2);
                         AT24C128_write(0x2000 + (SAVEP-1)*16,card,14);
                      }
                   }
                }
                else
                {
                   SAVEP++;
                   if(SAVEP > 0x1FF)
                   {
                      SAVEP = 0;
                      D0_flag = 1;
                      I2C_rcv[3] = 0;
                      I2C_rcv[4] = 0;
                      I2C_rcv[5] = 1;
                      AT24C128_write(0x03,I2C_rcv+3,3);
                      AT24C128_write(0x2000 + 0x1FF*16,card,14);
                   }
                   else
                   {
                      I2C_rcv[3] = (SAVEP >> 8) & 0x00ff;
                      I2C_rcv[4] = SAVEP& 0x00ff;
                      AT24C128_write(0x03,I2C_rcv+3,2);
                      AT24C128_write(0x2000 + (SAVEP-1)*16,card,14);
                   }
                }
                timer2_tick = 20;
                timer2_out = 0;
                nopen_flag = 1;
             }
          }
       }
       if(addr != P0)
       {
           addr = P0;
           rec_buf[2] = hex_asc((addr >> 4)&0x0F);
           rec_buf[3] = hex_asc(addr&0x0F);
           Rxsum1 = Rxsum + rec_buf[2] + rec_buf[3] + rec_buf[5];
       }
       /*if(timer0_out)
       {
          timer0_out = 0;
          sys_second = read_time_byte(0x81);     //读系统时间 --- 秒
          sys_min = read_time_byte(0x83);        //读系统时间 --- 分
          sys_hour = read_time_byte(0x85);       //读系统时间 --- 时
          sys_date = read_time_byte(0x87);       //读系统时间 --- 日
          sys_mon = read_time_byte(0x89);        //读系统时间 --- 月
          sys_week = read_time_byte(0x8b);       //读系统时间 --- 星期
          sys_year = read_time_byte(0x8d);       //读系统时间 --- 年
       }*/
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -