#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
}
}
}
Don't think so. I2C1_Read2ByteRegister() is a high level function issuing combined address write and data read. It does the selection of read and write bit internally.you did not care about R/W bit in Slave_address_byte (Control_byte)
static i2c_fsm_states_t I2C_DO_SEND_ADR_READ(void)
{
I2C_Status.addressNackCheck = 1;
I2C_MasterSendTxData(I2C_Status.address << 1 | 1);
return I2C_RCEN;
}
Yes few people recommend to use 0x50 and 0x53 . But I don't know how they got these value. Because data sheet says 0xA0 and 0xA1
As per data sheet 24lc08 device
#define Slave address 0X50
#define start addres 0X00
void main(void) {
// Initialize the device
SYSTEM_Initialize();
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
I2C1_Initialize();
I2C1_Write1ByteRegister( Slave address + (start address >> 8),(start_address & 0xFF),0x01);
while (1)
{
sec=I2C1_Read1ByteRegister(0XA1+(start address >> 8),0x00);
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
}
}
}
You'll know if you review the MCC generate code. Analyzing the logic analyzer output will also show you how MCC is interpreting the address value.Yes few people recommend to use 0x50 and 0x53 . But I don't know how they got these value. Because data sheet says 0xA0 and 0xA1
Sorry, don't understand what you mean, what is rapidly in this context? Please show logic analyzer recording.but when device has to send acknowledge device sending me not acknowledge rapidly
void main(void)
{
// Initialize the device
SYSTEM_Initialize();
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
I2C1_Initialize();
I2C1_Write1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF),0x35);
I2C1_Write1ByteRegister(0X51+(StartAddr>>8),(StartAddr&0XFF),0x10);
while (1)
{
sec=I2C1_Read1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF));
min=I2C1_Read1ByteRegister(0X51+(StartAddr>>8),(StartAddr&0XFF));
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
}
}
}
unsigned int i=0;
unsigned int k=0;
unsigned int count;
unsigned int x;
#define LED RC7
#define StartAddr 0X00
#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;
I2C1_Initialize();
I2C1_Write1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF),0x35);
while (1) {
sec=I2C1_Read1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF));
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
}
}
}
void main(void) {
// Initialize the device
SYSTEM_Initialize();
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
I2C1_Initialize();
//I2C1_Read2ByteRegister(0XA0,0x02);
I2C1_Write1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF),0x35);
I2C1_Write1ByteRegister(0X50+((StartAddr+1)>>8),((StartAddr+1)&0XFF),0x02);
while (1)
{
sec=I2C1_Read1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF));
min=I2C1_Read1ByteRegister(0X50+((StartAddr+1)>>8),(StartAddr+1)&0XFF);
//min=I2C1_Read1ByteRegister(0X51+(StartAddr>>8),(StartAddr&0XFF));
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
}
}
}
EEPROM can, but you need to observe the datasheet requirements.My question is if RTC device could take response why cant EEPROM. where i am writing RTC date and time one after the other and read also doing same time.
#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
#define Seg7 0x40
#define Seg8 0x80
#define StartAddr 0X00
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) {
PORTA = Seg5;
}
if(segno==6) {
PORTA = Seg6;
}
if(segno==7) {
PORTA = Seg7; //DP2 Second Segment
}
if(segno==8) {
PORTA = Seg8;
}
}
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>=1) {
LED=!LED;
Flag_Update=1;
count=0;
}
}
}
unsigned int MIN;
unsigned int SEC;
void main(void) {
// Initialize the device
SYSTEM_Initialize();
INTCONbits.GIE=1;
INTCONbits.PEIE=1;
I2C1_Initialize();
I2C1_Write1ByteRegister(0X51,0x02,0x58);// Second
I2C1_Write1ByteRegister(0X51,0x03,0x58);// minute
I2C1_Write1ByteRegister(0X51,0x04,0x01);// hour
I2C1_Write1ByteRegister(0X51,0x05,0x01);
I2C1_Write1ByteRegister(0X51,0x06,0x02);
I2C1_Write1ByteRegister(0X51,0x07,0x03);
I2C1_Write1ByteRegister(0X51,0x08,0x10);
I2C1_Write1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF),0x35);
I2C1_Write1ByteRegister(0X50+((StartAddr+1)>>8),((StartAddr+1)&0XFF),0x02);
while (1)
{
sec=I2C1_Read1ByteRegister(0X51,0x02);
min=I2C1_Read1ByteRegister(0X51,0x03);
MIN=I2C1_Read1ByteRegister(0X50+(StartAddr>>8),(StartAddr&0XFF));
I2C1_MasterSendAck();
SEC=I2C1_Read1ByteRegister(0X50+((StartAddr+1)>>8),(StartAddr+1)&0XFF);
SetSeg(min >> 4,4);
__delay_ms(2);
SetSeg(min & 0x0f,3);
__delay_ms(2);
SetSeg(sec >> 4,2);
__delay_ms(2);
SetSeg(sec & 0x0f,1);
__delay_ms(2);
Flag_Update = 0; //ready for next update
SetSeg(MIN >> 4,6);
__delay_ms(2);
SetSeg(MIN & 0x0f,5);
__delay_ms(2);
SetSeg(SEC>> 4,8);
__delay_ms(2);
SetSeg(SEC & 0x0f,7);
__delay_ms(2);
Flag_Update = 0; //ready for next update
}
}
But there is no NXP8563, thus I assume PCF8563, which has 0xA2/0xA3 as device address.i am not using DS3231 , iam using NXP 8563 RTC device
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?