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

📄 196kxc.cod

📁 mcs51,2051,x86系列MCU
💻 COD
📖 第 1 页 / 共 5 页
字号:
#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
     /*   To have code generate for the epax interrupt,
          Select the ICU design screen.  */
$$end$
##80C196NT Serial#
##80C196NQ Serial#
##80C196KT Serial#
##80C196KQ Serial#
##80C196KR Serial#
##80C196JR Serial#
##80C196JT Serial#
##80C196JQ Serial#
$$ifp$ 80C196KT || 80C196KQ || 80C196KR || 80C196JR || 80C196JQ || 80C196JT
#pragma model(KR)
$$end$
$$ifp$ 80C196NT || 80C196NQ
#pragma model(NT)
$$end$
#include <80c196kr.h>
#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
#define   SET_BIT_8          0x10
#define   SP_INTERNAL_CLK    0x8000
#define   SP_EXTERNAL_CLK    0x0000
#define   TXD_INTERRUPT      0x08
#define   RXD_INTERRUPT      0x10
#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_MASK1.4 |! INT_MASK1.3
     $$ifn$ INT_MASK1.3 && 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_MASK1.4 && 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_MASK1.3-4
     $$if$ INT_MASK1.4

#pragma interrupt(receive=28)
     $$end$
     $$if$ INT_MASK1.3
#pragma interrupt(transmit=27)
     $$end$

     $$if$ INT_MASK1.3
#define TRANSMIT_BUF_SIZE 20
     $$end$
     $$if$ INT_MASK1.4
#define RECEIVE_BUF_SIZE 20
     $$end$
     $$if$ INT_MASK1.3

/*   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_MASK1.4

/*   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_MASK1.3

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_pend1 |= TXD_INTERRUPT;  /*     If transmitt buffer
                            was empty, then cause
                            an interrupt to start
                            transmitting.  */
}
     $$end$
     $$if$ INT_MASK1.4

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$ |
$$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_MASK1.3-4
 int_mask1 |= $%TINT_MASK1.3$TXD_INTERRUPT$$$%TINT_MASK1.4$ | RXD_INTERRUPT$$;
     $$if$  INT_MASK1.4
 end_rec_buff=0;          /* initialize buffer pointers        */
 begin_rec_buff=0;
     $$end$
     $$if$  INT_MASK1.3
 end_trans_buff=0;
 begin_trans_buff=0;
     $$end$
$$end$
 sp_status_image = 0;
}

void main(void)
{
 init_serial();
$$if$ INT_MASK1.3-4
 enable();
     $$if$ INT_MASK1.4
/*   The following line will loop until the letter 'Q' is 
     received.   */
 while(getchar() != 'Q');     
     $$end$
     $$if$ INT_MASK1.3
/*   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_MASK1.3-4
     $$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$
}
##80C196NT PM#
##80C196NQ PM#
##80C196KT PM#
##80C196KQ PM#
##80C196KR PM#
##80C196JR PM#
##80C196JT PM#
##80C196JQ PM#
##80C196NT BIU#
##80C196NQ BIU#
##80C196KT BIU#
##80C196KQ BIU#
##80C196KR BIU#
##80C196JR BIU#
##80C196JT BIU#
##80C196JQ BIU#
##80C196NT CPU#
##80C196NQ CPU#
##80C196KT CPU#
##80C196KQ CPU#
##80C196KR CPU#
##80C196JR CPU#
##80C196JT CPU#
##80C196JQ CPU#
##80C196NT CODE#
##80C196NQ CODE#
##80C196KT CODE#
##80C196KQ CODE#
##80C196KR CODE#
##80C196JR CODE#
##80C196JT CODE#
##80C196JQ CODE#
$$ifp$ 80C196KT || 80C196KQ || 80C196KR || 80C196JR || 80C196JQ || 80C196JT
#pragma model(KR)
$$end$
$$ifp$ 80C196NT || 80C196NQ
#pragma model(NT)
$$end$
#include <80c196kr.h>
/*
$$ifn$ CCR1.1 &! CCR0.4-5
* Number of wait states = Zero wait states
$$end$
$$if$ CCR1.1
     $$if$ CCR0.5 && CCR0.4
* Number of wait states = READY pin controlled
     $$end$
     $$ifn$ CCR0.4-5
* Number of wait states = One wait state
     $$end$
     $$ifn$ CCR0.5 && CCR0.4
* Number of wait states = Two wait state
     $$end$
     $$if$  CCR0.5 &! CCR0.4
* Number of wait states = Three wait state
     $$end$
$$end$
*
* Address Valid Strobe Mode = $%TCCR0.3$Address Valid with Write Strobe$Address Valid Strobe$
*
$$ifn$ CCR0.6-7
* Programming protection = Read and Write Protection.
$$end$
$$if$ CCR0.6 && CCR0.7
* Programming protection = No Protection.
$$end$
$$if$ CCR0.6 &! CCR0.7
* Programming protection = Read Protection Only.
$$end$
$$ifn$ CCR0.6 && CCR0.7
* Programming protection = Write Protection Only.
$$end$
* Powerdown Mode = $%ECCR0.0$
*/
#define   READ_PROTECT       0x40
#define   WRITE_PROTECT      0x80
#define   NO_PROTECT         0xC0
#define   READ_WRITE_PROTECT 0x00
#define   ZERO_WAIT_STATE    0x00
#define   ONE_WAIT_STATE     0x00
#define   TWO_WAIT_STATE     0x10
#define   THREE_WAIT_STATE   0x20
#define   READY_CONTROLLED   0x30
#define   CCR1_WAIT_CONTROL  0x02
#define   CCR1_BUS_WIDTH     0x04
#define   BUSWIDTH_PIN       0x02
#define   BUS_WIDTH_16       0x02
#define   BUS_WIDTH_8        0x00
#define   WR_BHE             0x04
#define   WRL_WRH            0x00
#define   ALE_MODE           0x08
#define   ADV_MODE           0x00
#define   POW_DN_ENABLE      0x01
#define   POW_DN_DISABLE     0x00
#define   WDE_ENABLE         0x08
$$ifp$ 80C196KR || 80C196KQ || 80C196JR || 80C196JQ || 80C196JT
#define   CCR1_RESERVED      0xD0
$$end$
$$ifp$ 80C196NT || 80C196NQ || 80C196KT
#define   CCR1_RESERVED      0x10
#define   STANDARD_BUS       0xC0
#define   LONG_RD_WR         0x40
#define   EARLY_ADDRESS      0x80
#define   STANDARD_ONE_WS    0x00

⌨️ 快捷键说明

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