реклама на сайте
подробности

 
 
 
Reply to this topicStart new topic
> PIC24FJ256GB106 + DS1621
vangraf
сообщение Oct 19 2009, 20:09
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 17
Регистрация: 2-03-08
Пользователь №: 35 569



Люди добрые помогите запустить PIC24FJ256GB106 + DS1621
Датчики температуры подключены к I2C2 резисторы по 10кОм.
код прилагается:

void InitI2C(void){
I2C2CON = 0;
I2C2BRG = I2C_BRG;

_TRISF4 = 1;
Nop();
_TRISF5 = 1;
Nop()

I2C2STAT = 0x0000;
I2C2CON = 0x1200;
I2C2RCV = 0x0000;
I2C2TRN = 0x0000;
I2C2CON = 0x9200;
IdleI2C();
}
void StartI2C(void){
I2C2CONbits.SEN = 1;
while (I2C2CONbits.SEN);
}
void RestartI2C2(void)
{
I2C2CONbits.RSEN = 1;
while (I2C2CONbits.RSEN);
}
void StopI2C(void)
{
I2C2CONbits.PEN = 1;
while (I2C2CONbits.PEN);
}
unsigned char ACKStatus(void)
{
return (!I2C2STATbits.ACKSTAT);
}
void AckI2C(unsigned char ack){
I2C2CONbits.ACKDT = !ack;
I2C2CONbits.ACKEN = 1;
while(I2C2CONbits.ACKEN);
I2C2CONbits.ACKDT = 0;
}
void WrI2C(unsigned char byte)
{
I2C2TRN = byte;
while (I2C2STATbits.TBF);
IdleI2C();
}
unsigned char RdI2C(unsigned char ack)
{
I2C2CONbits.RCEN = 1;
while(I2C2CONbits.RCEN);
AckI2C(ack);
return I2C2RCV;
}
//-----------------------------------------------------------------------------
// For DS1621 -----------------------------------------------------------------
void dsConfig( BYTE address, BYTE data )
{
WrI2C( DS_ADDRESS | ( address << 1 ) | 0);
WrI2C( ACCESS_CONFIG );
WrI2C( data );
StopI2C();
}
//-[ end of dsConfig ]---------------------------------------------------------
void dsInit(BYTE address)
{
StartI2C(); //Send the Start Bit
WrI2C( DS_ADDRESS | ( address << 1 ) | 0);
WrI2C( START_CONVERT_T );
dsConfig( address, 8 );
}
//-[ end of dsInit ]-----------------------------------------------------------
char dsRead( BYTE address )
{

WORD_VAL data;
char temperature;

StartI2C(); //Send the Start Bit
WrI2C( DS_ADDRESS | ( address << 1 ) | 0);
WrI2C( READ_TEMPERATURE );
RestartI2C2(); //Send the Restart condition
i2c_wait(10);
WrI2C( DS_ADDRESS | ( address << 1 ) | 1);

data.byte.HB = RdI2C(1); /* save byte received */
data.byte.LB = RdI2C(0); /* save byte received */

StopI2C();

temperature = data.byte.HB;
temperature <<= 1;
temperature |= data.bits.b7;
return ( temperature );
}
//-[ end of dsRead ]-----------------------------------------------------------
Go to the top of the page
 
+Quote Post
vangraf
сообщение Oct 27 2009, 18:11
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 17
Регистрация: 2-03-08
Пользователь №: 35 569



Тема закрыта. Разобрался)
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 2nd July 2025 - 20:40
Рейтинг@Mail.ru


Страница сгенерированна за 0.60496 секунд с 7
ELECTRONIX ©2004-2016