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

📄 f06x_uart0_interrupt.lst

📁 // This program demonstrates how to configure the C8051F060 to write to and read // from the UART i
💻 LST
📖 第 1 页 / 共 2 页
字号:
 151          // PORT_Init
 152          //-----------------------------------------------------------------------------
 153          //
 154          // Return Value : None
 155          // Parameters   : None
 156          //
 157          // This function configures the crossbar and GPIO ports.
 158          //
 159          // Pinout:
 160          //
 161          // P0.0   digital   push-pull     UART TX
 162          // P0.1   digital   open-drain    UART RX
 163          // P1.6   digital   push-pull     LED
 164          //-----------------------------------------------------------------------------
 165          void PORT_Init (void)
 166          {
 167   1         char SFRPAGE_SAVE = SFRPAGE;        // Save Current SFR page
 168   1      
 169   1         SFRPAGE = CONFIG_PAGE;              // Set SFR page
 170   1      
 171   1         XBR0     = 0x04;                    // Enable UART0
 172   1         XBR1     = 0x00;
 173   1         XBR2     = 0x40;                    // Enable crossbar and weak pull-up
 174   1      
 175   1      
 176   1         P0MDOUT |= 0x01;                    // Set TX pin to push-pull
 177   1         P1MDOUT |= 0x40;                    // Set P1.6(LED) to push-pull
 178   1      
 179   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFR page
C51 COMPILER V8.08   F06X_UART0_INTERRUPT                                                  02/14/2008 09:58:07 PAGE 4   

 180   1      }
 181          
 182          //-----------------------------------------------------------------------------
 183          // UART0_Init   Variable baud rate, Timer 2, 8-N-1
 184          //-----------------------------------------------------------------------------
 185          //
 186          // Return Value : None
 187          // Parameters   : None
 188          //
 189          // Configure UART0 for operation at <BAUDRATE> 8-N-1 using Timer2 as
 190          // baud rate source.
 191          //
 192          //-----------------------------------------------------------------------------
 193          void UART0_Init (void)
 194          {
 195   1         char SFRPAGE_SAVE;
 196   1      
 197   1         SFRPAGE_SAVE = SFRPAGE;             // Preserve SFRPAGE
 198   1      
 199   1         SFRPAGE = TMR2_PAGE;
 200   1      
 201   1         TMR2CN = 0x00;                      // Timer in 16-bit auto-reload up timer
 202   1                                             // mode
 203   1         TMR2CF = 0x08;                      // SYSCLK is time base; no output;
 204   1                                             // up count only
 205   1         RCAP2 = - ((long) SYSTEMCLOCK/BAUDRATE/16);
 206   1         TMR2 = RCAP2;
 207   1         TR2= 1;                             // Start Timer2
 208   1      
 209   1         SFRPAGE = UART0_PAGE;
 210   1      
 211   1         SCON0 = 0x50;                       // 8-bit variable baud rate;
 212   1                                             // 9th bit ignored; RX enabled
 213   1                                             // clear all flags
 214   1         SSTA0 = 0x15;                       // Clear all flags; enable baud rate
 215   1                                             // doubler (not relevant for these
 216   1                                             // timers);
 217   1                                             // Use Timer2 as RX and TX baud rate
 218   1                                             // source;
 219   1         ES0 = 1;
 220   1         IP |= 0x10;
 221   1      
 222   1         SFRPAGE = SFRPAGE_SAVE;             // Restore SFRPAGE
 223   1      }
 224          
 225          //-----------------------------------------------------------------------------
 226          // Interrupt Service Routines
 227          //-----------------------------------------------------------------------------
 228          
 229          //-----------------------------------------------------------------------------
 230          // UART0_Interrupt
 231          //-----------------------------------------------------------------------------
 232          //
 233          // This routine is invoked whenever a character is entered or displayed on the
 234          // Hyperterminal.
 235          //
 236          //-----------------------------------------------------------------------------
 237          
 238          void UART0_Interrupt (void) interrupt 4
 239          {
 240   1         SFRPAGE = UART0_PAGE;
 241   1      
C51 COMPILER V8.08   F06X_UART0_INTERRUPT                                                  02/14/2008 09:58:07 PAGE 5   

 242   1         if (RI0 == 1)
 243   1         {
 244   2           // Check if a new word is being entered
 245   2           if( UART_Buffer_Size == 0) {
 246   3              UART_Input_First = 0; }
 247   2      
 248   2           RI0 = 0;
 249   2           Byte = SBUF0;   // Read a character from Hyperterminal
 250   2           
 251   2           if (UART_Buffer_Size < UART_BUFFERSIZE)
 252   2           {
 253   3              UART_Buffer[UART_Input_First] = Byte;
 254   3      
 255   3              UART_Buffer_Size++;            // Update array's size
 256   3      
 257   3              UART_Input_First++;            // Update counter
 258   3           }
 259   2         }
 260   1      
 261   1         if (TI0 == 1)           // Check if transmit flag is set
 262   1         {
 263   2            TI0 = 0;
 264   2      
 265   2            if (UART_Buffer_Size != 1)        // If buffer not empty
 266   2            {
 267   3               // Check if a new word is being output
 268   3               if ( UART_Buffer_Size == UART_Input_First )  {
 269   4                    UART_Output_First = 0;   }
 270   3      
 271   3               Byte = UART_Buffer[UART_Output_First];
 272   3      
 273   3               if ((Byte >= 0x61) && (Byte <= 0x7A)) { // If upper case letter
 274   4                  Byte -= 32; }
 275   3      
 276   3               SBUF0 = Byte;                   // Transmit to Hyperterminal
 277   3      
 278   3               UART_Output_First++;             // Update counter
 279   3      
 280   3               UART_Buffer_Size--;              // Decrease array size
 281   3            }
 282   2            else
 283   2            {
 284   3               UART_Buffer_Size = 0;          // Set the array size to 0
 285   3               TX_Ready = 1;                  // Transmission complete
 286   3            }
 287   2         }
 288   1      }
 289          
 290          //-----------------------------------------------------------------------------
 291          // End Of File
 292          //-----------------------------------------------------------------------------


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    262    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     15    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.

C51 COMPILER V8.08   F06X_UART0_INTERRUPT                                                  02/14/2008 09:58:07 PAGE 6   


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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