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

📄 196npc.cod

📁 mcs51,2051,x86系列MCU
💻 COD
📖 第 1 页 / 共 4 页
字号:

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$
          $$if$  TIME_CON.0 && TIME_CON.1 && TIME_CON.2
                    DIVIDE_BY_128;
          $$end$
     $$end$
$$end$
$$if$ TIME_CON.5 && TIME_CON.4 && TIME_CON.3
                    QUADRATURE_CLOCK;
     /*  enable the pins to inputs  */

 p1_dir |= $%3TIMER_NUMBER$$0x30$0xC0$; 
 p1_mode |= $%3TIMER_NUMBER$$0x30$0xC0$; 
$$end$
$$else$
     $$if$ TIME_CON.4
     /*  enable the direction pin to input  */
 p1_dir |= $%3TIMER_NUMBER$$0x20$0x80$; 
 p1_mode |= $%3TIMER_NUMBER$$0x20$0x80$; 
     $$end$
     $$if$  TIME_CON.3
     /*  enable the clock pin to input  */
 p1_dir |= $%3TIMER_NUMBER$$0x10$0x40$; 
 p1_dir |= $%3TIMER_NUMBER$$0x10$0x40$; 
     $$end$
$$end$

$$if$ TIMER_INTERRUPT
 int_mask |= $%XTIMER_NUMBER$;  /*  un-mask interrupt */ 
$$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
#define   NEGATIVE     0x00
int  temp;
unsigned int speed, direction;
$$end$

 init_timer@@TIMER_NUMBER@();

 /*  If the EPA unit is to be used with the timers, then the init
     EPA code should be called.   */

$$if$ TIMER_INTERRUPT
 enable();
$$end$
$$if$ (TIME_CON.3-5 == 7)
     /*   In Quadrature clocking mode, reading the timer@@TIMER_NUMBER@
          at fixed intervals of time can give speed and
          direction.  example:   */

 temp = timer@@TIMER_NUMBER@;
/*  delay(some_unit_of_time);    User's routine to delay some time */
 temp = timer@@TIMER_NUMBER@ - temp;
 speed = abs(temp);
 direction = (temp > 0 ? POSITIVE : NEGATIVE);
$$end$
$$if$ (TIME_CON.3-5 <> 7)
/*   The timer@@TIMER_NUMBER@ can now be used by the EPA or
     read at any time to obtain information on counting speed
     and or direction.  */

 delay@@TIMER_NUMBER@(10);  /*  example to delay 10 timer ticks */    
$$end$ 
}

$$if$ TIMER_INTERRUPT
#pragma interrupt(timer$$TIMER_NUMBER$_interrupt = $%XTIMER_NUMBER -1$)
void timer$$TIMER_NUMBER$_interrupt()
{
/*  User's code to handle a timer overflow  */

}
$$end$
##80C196NP Serial#
##80C196NU Serial#
$$ifp$80c196np
#pragma model(NP)
#include <80c196np.h>
$$end$
$$ifp$80c196nu
#pragma model(NU)
#include <80c196nu.h>
$$end$
#define   SP_MODE0           0x00
#define   SP_MODE1           0x01
#define   SP_MODE2           0x02
#define   SP_MODE3           0x03
#define   REC_ENABLE         0x08
#define   REC_DISABLE        0x00
#define   EVEN_PARITY        0x08
#define   ODD_PARITY         0x28
#define   NO_PARITY          0x00
$$ifp$80c196nu
#define   CLK_PRESCAL_ENAB   0x40
#define   CLK_PRESCAL_DISAB  0x00
$$end$
#define   SET_BIT_8          0x10
#define   SP_INTERNAL_CLK    0x8000
#define   SP_EXTERNAL_CLK    0x0000
#define   TXD_INTERRUPT      0x20
#define   RXD_INTERRUPT      0x40
#define   TI_BIT             0x05
#define   RI_BIT             0x06
#define   FE_BIT             0x04
#define   OE_BIT             0x02
#define   RPE_BIT            0x07
#define   RB8_BIT            0x07
#define   TXE_BIT            0x03

