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

📄 196kxc.cod

📁 mcs51,2051,x86系列MCU
💻 COD
📖 第 1 页 / 共 5 页
字号:
##80C196JR EPA#
##80C196JT EPA#
##80C196JQ EPA#
$$ifp$ 80C196KT || 80C196KQ || 80C196KR || 80C196JR || 80C196JQ || 80C196JT
#pragma model(KR)
$$end$
$$ifp$ 80C196NT || 80C196NQ
#pragma model(NT)
$$end$
#include <80c196kr.h>
#define   CAPTURE      0x00
#define   COMPARE      0x40
#define   EPA_ATOD     0x04
#define   RE_ENABLE    0x08
#define   POS_EDGE     0x20
#define   SET_PIN      0x20
#define   NEG_EDGE     0x10
#define   CLR_PIN      0x10
#define   BOTH_EDGE    0x30
#define   TOGGLE_PIN   0x30
#define   NOTHING      0x00
#define   RESET_OPP_TIMER          0x02
#define   RESET_TIMER              0x01
#define   OVERWRITE_NEW_DATA       0x01
#define   IGNORE_NEW_DATA          0x00
#define   USE_TIMER1               0x00
#define   USE_TIMER2               0x80
#define   RE_MAP                   0x0100
#define   EPA0_INT_BIT             4
#define   EPA1_INT_BIT             3
#define   EPA2_INT_BIT             2
#define   EPA3_INT_BIT             1
#define   EPAX_INT_BIT             0
#define   EPA4_INT_BIT             15
#define   EPA5_INT_BIT             14
#define   EPA6_INT_BIT             13
#define   EPA7_INT_BIT             12
#define   EPA8_INT_BIT             11
#define   EPA9_INT_BIT             10
#define   EPA0_OVR_BIT             9
#define   EPA1_OVR_BIT             8
#define   EPA2_OVR_BIT             7
#define   EPA3_OVR_BIT             6
#define   EPA4_OVR_BIT             5
#define   EPA5_OVR_BIT             4
#define   EPA6_OVR_BIT             3
#define   EPA7_OVR_BIT             2
#define   EPA8_OVR_BIT             1
#define   EPA9_OVR_BIT             0
#define   COMP_CH0_BIT             3
#define   COMP_CH1_BIT             2
#define   TIMER1_OVR_BIT           1
#define   TIMER2_OVR_BIT           0

