微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > C8051F单片机读写串行EEPROM程序

C8051F单片机读写串行EEPROM程序

时间:11-24 来源:互联网 点击:
//C8051F单片机读写串行EEPROM程序,查询方式

//------------------------------------------------------------------------------
// Keil Software, Inc.
//
// Project: Cygnal 8051F000 I2C Example Program
//
// Filename: Cygnal_I2C_Example_Program.c
// Version: 1.0.0
// Description: This file contains example code that will communicate to a
// serial EEPROM using I2C. Data will be printed over the
// serial port.
//
// Copyright 2000 - Keil Software, Inc.
// All rights reserved.
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Header files
//------------------------------------------------------------------------------
#include // Header file for the Cygnal 8051F0X0
#include // Header file for standard I/O

//------------------------------------------------------------------------------
// Value Definitions
//------------------------------------------------------------------------------
#define TRUE 0x01 // Value representing TRUE
#define FALSE 0x00 // Value representing FALSE
#define ON 0x01 // Value representing ON
#define OFF 0x00 // Value representing OFF
#define HIGH 0x01 // Value representing ON
#define LOW 0x00 // Value representing OFF

#define DELAY_WRITE 5000 // approx. 5 ms delay write time (about 1000 cycles / ms)
#define DELAY_BLINK 50000 // Value for delay time - blink

//------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
// Get high byte macro
#define high_byte(x) ((x & 0xFF00) >> 8)

//------------------------------------------------------------------------------
// I/O Port Defines
//------------------------------------------------------------------------------
sbit P1_6 = 0x96; // Define the individual bit (P1.6)
#define LED P1_6 // The eval board has an LED on P1.6

//------------------------------------------------------------------------------
// I2C Bus (SMBus) register bit definitions
//------------------------------------------------------------------------------
sbit BUS_BUSY = 0xC7; // SM Bus Busy (bit 7)
sbit BUS_EN = 0xC6; // SM Bus Enable (bit 6)
sbit BUS_START = 0xC5; // SM Bus Start (bit 5)
sbit BUS_STOP = 0xC4; // SM Bus Stop (bit 4)
sbit BUS_INT = 0xC3; // SM Bus Interrupt (bit 3)
sbit BUS_AA = 0xC2; // SM Bus ACK (bit 2)
sbit BUS_FTE = 0xC1; // SM Bus Clock timeout - high (bit 1)
sbit BUS_TOE = 0xC0; // SM Bus Clock timeout - low (bit 0)

//------------------------------------------------------------------------------
// Rerserve Interrupt vector space (the 8051F000 has an IV table from 0x03 to 0xAB)
//------------------------------------------------------------------------------
unsigned char code iv_table [0xB0] _at_ 0x0003;

//------------------------------------------------------------------------------
// Function Prototypes
//------------------------------------------------------------------------------
void write_byte (unsigned char data_out, unsigned int address);
unsigned char read_byte (unsigned int address);
void i2c_write (unsigned char output_data);
unsigned char i2c_read (void);
void delay_time (unsigned int time_end);
void i2c_start (void);
unsigned char i2c_stop_and_read (void);
void repeated_i2c_start_and_write (unsigned char output_data);
void i2c_stop_and_write (unsigned char output_data);

//------------------------------------------------------------------------------
// MAIN FUNCTION
//------------------------------------------------------------------------------
void main (void)
{
unsigned int eeprom_address;
unsigned char eeprom_data;

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top