Toll-Free Customer Support 24/7

PIC Development Board -RTC

// Software I2C connections

sbit Soft_I2C_Scl at RC4_bit;

sbit Soft_I2C_Sda at RC3_bit;

sbit Soft_I2C_Scl_Direction at TRISC4_bit;

sbit Soft_I2C_Sda_Direction at TRISC3_bit;

// End Software I2C connections

// LCD module connections

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D4 at RB4_bit;

sbit LCD_D5 at RB5_bit;

sbit LCD_D6 at RB6_bit;

sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB4_bit;

sbit LCD_D5_Direction at TRISB5_bit;

sbit LCD_D6_Direction at TRISB6_bit;

sbit LCD_D7_Direction at TRISB7_bit;

// End LCD module connections

void delay()

{

unsigned char z;

for(z=250;z>0;z--)

;

}

void rtc_init()

{

unsigned char a[]={0x00,0x00,0x01,0x05,0x02,0x17,0x03,0x05,0x04,0x30,0x05,0x03,0x06,0x22};

unsigned char x=0;

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[0]);

Soft_I2C_Write(a[1]);

Soft_I2C_Stop();

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[2]);

Soft_I2C_Write(a[3]);

Soft_I2C_Stop();

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[4]);

Soft_I2C_Write(a[5]);

Soft_I2C_Stop();

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[8]);

Soft_I2C_Write(a[9]);

Soft_I2C_Stop();

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[10]);

Soft_I2C_Write(a[11]);

Soft_I2C_Stop();

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(a[12]);

Soft_I2C_Write(a[13]);

Soft_I2C_Stop();

}

void display(unsigned char a1)

{

unsigned char b1;

b1=(a1 & 0x0f0);

b1=(b1>>4)+0x30;

Lcd_Chr_Cp(b1);

b1=(a1 & 0x0f);

b1=b1+0x30;

Lcd_Chr_Cp(b1);

}

void main()

{

unsigned char i,temp,ch,hr,min,STORE_VAL=0,FLAG1=0,FLAG2=0;

unsigned int LDR_VAL1,LDR_VAL2,LDR_VAL3;

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF);

delay();

delay();

Soft_I2C_Init();

delay();

rtc_init();

while(1)

{

Lcd_Out(1, 1, "TIME ");

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

delay();

Soft_I2C_Write(2);

Delay_100ms();

Soft_I2C_Start();

// Soft_I2C_Write(0xD0);

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

Soft_I2C_Stop();

hr=ch;

display(ch);

delay();

delay();

delay();

Lcd_Chr_Cp(':');

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(1);

Delay_100ms();

Soft_I2C_Start();

//I2C1_Repeated_Start();

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

min=ch;

delay();

Soft_I2C_Stop();

delay();

display(ch);

delay();

delay();

delay();

Lcd_Chr_Cp(':');

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(0);

Delay_100ms();

Soft_I2C_Start();

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

Soft_I2C_Stop();

display(ch);

delay();

delay();

if(hr==0x12||hr==0x01||hr==0x02||hr==0x03||hr==0x04||hr==0x05||hr==0x06)

{

Lcd_Chr_Cp(' ');

Lcd_Chr_Cp('A');

Lcd_Chr_Cp('M');

}

else

{

Lcd_Chr_Cp(' ');

Lcd_Chr_Cp('P');

Lcd_Chr_Cp('M');

}

i=0;

Lcd_Out(2, 1, "DATE ");

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(4);

Delay_100ms();

Soft_I2C_Start();

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

delay();

Soft_I2C_Stop();

display(ch);

delay();

delay();

Lcd_Chr_Cp('-');

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(5);

Delay_100ms();

Soft_I2C_Start();

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

delay();

Soft_I2C_Stop();

display(ch);

delay();

delay();

Lcd_Chr_Cp('-');

Soft_I2C_Start();

Soft_I2C_Write(0xD0);

Soft_I2C_Write(6);

Delay_100ms();

Soft_I2C_Start();

Soft_I2C_Write(0xD1);

ch=Soft_I2C_Read(0u);

Soft_I2C_Stop();

display(ch);

delay();

delay();

}

}

Back to top