jaya krishna
Member level 1
- Joined
- May 10, 2012
- Messages
- 41
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- India,coimbatore
- Activity points
- 1,770
i want to display the date and time to LCD....
i dont know to how to read and write I2C... the below program is executed...but output is not worked
pls somebody help me...or give some code based on pic18 compiler...
#include<p18f458.h>OR <P18F452.h>
unsigned char SPI(unsigned char mybyte);
void TRANS(unsigned char mychar);
void main()
{
int c;
SSPSTAT=0x00;
SSPCON1=0x22;
TRISC=0x00;
TRISCbits.TRISC4=1;
TRISCbits.TRISC7=1;
TXSTA=0x20;
SPBRG=15;
RCSTAbits.SPEN=1;
TRANS(0x0A);
TRANS(0X0D);
while(1)
{
PORTCbits.RC2=1; //start single byte write
SPI(0x8F);
SPI(0x00);
PORTCbits.RC2=0; // end single byte write
PORTCbits.RC2=1;
SPI(0x80);
c=SSPBUF;
SPI(0x55);
SPI(0x58);
SPI(0x16);
SPI(0x03);
SPI(0x19);
SPI(0x10);
SPI(0x05);
PORTCbits.RC2=0;
PORTC=c;
}
TRANS(0x0D);
}
unsigned char SPI(unsigned char mybyte)
{
SSPBUF=mybyte;
while(!SSPSTATbits.BF);
return SSPBUF;
}
void TRANS(unsigned char mychar)
{
while(!PIR1bits.TXIF);
TXREG=mychar;
}
thanks
jai
i dont know to how to read and write I2C... the below program is executed...but output is not worked
pls somebody help me...or give some code based on pic18 compiler...
#include<p18f458.h>OR <P18F452.h>
unsigned char SPI(unsigned char mybyte);
void TRANS(unsigned char mychar);
void main()
{
int c;
SSPSTAT=0x00;
SSPCON1=0x22;
TRISC=0x00;
TRISCbits.TRISC4=1;
TRISCbits.TRISC7=1;
TXSTA=0x20;
SPBRG=15;
RCSTAbits.SPEN=1;
TRANS(0x0A);
TRANS(0X0D);
while(1)
{
PORTCbits.RC2=1; //start single byte write
SPI(0x8F);
SPI(0x00);
PORTCbits.RC2=0; // end single byte write
PORTCbits.RC2=1;
SPI(0x80);
c=SSPBUF;
SPI(0x55);
SPI(0x58);
SPI(0x16);
SPI(0x03);
SPI(0x19);
SPI(0x10);
SPI(0x05);
PORTCbits.RC2=0;
PORTC=c;
}
TRANS(0x0D);
}
unsigned char SPI(unsigned char mybyte)
{
SSPBUF=mybyte;
while(!SSPSTATbits.BF);
return SSPBUF;
}
void TRANS(unsigned char mychar)
{
while(!PIR1bits.TXIF);
TXREG=mychar;
}
thanks
jai