void init_epa$$EPA_CHANNEL$()
{
 epa$$EPA_CHANNEL$_con = $%TEPA_CON.6$COMPARE$CAPTURE$ |
$$ifn$ EPA_CON.5
     $$if$ EPA_CON.6
                $%TEPA_CON.4$CLR_PIN$NOTHING$ |
     $$end$
     $$ifn$ EPA_CON.6
                $%TEPA_CON.4$NEG_EDGE$NOTHING$ |
     $$end$
$$end$
$$if$ EPA_CON.5
     $$if$ EPA_CON.6
                $%TEPA_CON.4$TOGGLE_PIN$SET_PIN$ |
     $$end$
     $$ifn$ EPA_CON.6
                $%TEPA_CON.4$BOTH_EDGE$POS_EDGE$ |
     $$end$
$$end$
$$if$ EPA_CON.8
                RE_MAP |
$$end$
$$if$ EPA_CON.3
                RE_ENABLE |
$$end$
$$if$ EPA_CON.2
                EPA_ATOD |
$$end$
$$if$ EPA_CON.1
                RESET_OPP_TIMER |
$$end$
$$if$ EPA_CON.0
                $%TEPA_CON.6$RESET_TIMER$IGNORE_NEW_DATA$ |
$$end$
                $%TEPA_CON.7$USE_TIMER2$USE_TIMER1$;
$$if$ EPA_CON.6
     $$if$ RELATIVE
 epa$$EPA_CHANNEL$_time = $%TEPA_CON.7$timer2$timer1$ + 0x$$TIMER_OFFSET$;
     $$end$
     $$ifn$ RELATIVE
 epa$$EPA_CHANNEL$_time = 0x$$TIMER_OFFSET$;
     $$end$
$$end$
$$if$ EPA_CON.4-5
     $$if$ (EPA_CHANNEL < 8)
 setbit(p1_reg, $$EPA_CHANNEL$);   /*  init reg  */
          $$if$ EPA_CON.6
 clrbit(p1_dir, $$EPA_CHANNEL$);   /*  make output pin  */
          $$end$
          $$ifn$ EPA_CON.6
 setbit(p1_dir, $$EPA_CHANNEL$);   /*  make input pin  */
          $$end$
 setbit(p1_mode, $$EPA_CHANNEL$);   /*  select EPA mode  */
     $$end$
     $$if$ (EPA_CHANNEL > 7)
 setbit(p6_reg, $%XEPA_CHANNEL - 8$);   /*  init reg  */
          $$if$ EPA_CON.6
 clrbit(p6_dir, $%XEPA_CHANNEL - 8$);   /*  make output pin  */
          $$end$
          $$ifn$ EPA_CON.6
 setbit(p6_dir, $%XEPA_CHANNEL - 8$);   /*  make input pin  */
          $$end$
 setbit(p6_mode, $%XEPA_CHANNEL - 8$);   /*  select EPA mode  */
      $$end$
$$end$   /*  end of port setup of epa0  */
$$if$ EPA_INTERRUPT
     $$if$ (EPA_CHANNEL > 3)
 setbit(int_mask, EPAX_INT_BIT);   /*  un-mask epax interrupts  */
 setbit(epa_mask, EPA$$EPA_CHANNEL$_INT_BIT);
     $$end$
     $$if$ (EPA_CHANNEL < 4)
 setbit(int_mask, EPA$$EPA_CHANNEL$_INT_BIT);   /*  un-mask epa interrupts  */
     $$end$
$$end$
$$if$ EPA_OVERFLOW
     $$if$ (EPA_CHANNEL < 4)
 setbit(int_mask, EPAX_INT_BIT);   /*  un-mask epax interrupts  */
     $$end$
 setbit(epa_mask,EPA$$EPA_CHANNEL$_OVR_BIT);  /* un-mask overflow on epa$$EPA_CHANNEL$  */
$$end$
}

$$ifn$ EPA_OVERFLOW &! EPA_INTERRUPT
void poll_epa$$EPA_CHANNEL$()
{
  $$ifn$ EPA_CON.6
unsigned int time_value;
  $$end$
  $$ifn$ EPA_INTERRUPT
     $$ifn$ EPA_CHANNEL.2-4
 if(checkbit(int_pend, EPA$$EPA_CHANNEL$_INT_BIT))
     $$end$
     $$if$ EPA_CHANNEL.2-4
 if(checkbit(epa_pend, EPA$$EPA_CHANNEL$_INT_BIT))
     $$end$
     {
      /*  User code for event channel $$EPA_CHANNEL$ would go here */
     $$ifn$ EPA_CON.6
     time_value = epa$$EPA_CHANNEL$_time;  /*  time needs to be read to
                                       avoid overrun  */
     $$end$
     $$if$ EPA_CON.6 &! EPA_CON.3
      /*  Since this event was not re-enabled, no more
          events will occur.  */
     $$end$
     $$if$ RELATIVE && EPA_CON.6 && EPA_CON.3
     epa$$EPA_CHANNEL$_time += 0x$$TIMER_OFFSET$;
     $$end$
     $$ifn$ RELATIVE && EPA_CON.6 && EPA_CON.3
      /*  Since this event is absolute and re-enabled,
          no polling is neccessary.   */
     $$end$
     $$ifn$ EPA_CHANNEL.2-4
     clrbit(int_pend, EPA$$EPA_CHANNEL$_INT_BIT);
     $$end$
     $$if$ EPA_CHANNEL.2-4
     clrbit(epa_pend, EPA$$EPA_CHANNEL$_INT_BIT);
     $$end$
     }
  $$end$
  $$if$ EPA_OVERFLOW
 if(checkbit(epa_pend, EPA$$EPA_CHANNEL$_OVR_BIT))
     {
     /*  code to handle overflow would go here */
     /*  The epa_time needs to be read to clear overflow */
     time_value = epa$$EPA_CHANNEL$_time;
     clrbit(epa_pend, EPA$$EPA_CHANNEL$_OVR_BIT);
     }
  $$end$
}
$$end$

