ALIARIF93
Junior Member level 1
- Joined
- Jun 24, 2012
- Messages
- 15
- Helped
- 0
- Reputation
- 4
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,421
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 void I2C_DATA_READ() { SSPCON1bits.SSPOV=0; I2C_IDLE(); SSPCON2bits.RCEN = 1; ///ENABLE RECIEVE MODE while(!SSPSTATbits.BF); //while recieve not complete //SSPCON2bits.RCEN = 0; ///DISABLE RECIEVE MODE PORTB =TEMP_READING;; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #include<p18f4520.h> #pragma config LVP = OFF #pragma config OSC = HS #include<i2c.h> #include<delays.h> void main() { while(1){ unsigned char LastTemp; DDRCbits.RC3 = 1; //Configure SCL //as Input DDRCbits.RC4 = 1; //Configure SDA //as Input SSPSTAT = 0x80; //Disable SMBus & //Slew Rate Control SSPCON1 = 0x28; //Enable MSSP Master SSPADD = 119; //Fosc = 48MHs HS+PLL //for 100kHz // SSPCON2 = 0x00; //Clear MSSP Conrol Bits IdleI2C(); // ensure module is idle StartI2C(); // initiate START condition while ( SSPCON2bits.SEN ); // wait until start condition is over Delay10TCYx(10); WriteI2C( 0b10011011 ); // write Address IdleI2C(); // ensure module is idle WriteI2C( 0 ); // Select Temperature Register IdleI2C(); // ensure module is idle RestartI2C(); // generate I2C bus restart condition while ( SSPCON2bits.RSEN ); // wait until re-start condition is over WriteI2C( 0b10011011); // WRITE Address IdleI2C(); // ensure module is idle ReadI2C(); // read in the temp NotAckI2C(); // send not ACK condition while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over StopI2C(); // send STOP condition while ( SSPCON2bits.PEN ); // wait until stop condition is over LastTemp = SSPBUF; // LastTemp is a Global unsigned char } }
DDRCbits.RC3 = 1; //Configure SCL
//as Input
DDRCbits.RC4 = 1; //Configure SDA
#include<p18f4520.h>
#pragma config LVP = OFF
#pragma config OSC = HS
#include<i2c.h>
#include<delays.h>
void main()
{
unsigned int LastTemp = 0;
TRISB = 0x00;
PORTB = 0x00;
SSPSTAT = 0x80; //Disable SMBus &
//Slew Rate Control
SSPCON1 = 0x28; //Enable MSSP Master
SSPADD = 119; //Fosc = 48MHs HS+PLL
//for 100kHz
// SSPCON2 = 0x00; //Clear MSSP Conrol Bits
while(1){
IdleI2C(); // ensure module is idle
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); // wait until start condition is over
Delay10TCYx(10);
WriteI2C( 0b10011010 ); // write Address
IdleI2C(); // ensure module is idle
WriteI2C( 0 ); // Select Temperature Register
IdleI2C(); // ensure module is idle
RestartI2C(); // generate I2C bus restart condition
while ( SSPCON2bits.RSEN ); // wait until re-start condition is over
WriteI2C( 0b10011011); // WRITE Address
IdleI2C(); // ensure module is idle
ReadI2C(); // read in the temp
NotAckI2C(); // send not ACK condition
while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN ); // wait until stop condition is over
LastTemp = SSPBUF; // LastTemp is a Global unsigned char
if(LastTemp != 0) {
PORTBbits.RB0 = 1;
}
}
}
#include<p18f4520.h>
#pragma config LVP = OFF
#pragma config OSC = HS
#include<i2c.h>
#include<delays.h>
void main()
{
unsigned int LastTemp = 0;
TRISB = 0x00;
PORTB = 0x00;
TRISD = 0x00;
PORTD = 0x00;
SSPSTAT = 0x80; //Disable SMBus &
//Slew Rate Control
SSPCON1 = 0x28; //Enable MSSP Master
SSPADD = 119; //Fosc = 48MHs HS+PLL
//for 100kHz
// SSPCON2 = 0x00; //Clear MSSP Conrol Bits
while(1){
IdleI2C(); // ensure module is idle
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); // wait until start condition is over
Delay10TCYx(10);
WriteI2C( 0b10011010 ); // write Address
IdleI2C(); // ensure module is idle
WriteI2C( 0 ); // Select Temperature Register
IdleI2C(); // ensure module is idle
RestartI2C(); // generate I2C bus restart condition
while ( SSPCON2bits.RSEN ); // wait until re-start condition is over
WriteI2C( 0b10011011); // WRITE Address
IdleI2C(); // ensure module is idle
ReadI2C(); // read in the temp
NotAckI2C(); // send not ACK condition
while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN ); // wait until stop condition is over
LastTemp = SSPBUF; // LastTemp is a Global unsigned char
if(LastTemp != 0) {
PORTBbits.RB0 = 1;
PORTD = LastTemp;
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 IdleI2C(); // ensure module is idle StartI2C(); // initiate START condition while ( SSPCON2bits.SEN ); // wait until start condition is over Delay10TCYx(10); WriteI2C( 0b10011010 ); // write Address IdleI2C(); // ensure module is idle WriteI2C( 0 ); // Select Temperature Register IdleI2C(); // ensure module is idle RestartI2C(); // generate I2C bus restart condition while ( SSPCON2bits.RSEN ); // wait until re-start condition is over WriteI2C( 0b10011011); // WRITE Address IdleI2C(); // ensure module is idle ReadI2C(); // read in the temp NotAckI2C(); // send not ACK condition while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over StopI2C(); // send STOP condition while ( SSPCON2bits.PEN ); // wait until stop condition is over LastTemp = SSPBUF; // LastTemp is a Global unsigned char if(LastTemp != 0) { PORTBbits.RB0 = 1; PORTD = LastTemp;
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?