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

📄 main.c

📁 mcs51,2051,x86系列MCU
💻 C
字号:
##80C251SA ALL#
##80C251SB ALL#
##80C251SP ALL#
##80C251SQ ALL#
##80C151SX ALL#
/*
 *  ApBUILDER CODE FILE - Intel Corporation
 *
 *
 *  Purpose:            Main file distributed for "FULL^CODE" generation on 251SX, and 8X930AX families.
 *
 *                      Contains main(), calls to initialization routines for peripherals.
 *
 *                      The Software is provided "AS IS."
 *
 *                      LIMITATION OF LIABILITY:    NEITHER INTEL NOR ITS VENDORS OR AGENTS
 *                      SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
 *                      INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
 *                      CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
 *                      OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 *                      While we have made every attempt to completely test this code, we request that
 *                      you personally test it completely prior to actual inclusion in your own projects.
 *
 *  Compiler:           Developed using Compass251 from Production Languages corporation.
 *
 *  Ext Packages:       None
 *
 *  Author:             Brad B.
 *
 *  Revisions:
 *
 *
 *
 *
 */

#include "global.h"
#include "main.h"
#include "timer.h"
#include "serial.h"
#include "misc.h"


/* These must be located at specific addresses in ROM for the device.  Shown here only for reference
UConfig0 = 0x$$CONFIG0$;
UConfig1 = 0x$$CONFIG1$;
*/


/* function prototypes */
static void Init_all(void);


/* Constant array of SFR values.. Filled in by ApBUILDER during code-generation.  Used in Init routine below */
const char sfrs[] =
{
   0x$$IE0$,      /* IE0 */     0x$$IPL0$,     /* IPL0 */      0x$$IPH0$,     /* IPH0 */    0x$$CL$,       /* CL */
   0x$$CH$,       /* CH */      0x$$CMOD$,     /* CMOD */      0x$$CCON$,     /* CCON */    0x$$PCATYPE$,  /* PCATYPE Flag */
   0x$$TMOD$,     /* TMOD */    0x$$TL0$,      /* TL0 */       0x$$TH0$,      /* TH0 */     0x$$TL1$,      /* TL1 */
   0x$$TH1$,      /* TH1 */     0x$$TL2$,      /* TL2 */       0x$$TH2$,      /* TH2 */     0x$$RCAP2L$,   /* RCAP2L */
   0x$$RCAP2H$,   /* RCAP2H */  0x$$T2MODES$,  /* T2 Modes */  0x$$PCON$,     /* PCON */    0x$$WCON$,     /* WCON */
   0x$$T2MOD$,    /* T2MOD */   0x$$T2CON$,    /* T2CON */     0x$$SCON$,     /* SCON */    0x$$TR1$,      /* TR1 */
   0x$$TCON$,     /* TCON */    0x$$CCAPM0$,   /* CCAPM0 */    0x$$CCAP0L$,   /* CCAP0L */  0x$$CCAP0H$,   /* CCAP0H */
   0x$$CCAPM1$,   /* CCAPM1 */  0x$$CCAP1L$,   /* CCAP1L */    0x$$CCAP1H$,   /* CCAP1H */  0x$$CCAPM2$,   /* CCAPM2 */
   0x$$CCAP2L$,   /* CCAP2L */  0x$$CCAP2H$,   /* CCAP2H */    0x$$CCAPM3$,   /* CCAPM3 */  0x$$CCAP3L$,   /* CCAP3L */
   0x$$CCAP3H$,   /* CCAP3H */  0x$$CCAPM4$,   /* CCAPM4 */    0x$$CCAP4L$,   /* CCAP4L */  0x$$CCAP4H$,   /* CCAP4H */
   0x$$P0$,       /* P0 */      0x$$P1$,       /* P1 */        0x$$P2$,       /* P2 */      0x$$P3$        /* P3 */
};

/* enum table of indicies for sfr's in sfr[] array above. They must match order. */
enum
{
   XXIE0,      XXIPL0,     XXIPH0,     XXCL,
   XXCH,       XXCMOD,     XXCCON,     XXPCATYPE,
   XXTMOD,     XXTL0,      XXTH0,      XXTL1,
   XXTH1,      XXTL2,      XXTH2,      XXRCAP2L,
   XXRCAP2H,   XXT2MODES,  XXPCON,     XXWCON,
   XXT2MOD,    XXT2CON,    XXSCON,     XXTR1,
   XXTCON,     XXCCAPM0,   XXCCAP0L,   XXCCAP0H,
   XXCCAPM1,   XXCCAP1L,   XXCCAP1H,   XXCCAPM2,
   XXCCAP2L,   XXCCAP2H,   XXCCAPM3,   XXCCAP3L,
   XXCCAP3H,   XXCCAPM4,   XXCCAP4L,   XXCCAP4H,
   XXP0,       XXP1,       XXP2,       XXP3
};