static unsigned char sp_status_image;
$$ifn$ INT_MASK.6 |! INT_MASK.5
     $$ifn$ INT_MASK.5 && P2_MODE.0
int putchar(int transmit_byte)
{
 clrbit(sp_status_image, TXE_BIT);
 while(!checkbit((sp_status_image |= sp_status), TXE_BIT));

          $$if$ SP_CON.4
/*   If bit 8 needs to be set, then the following line needs to
     be inserted:
 sp_con |= SET_BIT_8;   */
          $$end$
 sbuf_tx = transmit_byte;
 clrbit(sp_status_image, TXE_BIT);
 return transmit_byte;
}
     $$end$
     $$ifn$ INT_MASK.6 && P2_MODE.1
int getchar(void)
{
 while(!checkbit((sp_status_image |= sp_status), RI_BIT));
 if(checkbit(sp_status_image, FE_BIT))
     {
     ;    /*  User code for framing error  */
     clrbit(sp_status_image, FE_BIT);
     }   
 if(checkbit(sp_status_image, OE_BIT))
     {
     ;    /*  User code for overrun error  */
     clrbit(sp_status_image, OE_BIT);
     }   
          $$if$ SP_CON.2
 if(checkbit(sp_status_image, RPE_BIT))
     {
     ;    /*  User code for Parity error  */
     clrbit(sp_status_image, RPE_BIT);
     }   
          $$end$
          $$if$ SP_CON.4
 if(checkbit(sp_status_image, RB8_BIT))
     {
     ;    /*  User code for Receiving BIT 8 */
     clrbit(sp_status_image, RB8_BIT);
     }   
          $$end$
 clrbit(sp_status_image, RI_BIT);
 return sbuf_rx;
}
     $$end$
$$end$
$$if$ INT_MASK.5-6
     $$if$ INT_MASK.6

#pragma interrupt(receive=6)
     $$end$
     $$if$ INT_MASK.5
#pragma interrupt(transmit=5)
     $$end$

     $$if$ INT_MASK.5
#define TRANSMIT_BUF_SIZE 20
     $$end$
     $$if$ INT_MASK.6
#define RECEIVE_BUF_SIZE 20
     $$end$
     $$if$ INT_MASK.5

/*   transmit buffer and it's indexes    */
static unsigned char trans_buff[TRANSMIT_BUF_SIZE];
static char begin_trans_buff,end_trans_buff;
     $$end$
     $$if$ INT_MASK.6

/*   receive buffer and it's indexes    */
static unsigned char receive_buff[RECEIVE_BUF_SIZE];
static char end_rec_buff,begin_rec_buff;
     $$end$
     $$if$ INT_MASK.5

void transmit(void)             /*  serial interrupt routine  */
{
sp_status_image |= sp_status;       /*  image sp_status into
                                        sp_status_image  */

/*   transmitt a character if there is a character in the buffer
     else leave TI_BIT set in image for putchar to enable interrupts   */
if(begin_trans_buff!=end_trans_buff)
     {
     $$if$ SP_CON.4
/*   If bit 8 needs to be set, then the following line needs to
     be inserted:
     sp_con |= SET_BIT_8;   */
     $$end$
     sbuf_tx=trans_buff[begin_trans_buff];   /*  transmit character  */

/*   The next statement makes the buffer circular by starting over when the
     index reaches the end of the buffer.   */

     if(++begin_trans_buff>TRANSMIT_BUF_SIZE - 1)begin_trans_buff=0;
     clrbit(sp_status_image,TI_BIT);     /*  clear TI bit in status_image.   */
     }
}

int putchar(int c)
{
/*   remain in loop while the buffer is full.  This is done by checking
     the end of buffer index to make sure it does not overrun the
     beginning of buffer index.   The while instruction checks the case
     when the end index is one less then the beginning index and at the
     end of the buffer when the beginning index may be equal to 0 and
     the end buffer index may be at the buffer end.   */

while((end_trans_buff+1==begin_trans_buff)||
      (end_trans_buff==TRANSMIT_BUF_SIZE -1 && !begin_trans_buff));

trans_buff[end_trans_buff]=c;           /*  put character in buffer  */
if(++end_trans_buff>TRANSMIT_BUF_SIZE - 1)   /*  make buffer appear  */
     end_trans_buff=0;                       /*  circular.           */
if(checkbit(sp_status_image, TI_BIT))
     int_pend |= TXD_INTERRUPT;  /*     If transmitt buffer
                            was empty, then cause
                            an interrupt to start
                            transmitting.  */
}
     $$end$
     $$if$ INT_MASK.6

