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

📄 rs232.h

📁 本代码是用C8051F330 MCU对24LC256EEPROM的读写和与RS232终端以9600BPS速率通信代码.
💻 H
字号:

sfr16 DP       = 0x82;                 
sfr16 ADC0     = 0xbd;                 
sfr16 ADC0GT   = 0xc3;                
sfr16 ADC0LT   = 0xc5;                 
sfr16 RCAP2    = 0xeb;                
sfr16 TMR2     = 0xcc;                 
sfr16 TMR3     = 0x94;



#ifdef INT_ISR_C             

#define  WRITE          0x00                 // SMBus WRITE command
#define  READ           0x01                 // SMBus READ command

// Device addresses (7 bits, lsb is a don't care)
#define  EEPROM_ADDR    0xA0                 // Device address for slave target
                                             // Note: This address is specified
                                             // in the Microchip 24C256
                                             // datasheet.
// SMBus Buffer Size
#define  SMB_BUFF_SIZE  0x08                 // Defines the maximum number of bytes
                                             // that can be sent or received in a
                                             // single transfer

// Status vector - top 4 bits only
#define  SMB_MTSTA      0xE0                 // (MT) start transmitted
#define  SMB_MTDB       0xC0                 // (MT) data byte transmitted
#define  SMB_MRDB       0x80                 // (MR) data byte received
// End status vector definition

//------------------------------------------------------------------------------------
// Global VARIABLES
//------------------------------------------------------------------------------------
unsigned char* pSMB_DATA_IN;                 // Global pointer for SMBus data
                                             // All receive data is written here

unsigned char SMB_SINGLEBYTE_OUT;            // Global holder for single byte writes.

unsigned char* pSMB_DATA_OUT;                // Global pointer for SMBus data.
                                             // All transmit data is read from here

unsigned char SMB_DATA_LEN;                  // Global holder for number of bytes
                                             // to send or receive in the current
                                             // SMBus transfer.

unsigned char WORD_ADDR;                     // Global holder for the EEPROM word
                                             // high 8bits address that will be accessed in
                                             // the next transfer

unsigned char WORD_ADDR1;                     // Global holder for the EEPROM word
                                             // low 8bits address that will be accessed in
                                             // the next transfer
unsigned char TARGET;                        // Target SMBus slave address

bit SMB_BUSY = 0;                            // Software flag to indicate when the
                                             // EEPROM_ByteRead() or 
                                             // EEPROM_ByteWrite()
                                             // functions have claimed the SMBus

bit SMB_RW;                                  // Software flag to indicate the
                                             // direction of the current transfer

bit SMB_SENDWORDADDR;                        // When set, this flag causes the ISR
                                             // to send the high 8-bit <WORD_ADDR>
                                             // after sending the slave address.


bit SMB_SENDWORDADDR1;                        // When set, this flag causes the ISR
                                             // to send the low 8-bit <WORD_ADDR>
                                             // after sending the slave address.


bit SMB_RANDOMREAD;                          // When set, this flag causes the ISR
                                             // to send a START signal after sending
                                             // the word address.

bit SMB_ACKPOLL;                             // When set, this flag causes the ISR
                                             // to send a repeated START until the
                                             // slave has acknowledged its address



#endif



void EEPROM_ByteWrite(unsigned int addr, unsigned char dat);
unsigned char EEPROM_ByteRead(unsigned int addr);
void Port_IO_Init(void);
void Oscillator_Init(void);
void UART_Init(void);
void UART_Isr(void);
void I2C_Init(void);
void Timer3_Init(void);
void Timer3_ISR (void);
void SMBus_ISR (void);

⌨️ 快捷键说明

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