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

📄 26.lst

📁 这是我大学4年来做过的竞赛以及老师的科研项目所积累下来的c51源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE 26
OBJECT MODULE PLACED IN 26.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 26.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          //------------------------------------------------------------------------------
   2          // Keil Software, Inc.
   3          // 
   4          // Project:     Cygnal 8051F000 I2C Example Program
   5          //
   6          // Filename:    Cygnal_I2C_Example_Program.c
   7          // Version:     1.0.0
   8          // Description: This file contains example code that will communicate to a 
   9          //                              serial EEPROM using I2C.  Data will be printed over the
  10          //                              serial port.
  11          //
  12          // Copyright 2000 - Keil Software, Inc.
  13          // All rights reserved.
  14          //------------------------------------------------------------------------------
  15          
  16          //------------------------------------------------------------------------------
  17          // Header files
  18          //------------------------------------------------------------------------------
  19          #include <REG51F0X0.H>                                          // Header file for the Cygnal 8051F0X0
  20          #include <STDIO.H>                                                      // Header file for standard I/O
  21          
  22          //------------------------------------------------------------------------------
  23          // Value Definitions
  24          //------------------------------------------------------------------------------
  25          #define         TRUE                    0x01                    // Value representing TRUE
  26          #define         FALSE                   0x00                    // Value representing FALSE
  27          #define         ON                              0x01                    // Value representing ON
  28          #define         OFF                             0x00                    // Value representing OFF
  29          #define         HIGH                    0x01                    // Value representing ON
  30          #define         LOW                             0x00                    // Value representing OFF
  31          
  32          #define         DELAY_WRITE             5000                    // approx. 5 ms delay write time (about 1000 cycles / ms)
  33          #define         DELAY_BLINK             50000                   // Value for delay time - blink 
  34          
  35          //------------------------------------------------------------------------------
  36          // Macros
  37          //------------------------------------------------------------------------------
  38                                                                                                  // Get high byte macro
  39          #define high_byte(x)            ((x & 0xFF00) >> 8)
  40          
  41          //------------------------------------------------------------------------------
  42          // I/O Port Defines
  43          //------------------------------------------------------------------------------
  44          sbit            P1_6            =       0x96;                   // Define the individual bit (P1.6)
  45          #define         LED                             P1_6                    // The eval board has an LED on P1.6
  46          
  47          //------------------------------------------------------------------------------
  48          // I2C Bus (SMBus) register bit definitions
  49          //------------------------------------------------------------------------------
  50          sbit            BUS_BUSY        =       0xC7;                   // SM Bus Busy (bit 7)
  51          sbit            BUS_EN          =       0xC6;                   // SM Bus Enable (bit 6)
  52          sbit            BUS_START       =       0xC5;                   // SM Bus Start (bit 5)
  53          sbit            BUS_STOP        =       0xC4;                   // SM Bus Stop (bit 4)
  54          sbit            BUS_INT         =       0xC3;                   // SM Bus Interrupt (bit 3)
  55          sbit            BUS_AA          =       0xC2;                   // SM Bus ACK (bit 2)
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 2   

  56          sbit            BUS_FTE         =       0xC1;                   // SM Bus Clock timeout - high (bit 1)
  57          sbit            BUS_TOE         =       0xC0;                   // SM Bus Clock timeout - low (bit 0)
  58          
  59          //------------------------------------------------------------------------------
  60          // Rerserve Interrupt vector space (the 8051F000 has an IV table from 0x03 to 0xAB)
  61          //------------------------------------------------------------------------------
  62          unsigned char code iv_table [0xB0] _at_ 0x0003;
  63          
  64          //------------------------------------------------------------------------------
  65          // Function Prototypes
  66          //------------------------------------------------------------------------------
  67          void write_byte (unsigned char data_out, unsigned int address);
  68          unsigned char read_byte (unsigned int address);
  69          void i2c_write (unsigned char output_data);
  70          unsigned char i2c_read (void);
  71          void delay_time (unsigned int time_end);
  72          void i2c_start (void);
  73          unsigned char  i2c_stop_and_read (void);
  74          void repeated_i2c_start_and_write (unsigned char output_data);
  75          void i2c_stop_and_write (unsigned char output_data);
  76          
  77          //------------------------------------------------------------------------------
  78          // MAIN FUNCTION 
  79          //------------------------------------------------------------------------------
  80          void main (void)
  81          {
  82   1              unsigned int eeprom_address;
  83   1              unsigned char eeprom_data;      
  84   1      
  85   1              // Disable the WDT (page 93 of data sheet)
  86   1              WDTCN = 0xDE;
  87   1              WDTCN = 0xAD;
  88   1      
  89   1              // Set internal oscilator to 16 MHz - Startup is 2 MHz (page 98 of data sheet)
  90   1              OSCICN = 0x07;
  91   1      
  92   1      
  93   1              // On the Cygnal processor there is a "Crossover" network that must     
  94   1              // be initialized to establish the port pin assignements
  95   1              // (see page 101 of the data sheet)
  96   1              XBR0 = 0x05;                                                    // Set UART and SMBus to be enabled
  97   1              XBR1 = 0x00;                                                    // No functions routed in this register
  98   1              XBR2 = 0x40;                                                    // Pull-ups enabled, XBAR enabled, no ADC
  99   1      
 100   1              PRT1CF = 0x40;                                                  // Set port 1.6 to push/pull 
 101   1                                                                                              // (i.e the LED on the Eval board)
 102   1      
 103   1              // Initialize the serial port (9600, 8, N, 1)      
 104   1              PCON &= 0x7F;                                                   // Clear bit 7 of the PCON register (SMOD1 = 0)  
 105   1              SCON = 0x50;                                                    // 0101,0000 (Mode 1 and RxD enable)                    
 106   1              CKCON = 0x10;                                                   // Make T1M 1 (i.e. SysClk for Timer 1 not / by 12)
 107   1                                                                                              // (see page 141 of the data sheet)
 108   1      
 109   1              TMOD |= 0x20;                                                   // Timer #1 in autoreload 8 bit mode
 110   1              TCON |= 0x40;                                                   // Set Timer #1 to run mode (TR = 1)
 111   1              TH1 = 0xCC;                                                             // Baud rate is determined by
 112   1                                                                                              // Timer #1 overflow rate
 113   1                                                                                              // Baud Rate = (Fcpu / 32) / (256 - TH1)
 114   1                                                                                              // Fcpu = 16.00 MHz (see above setting of osc.)
 115   1                                                                                              // TH1 = 252
 116   1                                                                                              // (see page 130 of the data sheet)
 117   1      
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 3   

 118   1              SCON |= 0x02;                                                   // Set UART to send first char (TI = 1)
 119   1      
 120   1      
 121   1              // Initialize the I2C Bus (SMBus)
 122   1              // (see page 111)
 123   1              SMB0CR = 0x60;                                                  // Set the clock to approx. 10 uS TH, TL (50 kHz) 
 124   1                                                                                              // (see page 117 of the data sheet)
 125   1              BUS_EN = TRUE;                                                  // Enable the bus
 126   1      
 127   1      
 128   1              printf("\n\rKeil Software, Inc.\n\r");  // Display starup message
 129   1              printf("8051F0X0 MCU I睠 Example Test Program\n\r");
 130   1              printf("Version 1.0.0\n\r");
 131   1              printf("Copyright 2000 - Keil Software, Inc.\n\r");
 132   1              printf("All rights reserved.\n\n\r");
 133   1      
 134   1              printf("Writing data to EEPROM....");
 135   1      
 136   1              for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
 137   1                      write_byte((unsigned char)eeprom_address + 0x30, eeprom_address);
 138   1      
 139   1              printf("Done!\r\n\n");
 140   1      
 141   1      
 142   1              while (TRUE)
 143   1              {
 144   2                      for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
 145   2                      {
 146   3                                                                                              // Read data from eeprom and display it
 147   3                              eeprom_data = read_byte(eeprom_address);
 148   3                              printf("Address: %3u    Character: %c\n\r", eeprom_address, eeprom_data);
 149   3      
 150   3                              LED = HIGH;                                             // Blink LED with delay
 151   3                              delay_time(DELAY_BLINK);
 152   3      
 153   3                              LED = LOW;
 154   3                              delay_time(DELAY_BLINK);
 155   3                      }
 156   2              }
 157   1      }
 158          
 159          //------------------------------------------------------------------------------

⌨️ 快捷键说明

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