void main(void)
{
$$ifn$ EPA_CON.6
 unsigned int time_value;
$$end$

 /*  Should init the timers before using the epa  */
 /*  init_timers();   */
 init_epa$$EPA_CHANNEL$();
$$if$ EPA_INTERRUPT || EPA_OVERFLOW
 enable();     /*  Globally enable interrupts  */
$$end$
$$ifn$ EPA_OVERFLOW &! EPA_INTERRUPT
 /*  EPA events can be serviced by polling int_pend
     or epa_pend.   */
 while(1)
     {
     poll_epa$$EPA_CHANNEL$();
     }
$$end$
$$if$ EPA_INTERRUPT || EPA_OVERFLOW 
 while(1);   /*  loop forever waiting for interrupts to occur  */
$$end$
}

$$if$ EPA_INTERRUPT
     $$if$ (EPA_CHANNEL < 4)
#pragma interrupt(epa$$EPA_CHANNEL$_interrupt=EPA$$EPA_CHANNEL$_INT_BIT)
void epa$$EPA_CHANNEL$_interrupt()
{
          $$ifn$ EPA_CON.6
 unsigned int time_value;

 time_value = epa$$EPA_CHANNEL$_time;   /* must read to prevent overrun */
          $$end$
          $$if$ EPA_CON.6 &! EPA_CON.3
  /*  Since not re-enabled, no more events will occur unless
      epa_control and epa_time are re-written.  */
          $$end$
          $$if$ RELATIVE && EPA_CON.6 && EPA_CON.3
 epa$$EPA_CHANNEL$_time += 0x$$TIMER_OFFSET$;
          $$end$
          $$ifn$ RELATIVE && EPA_CON.6 && EPA_CON.3
  /*  Since this event is absolute and re-enabled,
      user code does not need to re-enable.   */
          $$end$
}
     $$end$    /*   end of epa0-3 interrupts  */
$$end$
$$if$ EPA_INTERRUPT && (EPA_CHANNEL > 3) || EPA_OVERFLOW
     /*   To have code generate for the epax interrupt,
          Select the ICU design screen.  */
$$end$
##80C196NT COMP#
##80C196NQ COMP#
##80C196KT COMP#
##80C196KQ COMP#
##80C196KR COMP#
##80C196JR COMP#
##80C196JT COMP#
##80C196JQ COMP#
$$ifp$ 80C196KT || 80C196KQ || 80C196KR || 80C196JR || 80C196JQ || 80C196JT
#pragma model(KR)
$$end$
$$ifp$ 80C196NT || 80C196NQ
#pragma model(NT)
$$end$
#include <80c196kr.h>
#define   COMPARE_EN   0x40
#define   EPA_ATOD     0x04
#define   RE_ENABLE    0x08
#define   SET_PIN      0x20
#define   CLR_PIN      0x10
#define   TOGGLE_PIN   0x30
#define   NOTHING      0x00
#define   RESET_OPP_TIMER          0x02
#define   RESET_TIMER              0x01
#define   USE_TIMER1               0x00
#define   USE_TIMER2               0x80
#define   EPAX_INT_BIT             0
#define   COMP0_INT_BIT            3
#define   COMP1_INT_BIT            2