/* MAIN.C */

void main(void)
{

   DI();
   Init_all();
   EI();

   while(1)                         /* Start main loop.  Execute timed/scheduled functions in Task control blocks */
   {
#ifdef TASK_CONTROL_BLOCK_ENABLED   /* Repeatedly execute timed functions in task-control loop     OPTIONAL */
      Task_controller(Hundredth_sec);
      Task_controller(Tenth_sec);
      Task_controller(Whole_sec);
#endif
   }
}


/*    Function:      Init_all
 *
 *    This function is used to initialize the peripherals.  SFR Value Entries in the sfrs[]
 *    array are filled in by ApBUILDER at code-generation time.
 *    This function takes those entries and passes them to the various general-purpose initialization
 *    routines.
 *
 *    While this is inefficient, it is coded this way for clarity, and for educational purposes.
 *    The initialization routines are also inefficient, as they must handle 'every' case presented
 *    to them.  You will probably want to eliminate unnecessary parameter passing, and unnecessary
 *    code from your final program.  You will also find that you can combine functionality from
 *    several initialization routines to make one single efficient init routine.
 *    Again, it has been seperated and expanded here for the purpose of clarity (showing which SFR's
 *    are involved for each peripheral), and to handle each possible case.
 *
 *    In the Timer section below, you will see that TIMER1 will be set up to provide a heart-beat
 *    tick at 10ms for the TCB functionality if the compiler directive is switched on.  You will
 *    need to fill in TL1 and TH1 with correct values to acheive 10ms overflow rate.  These values
 *    will be dependent on your clock speed.  They are not set by ApBUILDER.
 *
 */

static void Init_all(void)
{
   init_cpu(sfrs[XXWCON]);

   init_io_ports(XXP0, XXP1, XXP2, XXP3);

   /* Initialize the timers.. Keep turned off for now */
   init_timer0(sfrs[XXTCON], sfrs[XXTMOD], sfrs[XXTL0], sfrs[XXTH0], sfrs[XXIE0], OFF);
   init_timer2(sfrs[XXT2CON], sfrs[XXT2MOD], sfrs[XXTL2], sfrs[XXTH2], sfrs[XXRCAP2L], sfrs[XXRCAP2H], sfrs[XXT2MODES], OFF);

   /* If using TCB functionality, use timer 1 as heart-beat clock, be sure to set it to an interval of 10ms
    * by properly setting sfrs[XXTL1] and sfrs[XXTH1].  This is not done in ApBUILDER.  You must set
    * it in this file manually in the sfrs array above.  Use mode 1.  Can use any timer you wish for this. */
#ifdef TASK_CONTROL_BLOCK_ENABLED
   init_timer1(sfrs[XXTCON], sfrs[XXTMOD], sfrs[XXTL1], sfrs[XXTH1], sfrs[XXIE0], ON);
   SET_VECTOR(TIMER1, timer1_handler);    /* Set interrupt vector to this routine */
#else
   init_timer1(sfrs[XXTCON], sfrs[XXTMOD], sfrs[XXTL1], sfrs[XXTH1], sfrs[XXIE0], OFF);
#endif

   /* Init the PCA modules */
   InitPCAModule(sfrs[XXCMOD], sfrs[XXCCAPM0], sfrs[XXCCAP0L], sfrs[XXCCAP0H], sfrs[XXPCATYPE], 0);
   InitPCAModule(sfrs[XXCMOD], sfrs[XXCCAPM1], sfrs[XXCCAP1L], sfrs[XXCCAP1H], sfrs[XXPCATYPE], 1);
   InitPCAModule(sfrs[XXCMOD], sfrs[XXCCAPM2], sfrs[XXCCAP2L], sfrs[XXCCAP2H], sfrs[XXPCATYPE], 2);
   InitPCAModule(sfrs[XXCMOD], sfrs[XXCCAPM3], sfrs[XXCCAP3L], sfrs[XXCCAP3H], sfrs[XXPCATYPE], 3);
   InitPCAModule(sfrs[XXCMOD], sfrs[XXCCAPM4], sfrs[XXCCAP4L], sfrs[XXCCAP4H], sfrs[XXPCATYPE], 4);
   InitPCATimer(sfrs[XXCL], sfrs[XXCH], sfrs[XXCMOD], sfrs[XXIE0], sfrs[XXCCON]);

   /* Get the serial port ready */
   init_serial(sfrs[XXSCON]);

   /* set up the Interrupt controller, do not turn on global int enable yet. */
   init_interrupts(sfrs[XXIE0] & 0x7f , sfrs[XXIPL0], sfrs[XXIPH0]);

   /* set up the Watch-dog timer, and power management */
   init_WDT(OFF);
   init_pm(sfrs[XXPCON]);
}





⌨️ 快捷键说明

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