• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users




« 1 (2)


Re: 想請問I2C應用範例
#4
新會員
新會員


查看用戶資訊
真是太厲害了....
小妹我看到程式真是嚇到
感激不盡阿....

對了!!請問這是c16還是c18的程式??

目前我這邊有18F452的現成晶片可以用
可以直接用ㄇ

發表於: 2005/8/4 17:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 想請問I2C應用範例
#3
高級會員
高級會員


查看用戶資訊
void IIC_INIT(void)
{
output_high(P_SDA);
output_high(P_SCL);
}
void IIC_WAIT(void)
{
delay_us(10);
}

void IIC_START(void)
{
output_high(P_SDA); //P_SDA = 1;
output_high(P_SCL); //P_SCL = 1;
IIC_WAIT();
output_low(P_SDA); //P_SDA = 0;
IIC_WAIT();
output_low(P_SCL); //P_SCL = 0;

}
//***** VERSION : 1.0 *****
// /------------
// SCL -----/
//
// /----------
// SDA-------/
//
// SCL先拉HI SDA 再跟著拉HI
//
//***********************************

void IIC_STOP(void)
{
output_low(P_SDA); //P_SDA = 0;
IIC_WAIT();
output_high(P_SCL); //P_SCL = 1;
IIC_WAIT();
output_high(P_SDA); //P_SDA = 1;
}
int8 IIC_SEND_BYTE(int8 databyte)
{
int8 i;
int8 ack;
for(i = 0;i<8;i++)
{
if ( databyte & 0x80)
output_high(P_SDA);
else
output_low(P_SDA);
databyte <<=1;
// IIC_WAIT();
output_high(P_SCL);
IIC_WAIT();
output_low(P_SCL);
// IIC_WAIT();

}
//in 8051 mcu is setting input mode output_high(P_SDA);
input(P_SDA);
IIC_WAIT();
output_high(P_SCL);
IIC_WAIT();
IIC_WAIT();
IIC_WAIT();
ack = input(P_SDA);
output_low(P_SCL);
IIC_WAIT();


return ack;
}
int8 IIC_RECEIVE_BYTE(void)
{
int8 i;
int8 databyte =0;
input(P_SDA);
for (i=0;i<8;i++)
{
output_high(P_SCL);
IIC_WAIT();
databyte <<=1;
if (input(P_SDA)) databyte |= 0x01;
output_low(P_SCL);
IIC_WAIT();

}
return databyte;
}

void SEND_ACK(int8 ack)
{
if (ack==0x01)
output_high(P_SDA);
else
output_low(P_SDA);
output_high(P_SCL);
IIC_WAIT();
output_low(P_SCL);

}
void IIC_BYTEWRITE(int8 device,int8 address,int8 databyte1,int8 databyte2)
{
int8 i;
int8 ack;
for (i=0;i<10;i++)
{
IIC_START();
ack = IIC_SEND_BYTE(device);
if (ack==1)
{
IIC_STOP();
continue;
}
ack = IIC_SEND_BYTE(address);
if (ack==1)
{
IIC_STOP();
continue;
}
ack = IIC_SEND_BYTE(databyte1);
if (ack==1)
{
IIC_STOP();
continue;
}
ack = IIC_SEND_BYTE(databyte2);
if (ack==1)
{
IIC_STOP();
continue;
}

IIC_STOP();
if (ack==0) break;

}
delay_us(2);
}
void IIC_READ_IOPORT(int8 device,int8 command)
{
int8 i;
int8 ack;
// F_SENDTIMEOUT = 1;
for (i=0;i<10;i++)
{
IIC_START();
ack = IIC_SEND_BYTE(device);
if (ack==1)
{
IIC_STOP();
continue;
}
ack = IIC_SEND_BYTE(command);
if (ack==1)
{
IIC_STOP();
continue;
}
IIC_STOP();
if (ack==0) break;

}

delay_us(2);
PORTDATA = IIC_RECEIVE_BYTE();

}
void READ_IO(int8 address,int8 command,int8 address1)
{
int8 i;
int8 ack;
/*
i2c_start(); // Generate START condition
i2c_write(AddressW); // Transmit ADDRESS with WRITE command
i2c_write(Command); // Transmit COMMAND byte
i2c_repStart(); // Generate a REPEATED-START condition
i2c_write(AddressR); // Transmit ADDRESS with READ command
MCP_LSB=i2c_read(1); // Receive first DATA byte (LSB) and acknowledge
MCP_MSB=i2c_read(0); // Receive second DATA byte (MSB) and don't acknowledge
i2c_stop(); // Generate a STOP condition
*/
// F_SENDTIMEOUT = 1;
for (i=0;i<10;i++)
{
IIC_START();
ack = IIC_SEND_BYTE(address);
if (ack==1)
{
IIC_STOP();
continue;
}
ack = IIC_SEND_BYTE(command);
if (ack==1)
{
IIC_STOP();
continue;
}
if (ack==0) break;
}
delay_us(14);
for (i=0;i<10;i++)
{
IIC_START();
ack = IIC_SEND_BYTE(address1);
if (ack==1)
{
IIC_STOP();
continue;
}
if (ack==0) break;

}
BUFFER1 = IIC_RECEIVE_BYTE();
delay_us(20);
input(P_SDA);
IIC_WAIT();
output_high(P_SCL);
IIC_WAIT();
IIC_WAIT();
IIC_WAIT();
if (input(P_SDA))
{
IIC_STOP();
}
output_low(P_SCL);
IIC_WAIT();
BUFFER2 = IIC_RECEIVE_BYTE();
input(P_SDA);
IIC_WAIT();
output_high(P_SCL);
IIC_WAIT();
IIC_WAIT();
IIC_WAIT();
if (input(P_SDA))
{
IIC_STOP();
}
output_low(P_SCL);
IIC_WAIT();

IIC_STOP();
}

void main() {
delay_ms(100);
EXPANDER_IO_INITIAL();

while (TRUE)
{
if (!input(P_INTERRUPT))
{
debug_pin();
READ_IO(WRITECOMMAND_TO_IC,ACCES_GP1,READCOMMAND_FROM_IC);

while(!input(P_INTERRUPT));
}else
{
IIC_BYTEWRITE(WRITECOMMAND_TO_IC,ACCES_OLAT0,0X7F,0xff); //寫初始直
delay_ms(250);
IIC_BYTEWRITE(WRITECOMMAND_TO_IC,ACCES_OLAT0,0XBF,0xff); //寫初始直
delay_ms(250);
}

}
}


發表於: 2005/8/4 15:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 想請問I2C應用範例
#2
新會員
新會員


查看用戶資訊
不好意思補充一下我的問題
我有APPOO1工作版以及ICD2

我是想用PIC當master做I2C串列通訊格式
發出及接收SDA以及SCL的命令
目前看到16F873有I2C的功能
請問18F系列有出I2C功能的晶片嗎

還有是否有可能拿到C18或C16的I2C控制範例程式

還有 請問24LCXX與25LCXX,,93c86
這些東西是用I2C格式做溝通的外接記憶體ㄇ
因為我是新手
看不太懂
希望可以得到解答
感激不盡阿

發表於: 2005/8/3 23:46
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


想請問I2C應用範例
#1
新會員
新會員


查看用戶資訊
我有在範例程式那邊看到I2C的應用範例
可是因為是組語寫成的
請問有可能拿到c code 控制I2C的範例程式ㄇ
還有那是針對哪一個晶片所寫的

有I2C電路介面的PIC晶片目前台灣買的到ㄇ


發表於: 2005/8/3 23:23
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------