void init_comp$$COMP_CHANNEL$()
{
 comp$$COMP_CHANNEL$_con = $%TCOMP_CON.7$USE_TIMER2$USE_TIMER1$ |
$$if$ COMP_CON.6
                COMPARE_EN |
$$end$                
$$ifn$ COMP_CON.5
                $%TCOMP_CON.4$CLR_PIN$NOTHING$ |
$$end$
$$if$ COMP_CON.5
                $%TCOMP_CON.4$TOGGLE_PIN$SET_PIN$ |
$$end$
$$if$ COMP_CON.3
                RE_ENABLE |
$$end$
$$if$ COMP_CON.2
                EPA_ATOD |
$$end$
$$if$ COMP_CON.1 && COMP_CON.0
                RESET_OPP_TIMER | RESET_TIMER;
$$end$
$$ifn$ COMP_CON.1 && COMP_CON.0
                RESET_TIMER;
$$end$
$$ifn$ COMP_CON.0
                NOTHING;
$$end$
$$if$ COMP_CON.6 && RELATIVE
 comp$$COMP_CHANNEL$_time = $%TCOMP_CON.7$timer2$timer1$ + 0x$$TIMER_OFFSET$;
$$end$
$$if$ COMP_CON.6 &! RELATIVE
 comp$$COMP_CHANNEL$_time = $$TIMER_OFFSET$;
$$end$
$$if$ COMP_CON.4-5
 setbit(p6_reg, $$COMP_CHANNEL$);   /*  init reg register  */
 clrbit(p6_dir, $$COMP_CHANNEL$);   /*  make output pin  */
 setbit(p6_mode, $$COMP_CHANNEL$);   /*  select COMP mode  */
$$end$   /*  end of port setup of COMP0  */
$$if$ COMP_INTERRUPT
 setbit(int_mask, EPAX_INT_BIT);   /*  un-mask COMPx interrupts  */
 setbit(epa_mask1, COMP$$COMP_CHANNEL$_INT_BIT);
$$end$
}

$$ifn$ COMP_INTERRUPT
void poll_comp$$COMP_CHANNEL$()
{
 if(checkbit(epa_pend1, COMP$$COMP_CHANNEL$_INT_BIT))
     {
      /*  User code for event channel $$COMP_CHANNEL$ would go here */
     $$ifn$ COMP_CON.3
      /*  Since this event was not re-enabled, no more
          events will occur.  */
     $$end$
     $$if$ RELATIVE && COMP_CON.3
     comp$$COMP_CHANNEL$_time += 0x$$TIMER_OFFSET$;
     $$end$
     $$ifn$ RELATIVE && COMP_CON.3
      /*  Since this event is absolute and re-enabled,
          no polling is neccessary.   */
     $$end$
     clrbit(epa_pend1, COMP$$COMP_CHANNEL$_INT_BIT);
     }
}
$$end$

void main(void)
{
 /*  Should init the timers before using the COMP  */
 /*  init_timers();   */
 init_comp$$COMP_CHANNEL$();
$$if$ COMP_INTERRUPT
 enable();     /*  Globally enable interrupts  */
$$end$
$$ifn$ COMP_INTERRUPT
 /*  COMP events can be serviced by polling epa_pend1.  */
 while(1)
     {
     poll_comp$$COMP_CHANNEL$();
     }
$$end$
$$if$ COMP_INTERRUPT
 while(1);   /*  loop forever waiting for interrupts to occur  */
$$end$
}
$$if$ COMP_INTERRUPT
     /*   To have code generate for the epax interrupt,
          Select the ICU design screen.  */
