怎么样用stm32单片机做iic从机
2016-07-14
可以看吴鉴鹰单片机开发板教程的
#include<reg52.h>
sbit HC595_sck = P0^5;
sbit HC595_rck = P0^6;
sbit HC595_data = P0^7;
code unsigned char Data_One_Array[2] = {0x01,0x00};
code unsigned char Data_Two_Array[2] = {0x00,0x00};
void Send_Data(unsigned char Data_One,unsigned char Data_Two)
{
unsigned char i;
HC595_rck = 0;
for(i=0; i < 8;i ++)
{
HC595_sck = 0;
if(0 == (Data_One & 0x80))
{
HC595_data = 0;
}
else
{
HC595_data = 1;
}
Data_One = Data_One << 1;
HC595_sck = 1;
}
for(i=0;i < 8;i ++)
{
HC595_sck = 0;
if(0 == (Data_Two & 0x80))
{
HC595_data = 0;
}
else
{
HC595_data = 1;
}
Data_Two = Data_Two << 1;
HC595_sck = 1;
}
HC595_rck = 1;
}
void main()
{
while(1)
{
Send_Data(Data_One_Array[0],Data_Two_Array[0]);
}
}