void receive(void)              /*  serial interrupt routine  */
{
sp_status_image |= sp_status;       /*  image sp_status into status_image  */

/*   If the input buffer is full, the last character can be handled
     as desired.  */

 if(end_rec_buff+1==begin_rec_buff || (end_rec_buff==RECEIVE_BUF_SIZE-1 &&
         !begin_rec_buff))
    {
     ;  /*  input overrun code  */
    }
else
    {

/*   The next statement makes the buffer circular by starting over when the
     index reaches the end of the buffer.   */

     if(++end_rec_buff > RECEIVE_BUF_SIZE - 1) end_rec_buff=0;
     receive_buff[end_rec_buff]=sbuf_rx;  /*    place character in
                                              buffer  */
     if(checkbit(sp_status_image, FE_BIT))
          {
          ;    /*  User code for framing error  */
          clrbit(sp_status_image, FE_BIT);
          } 
     if(checkbit(sp_status_image, OE_BIT))
          {
          ;    /*  User code for overrun error  */
          clrbit(sp_status_image, OE_BIT);
          } 
          $$if$ SP_CON.2
     if(checkbit(sp_status_image, RPE_BIT))
          {
          ;    /*  User code for Parity error  */
          clrbit(sp_status_image, RPE_BIT);
          } 
          $$end$
          $$if$ SP_CON.4
     if(checkbit(sp_status_image, RB8_BIT))
          {
          ;    /*  User code for Receiving BIT 8 */
          clrbit(sp_status_image, RB8_BIT);
          } 
          $$end$
    }
 clrbit(sp_status_image,RI_BIT);   /*  clear RI bit in status_image.  */
}

int getchar(void)
{
while(begin_rec_buff==end_rec_buff);  /*  remain in loop while there is
                 not a character avaliable. */
if(++begin_rec_buff>RECEIVE_BUF_SIZE - 1)  /*  make buffer appear    */
     begin_rec_buff=0;                     /*  circular.  */
return(receive_buff[begin_rec_buff]);      /*  return the character in
                                     buffer.    */
}
     $$end$
$$end$

void init_serial()
{
/*
* Mode = $%TSP_CON.0-1$ASYNCHRONOUS$SYNCHRONOUS$ MODE$$SP_CON.0-1$.
* Parity is $%ESP_CON.2$
*/
 sp_con = SP_MODE$$SP_CON.0-1$ | $%TSP_CON.3$REC_ENABLE$REC_DISABLE$
$$ifp$80c196nu
$$if$ SP_BAUD.15
              | $%TSP_CON.6$CLK_PRESCAL_ENAB$CLK_PRESCAL_DISAB$
$$end$
$$end$
$$if$ SP_CON.2
              | $%TSP_CON.5$ODD_PARITY$EVEN_PARITY$;
$$end$
$$ifn$ SP_CON.2
              | NO_PARITY;
$$end$

/*
* Baud Rate = $$SP_BAUD.0-14$
*/

 sp_baud = 0x$$SP_BAUD$;
$$if$ P2_MODE.0

 setbit(p2_reg,0);    /*  init txd pin output  */
 clrbit(p2_dir,0);     /*  make txd pin output  */
 setbit(p2_mode,0);   /*  enable txd mode on p2.0 */
$$end$
$$if$ P2_MODE.1

 setbit(p2_reg,1);    /*  init rxd pin input  */
 setbit(p2_dir,1);     /*  make rxd pin input  */
 setbit(p2_mode,1);   /*  enable rxd mode on p2.1 */
$$end$
$$ifn$  SP_BAUD.15

 setbit(p6_reg,2);    /*  init t1clk pin input  */
 setbit(p6_dir,2);     /*  make t1clk pin input  */
$$end$

$$if$ INT_MASK.5-6
 int_mask |= $%TINT_MASK.5$TXD_INTERRUPT$$$%TINT_MASK.6$ | RXD_INTERRUPT$$;
     $$if$  INT_MASK.6
 end_rec_buff=0;          /* initialize buffer pointers        */
 begin_rec_buff=0;
     $$end$
     $$if$  INT_MASK.5
 end_trans_buff=0;
 begin_trans_buff=0;
     $$end$
$$end$
 sp_status_image = 0;
}