$$end$
##80C196NT TIMER#
##80C196NQ TIMER#
##80C196KT TIMER#
##80C196KQ TIMER#
##80C196KR TIMER#
##80C196JR TIMER#
##80C196JT TIMER#
##80C196JQ TIMER#
$$ifp$ 80C196KT || 80C196KQ || 80C196KR || 80C196JR || 80C196JQ || 80C196JT
#pragma model(KR)
$$end$
$$ifp$ 80C196NT || 80C196NQ
#pragma model(NT)
$$end$
#include <80c196kr.h>
#define  COUNT_ENABLE         0x80
#define  COUNT_DISABLE        0x00
#define  COUNT_UP             0x40
#define  COUNT_DOWN           0x00
#define  CLOCK_INTERNAL       0x00
#define  CLOCK_EXTERNAL       0x08
#define  DIRECTION_TXDIR      0x10
#define  CLOCK_T1_OVFL        0x20
#define  DIRECTION_T1_OVFL    0x10
#define  QUADRATURE_CLOCK     0x38
#define  DIVIDE_BY_1          0x00
#define  DIVIDE_BY_2          0x01
#define  DIVIDE_BY_4          0x02
#define  DIVIDE_BY_8          0x03
#define  DIVIDE_BY_16         0x04
#define  DIVIDE_BY_32         0x05
#define  DIVIDE_BY_64         0x06
#define  OVR_TIMER1           0x01
#define  OVR_TIMER2           0x00

void init_timer@@TIMER_NUMBER@()
{
 t@@TIMER_NUMBER@control = $%TTIME_CON.7$COUNT_ENABLE$COUNT_DISABLE$ |
$$ifn$ TIME_CON.4
                    $%TTIME_CON.6$COUNT_UP$COUNT_DOWN$ |
$$end$
$$if$ TIME_CON.5 &! TIME_CON.3
                    CLOCK_T1_OVFL | $%TTIME_CON.4$DIRECTION_T1_OVFL;$$
$$end$
$$ifn$ TIME_CON.5
     $$if$ TIME_CON.4
                    DIRECTION_TXDIR |
     $$end$
     $$if$  TIME_CON.3
                    CLOCK_EXTERNAL;
     $$end$
     $$ifn$  TIME_CON.3
                    CLOCK_INTERNAL |
          $$ifn$  TIME_CON.0 &! TIME_CON.1 &! TIME_CON.2
                    DIVIDE_BY_1;
          $$end$
          $$if$   TIME_CON.0 &! TIME_CON.1 &! TIME_CON.2
                    DIVIDE_BY_2;
          $$end$
          $$ifn$  TIME_CON.0 && TIME_CON.1 &! TIME_CON.2
                    DIVIDE_BY_4;
          $$end$
          $$if$   TIME_CON.0 && TIME_CON.1 &! TIME_CON.2
                    DIVIDE_BY_8;
          $$end$
          $$ifn$  TIME_CON.0 &! TIME_CON.1 && TIME_CON.2
                    DIVIDE_BY_16;
          $$end$
          $$if$   TIME_CON.0 &! TIME_CON.1 && TIME_CON.2
                    DIVIDE_BY_32;
          $$end$
          $$ifn$  TIME_CON.0 && TIME_CON.1 && TIME_CON.2
                    DIVIDE_BY_64;
          $$end$
     $$end$
$$end$
$$if$ TIME_CON.5 && TIME_CON.4 && TIME_CON.3
                    QUADRATURE_CLOCK;
$$end$
$$if$ TIMER_INTERRUPT
 setbit(int_mask, 0);   /*  set epax interrupt mask */
 setbit(epa_mask1, OVR_TIMER@@TIMER_NUMBER@);
$$end$
}

$$ifn$ TIME_CON.3-5
/*   routine to delay at least (Xtal * 4 * ($$TIME_CON.0-2$+1)) * 'time'
     units of time.  */

void  delay@@TIMER_NUMBER@(unsigned int time)
{
 register unsigned int init_time;
 init_time = timer@@TIMER_NUMBER@;
 while((timer@@TIMER_NUMBER@ - init_time) < time);
}

$$end$

void main(void)
{
$$if$ (TIME_CON.3-5 == 7)
#define   POSITIVE     0x01

⌨️ 快捷键说明

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