ANSI-C/cC++ Compiler for ST7 V-5.0.7, Aug 21 2001

    1:  /******************************************************************************
    2:  COPYRIGHT 2002 STMicroelectronics
    3:  Source File Name :  main.c  
    4:  Group            :  IPSW,CMG-IPDF
    5:  Author           : MCD Application Team
    6:  Date First Issued:  5/3/2002
    7:  ********************************Documentation**********************************
    8:  General Purpose - It is application file which calls the functions in sci.c. 
    9:  This example carries out the single byte transmission and continuous 
   10:  transmission in polling mode or in interrupt driven without buffer mode as per 
   11:  the selection made in the ST7lib_Config.h. Also it carries out the reception of
   12:  a single byte and a buffer of data in polling mode or in interrupt driven 
   13:  without buffer mode.The transmission and reception baudrate with extended 
   14:  prescalar register are selected as 9600.
   15:  Also for the transmission in interrupt driven case transmit data register ready
   16:  flag is enabled for generating the interrupt.      
   17:  ********************************Revision History*******************************
   18:  _______________________________________________________________________________
   19:  Date : 5/3/2002             Release:1.0  
   20:  Date : 28/04/04             MISRA changes
   21:  
   22:  --*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
   23:  #include "ST7lib_Config.h"   /*List of all ST7 devices and communication mode*/
   24:  #include "main.h"           /*Declaration of all the functions used in main.c*/
   25:  
   26:  #define Buf_Size ((unsigned char)20)
   27:  
   28:  void main(void);
   29:  static unsigned int Timeoutcount;
   30:  unsigned char Buff_Rcv[20]= {"                  "} ; 
   31:  
   32:  void main (void)
   33:  { 

Function: main
Source  : ..\..\..\..\Sources\main.c
Options : -Cc -Cni -F2 -Lasm=%n.lst -Ml -N -Or -TE1uE

   34:      unsigned char Rx_Data = 0;
  0000 3f00     CLR   __OVL_main_7_Rx_Data
   35:      unsigned char NbOfBytes = 20;
  0002 a614     LD    A,#20
  0004 b700     LD    __OVL_main_NbOfBytes,A
   36:      unsigned char Tx_Data = 51;
  0006 a633     LD    A,#51
  0008 b700     LD    __OVL_main_7_Tx_Data,A
   37:      unsigned int BaudRate_Tx = 9600;
  000a a680     LD    A,#128
  000c b701     LD    __OVL_main_11_BaudRate_Tx:1,A
  000e a625     LD    A,#37
  0010 b700     LD    __OVL_main_11_BaudRate_Tx,A
   38:      unsigned int BaudRate_Rx = 9600;
  0012 ae80     LD    X,#128
  0014 bf01     LD    __OVL_main_11_BaudRate_Rx:1,X
  0016 b700     LD    __OVL_main_11_BaudRate_Rx,A
   39:      SCI_RxError_t Err = 0;
  0018 3f00     CLR   __OVL_main_Err
   40:      unsigned char Buff[Buf_Size]= "SCI DRIVERS TESTING"; /*user buffer*/ 
  001a a653     LD    A,#83
  001c b700     LD    __OVL_main_Buff,A
  001e a643     LD    A,#67
  0020 b701     LD    __OVL_main_Buff:1,A
  0022 a649     LD    A,#73
  0024 b702     LD    __OVL_main_Buff:2,A
  0026 a620     LD    A,#32
  0028 b703     LD    __OVL_main_Buff:3,A
  002a a644     LD    A,#68
  002c b704     LD    __OVL_main_Buff:4,A
  002e a652     LD    A,#82
  0030 b705     LD    __OVL_main_Buff:5,A
  0032 a649     LD    A,#73
  0034 b706     LD    __OVL_main_Buff:6,A
  0036 a656     LD    A,#86
  0038 b707     LD    __OVL_main_Buff:7,A
  003a a645     LD    A,#69
  003c b708     LD    __OVL_main_Buff:8,A
  003e a652     LD    A,#82
  0040 b709     LD    __OVL_main_Buff:9,A
  0042 4c       INC   A
  0043 b70a     LD    __OVL_main_Buff:10,A
  0045 a620     LD    A,#32
  0047 b70b     LD    __OVL_main_Buff:11,A
  0049 a654     LD    A,#84
  004b b70c     LD    __OVL_main_Buff:12,A
  004d a645     LD    A,#69
  004f b70d     LD    __OVL_main_Buff:13,A
  0051 a653     LD    A,#83
  0053 b70e     LD    __OVL_main_Buff:14,A
  0055 4c       INC   A
  0056 b70f     LD    __OVL_main_Buff:15,A
  0058 a649     LD    A,#73
  005a b710     LD    __OVL_main_Buff:16,A
  005c a64e     LD    A,#78
  005e b711     LD    __OVL_main_Buff:17,A
  0060 a647     LD    A,#71
  0062 b712     LD    __OVL_main_Buff:18,A
  0064 3f13     CLR   __OVL_main_Buff:19
   41:      unsigned char new[] = "\n\r";
  0066 a60a     LD    A,#10
  0068 b700     LD    __OVL_main_new,A
  006a a60d     LD    A,#13
  006c b701     LD    __OVL_main_new:1,A
  006e 3f02     CLR   __OVL_main_new:2
   42:      BOOL Bool_Temp1 ;
   43:      BOOL Bool_Temp2 ;
   44:      Timeoutcount = 0;  
  0070 4f       CLR   A
  0071 c70001   LD    Timeoutcount:1,A
  0074 c70000   LD    Timeoutcount,A
   45:      SCI_Init(SCI_DEFAULT_PARAM1, SCI_DEFAULT_PARAM2); 
  0077 5f       CLR   X
  0078 cd0000   CALL  SCI_Init
   46:      SCI_Compute_Baudrate(BaudRate_Tx,BaudRate_Rx);
  007b ae25     LD    X,#37
  007d bf00     LD    __OVL_20_SCI_Compute_Baudrate_p1,X
  007f a680     LD    A,#128
  0081 b701     LD    __OVL_20_SCI_Compute_Baudrate_p1:1,A
  0083 cd0000   CALL  SCI_Compute_Baudrate
   47:                          /*Selects the transmission reception baudrate as 9600*/
   48:  //    SCI_Extend_Baudrate (SCI_PR_13+SCI_TR_2+SCI_RR_2,0x02,0x02);  
   49:  /*                            Selects transmission reception baudrate as 9600*/
   50:      EnableInterrupts 
  0086 9a       RIM   
   51:  /*-----------------------------------------------------------------------------
   52:  Transmission through Polling mechanism
   53:  -----------------------------------------------------------------------------*/
   54:  #ifdef SCI_POLLING_TX                 /*Selects polling mode for transmission*/
   55:      SCI_Mode(SCI_TX_ENABLE);                                                  
   56:                                 
   57:      SCI_PutByte(Tx_Data);/*Single Byte transmission*/
   58:      Bool_Temp1 = (SCI_IsTransmitCompleted()); /* this function causes a 
   59:      volatile variable to change,hence it cannot be put as a right side operand 
   60:                                                        in a conditional stmt */
   61:                                  
   62:      while ( (User_Timeout_Function()) && (!(Bool_Temp1)));
   63:      SCI_PutBuffer( Buff,NbOfBytes);/*Continuous buffer transmission*/
   64:  
   65:  #endif
   66:  /*-----------------------------------------------------------------------------
   67:  Reception Through Polling mechanism
   68:  -----------------------------------------------------------------------------*/
   69:  #ifdef SCI_POLLING_RX                   /*Selects polling mode for  reception*/
   70:      SCI_Mode(SCI_RX_ENABLE);               /* Enable the receiver mode of SCI*/
  0087 1400     BSET  SCICR2,#2
   71:      
   72:  /*-----------------------------Single Byte Reception-------------------------*/
   73:  
   74:      do                                              /*Wait for data reception*/
   75:      {
   76:          Err = SCI_IsReceptionCompleted();
  0089 cd0000   CALL  SCI_IsReceptionCompleted
  008c b700     LD    __OVL_main_Err,A
   77:      }while ((User_Timeout_Function()) && (Err == SCI_RX_DATA_EMPTY) ); 
  008e cd0000   CALL  User_Timeout_Function
  0091 4d       TNZ   A
  0092 2706     JREQ  *8 ;abs = 009a
  0094 b600     LD    A,__OVL_main_Err
  0096 a1fd     CP    A,#-3
  0098 27ef     JREQ  *-15 ;abs = 0089
   78:       
   79:      if(User_Timeout_Function())               /*Byte received before Timeout */    
  009a cd0000   CALL  User_Timeout_Function
  009d 4d       TNZ   A
  009e 272b     JREQ  *45 ;abs = 00cb
   80:      { 
   81:          if(Err == SCI_RECEIVE_OK)
  00a0 b600     LD    A,__OVL_main_Err
  00a2 2608     JRNE  *10 ;abs = 00ac
   82:          {            
   83:              Rx_Data = SCI_GetByte();             /*Correct Data Byte received*/     
  00a4 cd0000   CALL  SCI_GetByte
  00a7 b700     LD    __OVL_main_7_Rx_Data,A
   84:              Nop 
  00a9 9d       NOP   
   85:          }    
  00aa 2021     JRT   *35 ;abs = 00cd
   86:          else
   87:          {
   88:              if((unsigned char)Err & SCI_NOISE_ERR)
  00ac 050003   BTJF  __OVL_main_Err,#2,*6 ;abs = 00b2
   89:              {
   90:                  Userfunction ();
  00af cd0000   CALL  Userfunction
   91:              }
   92:              if((unsigned char)Err & SCI_OVERRUN_ERR)
  00b2 070003   BTJF  __OVL_main_Err,#3,*6 ;abs = 00b8
   93:              {
   94:                  Userfunction ();
  00b5 cd0000   CALL  Userfunction
   95:              }
   96:              if((unsigned char)Err & SCI_FRAMING_ERR)
  00b8 030003   BTJF  __OVL_main_Err,#1,*6 ;abs = 00be
   97:              {
   98:                  Userfunction ();
  00bb cd0000   CALL  Userfunction
   99:              }
  100:              if((unsigned char)Err & SCI_PARITY_ERR)
  00be 010003   BTJF  __OVL_main_Err,#0,*6 ;abs = 00c4
  101:              {
  102:                  Userfunction ();
  00c1 cd0000   CALL  Userfunction
  103:              } 
  104:              Rx_Data = SCI_GetByte();           /*Corrupted Data Byte received*/
  00c4 cd0000   CALL  SCI_GetByte
  00c7 b700     LD    __OVL_main_7_Rx_Data,A
  00c9 2002     JRT   *4 ;abs = 00cd
  105:          } 
  106:      }                                                       /*Timeout elapsed*/
  107:      else
  108:      {
  109:          while(1);                   /*Transmitter or Receiver having problem */
  00cb 20fe     JRT   *0 ;abs = 00cb
  110:      }                                                                          
  111:  
  112:  /*----------------------------Buffer Reception-------------------------------*/
  113:  
  114:      Err = (SCI_GetBuffer(Buff_Rcv,(unsigned char)19));  /*Reception of data 
  00cd a601     LD    A,#HIGH(Buff_Rcv)
  00cf b700     LD    __OVL_13_SCI_GetBuffer_p1,A
  00d1 ae00     LD    X,#Buff_Rcv
  00d3 bf01     LD    __OVL_13_SCI_GetBuffer_p1:1,X
  00d5 a613     LD    A,#19
  00d7 cd0000   CALL  SCI_GetBuffer
  00da b700     LD    __OVL_main_Err,A
  00dc 2603     JRNE  *5 ;abs = 00e1
  115:                                                                 in user buffer*/
  116:                                                      
  117:      if(Err == SCI_RECEIVE_OK)                       /*Checks the error status*/
  118:      {
  119:          Nop                                                 /* Reception OK*/
  00de 9d       NOP   
  120:      }                                                         
  00df 2018     JRT   *26 ;abs = 00f9
  121:      else                                     /*Error Ocurred during reception*/
  122:      {
  123:          if((unsigned char)Err & SCI_NOISE_ERR)
  00e1 050003   BTJF  __OVL_main_Err,#2,*6 ;abs = 00e7
  124:          {
  125:              Userfunction ();
  00e4 cd0000   CALL  Userfunction
  126:          }
  127:          if((unsigned char)Err & SCI_OVERRUN_ERR)
  00e7 070003   BTJF  __OVL_main_Err,#3,*6 ;abs = 00ed
  128:          {
  129:              Userfunction ();
  00ea cd0000   CALL  Userfunction
  130:          }
  131:          if((unsigned char)Err & SCI_FRAMING_ERR)
  00ed 030003   BTJF  __OVL_main_Err,#1,*6 ;abs = 00f3
  132:          {
  133:              Userfunction ();
  00f0 cd0000   CALL  Userfunction
  134:          }
  135:          if((unsigned char)Err & SCI_PARITY_ERR)
  00f3 010003   BTJF  __OVL_main_Err,#0,*6 ;abs = 00f9
  136:          {
  137:              Userfunction ();
  00f6 cd0000   CALL  Userfunction
  138:          }
  139:      }   
  140:  #endif 
  141:  /*-----------------------------------------------------------------------------
  142:  Transmission through Interrupt Driven without Buffer mode
  143:  -----------------------------------------------------------------------------*/ 
  144:  #ifdef SCI_ITDRV_WITHOUTBUF_TX      /*Selects interrupt mode for transmission*/
  145:                                      /*Interrupt enable when TDRE flag is set */
  146:      SCI_Mode(SCI_TX_ENABLE);   
  147:      if(SCI_IsTransmitCompleted())
  148:      {         
  149:          SCI_PutByte((unsigned char)55);  
  150:          while (!(SCI_IsTransmitCompleted())); 
  151:          SCI_PutString(Buff);/*user pointer is copied to the global pointer*/
  152:  /* Here,user can perform other tasks or operations except transmission till the
  153:  time transmission is complete,after which user can perform transmission again*/        
  154:          
  155:          while (!(SCI_IsTransmitCompleted())); 
  156:      }           
  157:  #endif
  158:  /*-----------------------------------------------------------------------------
  159:  Reception through Interrupt driven without Buffer mechanism
  160:  -----------------------------------------------------------------------------*/
  161:  #ifdef SCI_ITDRV_WITHOUTBUF_RX         /*Selects interrupt mode for reception*/
  162:                          /*Interrupt enable when RDR register is ready to read*/
  163:      SCI_IT_Enable((unsigned char)SCI_RECEIVE_OVERRUN);            
  164:      SCI_Mode(SCI_RX_ENABLE); 
  165:               
  166:  /*----------------------------Single Byte reception--------------------------*/   
  167:      do
  168:      {
  169:          Err = SCI_IsReceptionCompleted();
  170:      }while ((User_Timeout_Function()) && (Err == SCI_RX_DATA_EMPTY) );
  171:                      /* Wait for the completion of current data byte reception*/ 
  172:       
  173:      if(User_Timeout_Function())      
  174:      {   
  175:         if(Err == SCI_RECEIVE_OK)
  176:          {/*Reception OK                                         */
  177:            Nop
  178:              Rx_Data = SCI_GetByte(); 
  179:              Nop
  180:          }
  181:          else
  182:          {
  183:              if((unsigned char)Err & SCI_NOISE_ERR)
  184:              {
  185:                  Userfunction ();
  186:              }
  187:              if((unsigned char)Err & SCI_OVERRUN_ERR)
  188:              {
  189:                  Userfunction ();
  190:              }
  191:              if((unsigned char)Err & SCI_FRAMING_ERR)
  192:              {
  193:                  Userfunction ();
  194:              }
  195:              if((unsigned char)Err & SCI_PARITY_ERR)
  196:              {
  197:                  Userfunction ();
  198:              }
  199:              Rx_Data = SCI_GetByte();  /*User will receive the corrupted data */
  200:          }
  201:      }    
  202:      else
  203:      {
  204:          while(1);                   /*Transmitter or Receiver having problem */
  205:      }             
  206:  
  207:  /*------------------------------Buffer Reception-----------------------------*/    
  208:  
  209:      SCI_GetBuffer(Buff_Rcv,(unsigned char)19);  
  210:                   /* Any data received before calling this function is ignored*/
  211:  /* Here, user can perform other tasks or operations except reception till the
  212:       time the function SCI_IsReceptionCompleted() returns RECEIVE_OK, 
  213:       after which user can perform reception again                            */
  214:   
  215:      do
  216:      {
  217:          Err = SCI_IsReceptionCompleted();
  218:      }while (Err == SCI_BUFFER_ONGOING); 
  219:         /* To be sure that the communication by this point has been completed */
  220:  
  221:      if(Err == SCI_RECEIVE_OK) 
  222:      {
  223:          Nop                                                  /*Reception OK */  
  224:      }
  225:      else 
  226:      {
  227:          if((unsigned char)Err & SCI_NOISE_ERR)
  228:          {
  229:              Userfunction ();
  230:          }
  231:          if((unsigned char)Err & SCI_OVERRUN_ERR)
  232:          {
  233:              Userfunction ();
  234:          }
  235:          if((unsigned char)Err & SCI_FRAMING_ERR)
  236:          {
  237:              Userfunction ();
  238:          }
  239:          if((unsigned char)Err & SCI_PARITY_ERR)
  240:          {
  241:              Userfunction ();
  242:          }
  243:      }                                                                              
  244:  
  245:  #endif  
  246:   Nop                                      
  00f9 9d       NOP   
  247:  }
  00fa 81       RET   
  248:  /******************************************************************************
  249:  Interrupt Subroutine
  250:  ******************************************************************************/
  251:  
  252:  #ifdef _HIWARE_                                  /* Test for HIWARE Compiler */
  253:  #pragma TRAP_PROC SAVE_REGS            /* Additional registers will be saved */
  254:  #else
  255:  #ifdef _COSMIC_                                  /* Test for Cosmic Compiler */
  256:  @interrupt                                      /* Cosmic interrupt handling */
  257:  #else
  258:  #error"Unsupported Compiler!"                 /* Compiler Defines not found! */
  259:  #endif
  260:  #endif
  261:  void sci_rt (void)
  262:  {

Function: sci_rt
Source  : ..\..\..\..\Sources\main.c
Options : -Cc -Cni -F2 -Lasm=%n.lst -Ml -N -Or -TE1uE

  0000 9089     PUSH  Y
  0002 b600     LD    A,_R_Z
  0004 88       PUSH  A
  0005 b601     LD    A,_LEX:1
  0007 88       PUSH  A
  0008 b600     LD    A,_LEX
  000a 88       PUSH  A
  000b b601     LD    A,_SEX:1
  000d 88       PUSH  A
  000e b600     LD    A,_SEX
  0010 88       PUSH  A
  263:      SCI_IT_Function();                    /*Interrupt function of the library*/
  0011 cd0000   CALL  SCI_IT_Function
  264:  }
  0014 84       POP   A
  0015 b700     LD    _SEX,A
  0017 84       POP   A
  0018 b701     LD    _SEX:1,A
  001a 84       POP   A
  001b b700     LD    _LEX,A
  001d 84       POP   A
  001e b701     LD    _LEX:1,A
  0020 84       POP   A
  0021 b700     LD    _R_Z,A
  0023 9085     POP   Y
  0025 80       IRET  
  265:  
  266:  /*******************************End OF ISR************************************/
  267:   
  268:  /*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
  269:  void Userfunction(void)
  270:  {

Function: Userfunction
Source  : ..\..\..\..\Sources\main.c
Options : -Cc -Cni -F2 -Lasm=%n.lst -Ml -N -Or -TE1uE

  271:      SCI_Forced_Clear_Flag();
  0000 cc0000   JP    SCI_Forced_Clear_Flag
  272:  }
  273:  
  274:  BOOL User_Timeout_Function(void)
  275:  {    

Function: User_Timeout_Function
Source  : ..\..\..\..\Sources\main.c
Options : -Cc -Cni -F2 -Lasm=%n.lst -Ml -N -Or -TE1uE

  276:      while(Timeoutcount < 50000)
  0000 2013     JRT   *21 ;abs = 0015
  277:      {
  278:          Timeoutcount++ ;
  0002 c60001   LD    A,Timeoutcount:1
  0005 ce0000   LD    X,Timeoutcount
  0008 4c       INC   A
  0009 2601     JRNE  *3 ;abs = 000c
  000b 5c       INC   X
  000c c70001   LD    Timeoutcount:1,A
  000f cf0000   LD    Timeoutcount,X
  279:          return (TRUE);        
  0012 a601     LD    A,#1
  0014 81       RET   
  0015 c60001   LD    A,Timeoutcount:1
  0018 ce0000   LD    X,Timeoutcount
  001b a3c3     CP    X,#195
  001d 25e3     JRULT *-27 ;abs = 0002
  001f 2604     JRNE  *6 ;abs = 0025
  0021 a150     CP    A,#80
  0023 25dd     JRULT *-33 ;abs = 0002
  280:      } 
  281:      return (FALSE)  ;
  0025 4f       CLR   A
  282:  }            
  0026 81       RET   
  283:      
  284:  /**** (c) 2002   STMicroelectronics *************************** END OF FILE **/
  285:  
