char read_rtc(char addr)
{
//C7=swq,6=rclr_bar,5=irq_bar,4=reset_bar,3=ds,2=rw_bar,1=as,0=cs_bar
char data;
rtc_tris=0b11100000;//set the tris of C for setting address
rtc_tris.ad=0x00; //set the tris of D for setting address
rtc =0b00011110;//set C for for setting address
rtc.ad=addr; //put address on bus
#asm nop #endasm //pause
rtc.as=0; //latch
delay_cycles(1); // pause
rtc_tris.ad=0xFF; //set the tris of D for reading data
rtc.ds=0; //release
[B] #asm nop #endasm //pause
data=rtc.ad; //read the data from the bus[/B] [B][I]tDDR[/I][/B]
rtc_tris_r(); //set the tris of B and D to ALL INPUTS
return(data);
}