Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I2C sample codes for pic16f877a

Status
Not open for further replies.

dhanraj_kmr

Advanced Member level 4
Joined
Sep 23, 2008
Messages
117
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Chennai, INDIA
Activity points
2,174
i2c pic16f877a

Hi to all.i am newbie to I2C in pic16f877a, i need to learn to programe for i2c in pic16f877a. but th datasheet of it is really confusing. so i cant get a neat idea abt how to start to write for SDA and SCK. so some tell me exactly how to write for it and upload some sample programes for MPLAB.


:cry:
thanx in advance
 

pic16f877a i2c

The best way to start is to make a project that uses an I2C device (like the eeprom 24LC256) and a PIC.

Google around a bit, ther may be many projects that use these devices.

Are you using C or asm for the project ??

aa
 

ccs i2c

i am using C. thats the problm.

Added after 5 minutes:

one more doubt is wats the difference btwn I2C mater mode and slave mode?
simple eplanation is enough.
 

i2c ccs example

Which kind of c compiler are you using, I use CCS C compiler (PCM) to develop projects.

CCS contains functions and procedures that are dedicated for I2C operations, I am other C compilers are also similar.

When a device initiates the I2C 'conversation', it is called the i2C master, while the device that receives the command from the master is called I2C slave.

In the PIC vs 24LC256 combination the PIC is the master as the EEPROM simply responds to the commands sent by the PIC, the EEPROM can also send back data (when a read command is sent by the master) but here again it is not the master.


See this link https://www.robot-electronics.co.uk/htm/using_the_i2c_bus.htm
thanks
a
 
ccs i2c example

i am using mplab.


here we go. while transmittin through i2c master mode whats the need of transmittin the address before transittin the data. whats that address means here?
is its slave address or address of the data which we transmittin?

one example: i want to transfr the data to EEPROM. for that i need to write code to start the i2c and tranfr the data and recieve the ACK and stop the trsmittn. for that how do i assign SDA and SCK?

pls:?:
 

pic16f877 i2c

You have not mentioned what C compiler you are using...

Each I2C slave has an unique address (I am sure you know that), the I2C master has to address each of the slaves using this address.

Before the address bits , a start bit and a control code is sent.. For more details on the exact transmission please read the datasheet for the 24LC256 device.

Pin assignment will depend on the kind of compiler/assembler being used.

As a rule you should spend more time reading the datasheets of the various components you intend to use in your project, you should also read the documentation of the C compiler.

thanks
a
 

ccs c i2c

For I2C communication can be used the code from attachment. Is very simple and is written in C. The Hi-Tech compiler was used.
 

Attachments

  • pic_hi-tech_c_i2c_for_eeprom_24lc01b_1258.zip
    2.6 KB · Views: 386
i2c ccs

try this code, its working for me.
 
Re: i2c ccs

try this code, its working for me.

k can give me the code thanks in advance

---------- Post added at 10:37 ---------- Previous post was at 10:34 ----------

hi friend is working but i need to display the data in LCD display please help me
 

Re: i2c ccs

k can give me the code thanks in advance

hi friend is working but i need to display the data in LCD display please help me
What compiler you use? I have I2C in Hi-Tech. This 2 example DS1307 and **broken link removed**.
 

Re: i2c ccs

k can give me the code thanks in advance

---------- Post added at 10:37 ---------- Previous post was at 10:34 ----------

hi friend is working but i need to display the data in LCD display please help me



if you are using hi-tech you can use the LCD example code on the samples folder.
It is easy enough to understand.

Be aware that the example is for a non rohs lcd. For a rohs example you will need to tweak it a little ;)
 

Re: i2c ccs

same Hi-tech c only.....
i need the circuit diagram also....
 

Re: i2c ccs

yes 16*2 only

---------- Post added at 16:00 ---------- Previous post was at 15:53 ----------

#define XTAL_FREQ 20MHZ /* Crystal frequency in MHz */
#include <pic.h>
#include "delay.h"
#include "lcd.h"
#include "24LC256.h"

#define LCD_BL RB3 //define LCD_BL as RB3

unsigned char data;

// ============================================================
// Configuration Bits (PIC16F886)
// ============================================================
__CONFIG(HS & WDTDIS & UNPROTECT & BORDIS & LVPDIS);

/**************************************************************
Initialise System
**************************************************************/
void System_init(void){

ANSELH = 0x00; //disable analog input at portb
TRISB = 0b00000000; //set portb as output port
PORTB = 0;
}

/**************************************************************
Main Program
**************************************************************/
void main(void){

System_init();
ee_init(); //EEPROM initialize
lcd_init(); //LCD initialize

LCD_BL=1; //Turn on backlight

lcd_goto(1,1); //Goto x:1, y:1
lcd_puts("\fStart Writing..."); //\f: Clear Screen
ee_write(0,'H'); //write 'H' into EEPROM address '0'
ee_write(1,'E'); //write 'E' into EEPROM address '1'...
ee_write(2,'L');
ee_write(3,'L');
ee_write(4,'0');
lcd_goto(2,1);
lcd_puts("Data Saved");

DelayMs(2000); //Delay 2sec
lcd_goto(1,1);
lcd_puts("\fStart Reading...");
lcd_goto(2,1);
lcd_putch(ee_read(0)); //Read data from EEPROM address '0' & dispaly at LCD
lcd_putch(ee_read(1)); //Read data from EEPROM address '1' & dispaly at LCD...
lcd_putch(ee_read(2));
lcd_putch(ee_read(3));
lcd_putch(ee_read(4));
lcd_puts(" -Data Read");

while(1){
LCD_BL=1; //turn on backlight
DelayMs(1000);
LCD_BL=0; //turn off backlight
DelayMs(1000);
}

}

Friend i used this code.... its compiling
but after fetching the hex code... the data does not reading from the eeprom instead just showing "start writing" only..
i think i have done some mistakes but i cant able to find
plz help...
thanks in advance
 

Re: i2c ccs

Do you have the C files associated with the header file you added (24LC256.h) in the same folder?

Also have disabled the configuration bit as read enabled..... that is without encryption.... Only then you would be able to read from the Device .....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top