ajit_nayak87
Member level 5
Dear all
i am trying to interface with 24lc08 with pic18F24k series . i am using XC8 Compiler V2.05/ MPLAB X IDE 5.15 . here i am attached sample code .
I am trying to write into eeprom location and read and display on seven segment display. with below code it display 00
i am using mcc generated file to read and write operation . the code works well with ds1307. how to provide slave address and start address for location
if i used logic analyzer i will get not acknowledge from slave device.
i am trying to interface with 24lc08 with pic18F24k series . i am using XC8 Compiler V2.05/ MPLAB X IDE 5.15 . here i am attached sample code .
I am trying to write into eeprom location and read and display on seven segment display. with below code it display 00
i am using mcc generated file to read and write operation . the code works well with ds1307. how to provide slave address and start address for location
if i used logic analyzer i will get not acknowledge from slave device.
C:
#include "mcc_generated_files/mcc.h"
#include"mcc_generated_files/examples/i2c1_master_example.h"
unsigned int i=0;
unsigned int k=0;
unsigned int count;
unsigned int x;
#define LED RC7
#define CONTROLREG 0xFF
#define SDA RC4 // Data pin for i2c
#define SCK RC3 // Clock pin for i2c
#define SDA_DIR TRISC4 // Data pin direction
#define SCK_DIR TRISC3 // Clock pin direction
#define I2C_SPEED 150 // kbps
unsigned short int cnt, num,Dgt=0;;
unsigned short int temp1,temp2,temp3;
int sec;
int min;
int hour;
int date;
int month;
int year;
int day;
int temp=0;
int r_data;
#define Seg1 0x01
#define Seg2 0x02
#define Seg3 0x04
#define Seg4 0x08
#define Seg5 0x10
#define Seg6 0x20
unsigned char Flag_Update=0;
void Delay(unsigned int k) {
unsigned int j;
for(j=0; j<k; j++);
}
void SetSeg(unsigned short data, unsigned short segno)
{
switch(data) {
case 0:
PORTB = 0x3F;
break;
case 1:
PORTB = 0x06;
break;
case 2:
PORTB = 0x5B;
break;
case 3:
PORTB = 0x4F;
break;
case 4:
PORTB = 0x66;
break;
case 5:
PORTB = 0x6D;
break;
case 6:
PORTB = 0x7D;
break;
case 7:
PORTB = 0x07;
break;
case 8:
PORTB = 0x7F;
break;
case 9:
PORTB = 0X6F;
break;
default :
PORTB = 0X00;
break;
}
if(segno==1) {
PORTA = Seg4;
}
if(segno==2) {
PORTA = Seg3;
}
if(segno==3) {
PORTA = Seg2;
}
if(segno==4) {
PORTA = Seg1;
}
if(segno==5) {
PORTC=0X00;
PORTC = 0x40;//DP2 fourth Segment
// PORTCbits.RC5=1;
}
if(segno==6) {
PORTC=0X00;
PORTC= 0x20;//DP2 third Segment
//PORTCbits.RC6=1;
}
if(segno==7) {
PORTA=0X00;
PORTA = Seg5; //DP2 Second Segment
// PORTAbits.RA4=1;
}
if(segno==8) {
PORTA=0X00;
PORTA = Seg6; //DP2 First Segment
// PORTAbits.RA5=1;
}
}
unsigned int bcdtodecimal(unsigned int bcd) {
unsigned int decimal;
decimal = (((bcd & 0xF0) >> 4) * 10) + (bcd & 0x0F);
return decimal;
}
void ISR_Routine(void) {
if(PIR0bits.TMR0IF==1) {
PIR0bits.TMR0IF = 0;
count= count+1;
if(count>=2) {
LED=!LED;
Flag_Update=1;
count=0;
}
}
}
void main(void) {
// Initialize the device
SYSTEM_Initialize();
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
// Use the following macros to:
// Enable the Global Interrupts
//INTERRUPT_GlobalInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Enable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptEnable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
I2C1_Initialize();
//I2C1_Read2ByteRegister(0XA0,0x02);
I2C1_Write2ByteRegister(0XA0,0x02,0x58);
while (1)
{
sec=I2C1_Read2ByteRegister(0XA0,0x02);
if(Flag_Update==1) {
/*SetSeg(min >> 4,4);
__delay_ms(10);
SetSeg(min & 0x0f,3);
__delay_ms(10);*/
SetSeg(sec >> 4,2);
__delay_ms(10);
SetSeg(sec & 0x0f,1);
__delay_ms(10);
Flag_Update = 0; //ready for next update
}
}
}