6 i2c.c source code listing, I2c.c, C.c description 9.6 i2c.c source code listing – Arizona Picdem 17 User Manual

Page 77

Advertising
background image

2001 Microchip Technology Inc.

DS39024B-page 71

I

2

C.C

Description

9.6

I2C.C

Source Code Listing

//****************************************************

//* I2C.C

//****************************************************

//* Rodger Richey

//* Principal Applications Engineer

//* Microchip Technology Incorporated

//****************************************************

//* 2 December 1998

//* Compiled using MPLAB C17 C Compiler V2.20

//****************************************************

//* This program reads and writes to the 24LC01B

//* Serial EEPROM using the master mode I2C module.

//* The value of the address is written to each

//* address of the EEPROM. The program then reads

//* the value out of the EEPROM and prints both

//* the desired value and the read value to the

//* USART2 for display on the Monitor program. The

//* address is also displayed on the memory mapped

//* LEDs.

//****************************************************

//* Uses an oscillator of 16MHz

//****************************************************

#include <p17c756.h>

#include <delays.h>

#include <i2c16.h>

#include <usart16.h>

#include <stdlib.h>

void PutsUSART2(char *data);

void PutcUSART2(char data);

// Prints a string to USART2 using hardware handshaking;

void PutsUSART2(char *data)

{

do

{

// Wait for USART2 to finish prev operation

while(BusyUSART2());

// Wait for CTS

while(PORTBbits.RB4);

// Write a character to USART2

putcUSART2(*data);

} while(*data++); // Increment pointer and check for NULL

return;

}

// Prints a character to USART2 using hardware handshaking

void PutcUSART2(char data)

{

while(BusyUSART2());

// Wait for

USART2 to finish

while(PORTBbits.RB4);

// Wait for CTS

Advertising