void main(void)
{
 init_serial();
$$if$ INT_MASK.5-6
 enable();
     $$if$ INT_MASK.6
/*   The following line will loop until the letter 'Q' is 
     received.   */
 while(getchar() != 'Q');     
     $$end$
     $$if$ INT_MASK.5
/*   The following lines are used to initialize putchar routine,
     so that the first time putchar is called it will send the 
     character.  */

 setbit(sp_status_image, TI_BIT);

/*   Example of sending out buffered data.    */
 
 putchar('H');
 putchar('e');
 putchar('l');
 putchar('l');
 putchar('o');
     $$end$   
 while(1);  
$$end$
$$ifn$ INT_MASK.5-6
     $$if$ P2_MODE.0 && P2_MODE.1
 while(1)
     putchar(getchar());  /*  transmitt the character received */
     $$end$
     $$if$ P2_MODE.0 &! P2_MODE.1
 putchar('A');  /*  transmitt a character */
 while(1);
     $$end$
     $$ifn$ P2_MODE.0 && P2_MODE.1
 while(getchar() != 'Q');  /*  wait in loop until byte received
                               is a 'Q' character */
 while(1);
     $$end$
$$end$
}
##80C196NP PM#
##80C196NP BIU#
##80C196NP CPU#
##80C196NP CODE#
##80C196NU PM#
##80C196NU BIU#
##80C196NU CPU#
##80C196NU CODE#
$$ifp$80c196np
#pragma model(NP)
#include <80c196np.h>
$$end$
$$ifp$80c196nu
#pragma model(NU)
#include <80c196nu.h>
$$end$
/*
*
* Number of wait states = $%4CCR0.4-5$Zero$One$Two$Three$ wait states
* Powerdown Mode = $%ECCR0.0$
* Bus Mode = $%TCCR0.3$Demultiplexed$Multiplexed$
* Write control mode = $%TCCR0.2$Standard BHE mode$Write strobe WRH$
* Bus width = $%TCCR0.1$Sixteen$Eight$ bit bus
* 
* Addressing mode = $%TCCR1.1$64 Kbyte$1 Mbyte$
$$ifp$80c196np
* ROM remapping = $%TCCR1.2$ROM mapped to 0 and 0FFh$ROM mapped to 0FFh$
$$end$
$$ifp$80c196nu
* Deferred Mode = $%ECCR1.5$
*
* Accumulator Options:
*           Saturation Mode = $%EACC_STAT.6$
*           Fractional Mode = $%EACC_STAT.7$
$$end$
*/

#define   ZERO_WAIT_STATES   0x00
#define   ONE_WAIT_STATES    0x10
#define   TWO_WAIT_STATES    0x20
#define   THREE_WAIT_STATES  0x30
#define   BUS_WIDTH_16       0x02
#define   BUS_WIDTH_8        0x00
#define   WR_BHE             0x04
#define   WRL_WRH            0x00
#define   DEMUXED_MODE       0x08
#define   MUXED_MODE         0x00
#define   POW_DN_ENABLE      0x01
#define   POW_DN_DISABLE     0x00

#define   CCR0_RESERVED      0xC0
#define   CCR1_RESERVED      0xD8

$$ifp$80c196np
#define   REMAP_ROM          0x04
#define   NO_ROM_REMAP       0x00

$$end$
#define   MODE64             0x02
#define   MODE1MEG           0x00
$$ifp$80c196nu

#define   SAT_MODE_ENAB      0x40
#define   FRACT_MODE_ENAB    0x80

⌨️ 快捷键说明

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