下面部分从TXT拷出,拷到网页,代码部分缺省了很多空格,比较凌乱,请谅解!
I2C(SMBus)详细程序请查看C8051F I2C(SMBus)程序。
//目标系统: 基于C8051F单片机
//应用软件: Silicon IDE / Keil
/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
实验内容:
使用PCF8574的输出端口接上8位LED指示灯查看CPU输出到PCF8574的数据是否正常
----------------------------------------------------------------------
硬件连接:
将PCF8574的P0~P7口和8位LED指示灯相连。
DVK501(PCF8574PrlPort) F320 EX
VCC --------- VCC
GND --------- GND
SDA --------- P1.0
SCL --------- P1.1
----------------------------------------------------------------------
注意事项:
(1)若有加载库程序,请将光盘根目录下的“library”下的“C8051F”文件夹拷到D盘
(2)请详细阅读:光盘根目录下的“说明书首页.htm”里的相应产品说明
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
#define _DVK501_F320_EX_
#include <c8051f320.h>
#include <../../../../library/C8051F/ws_clock.h>
#include <../../../../library/C8051F/ws_delay.h>
#include <../../../../library/C8051F/ws_iic_port.h>
#include <../../../../library/C8051F/ws_pcf8574.h>
void main(void)
{
uchar wRdat; // Test counter
//uchar *rDdat;
PCA0MD &= ~0x40; // Clear watchdog timer enable
clock_external(); // Set oscillator in external,the clock is 12M
delay_ms(100);
Check_SDA();
XBR1 = 0x40; // Enable crossbar and weak pull-ups
SMBus_Init();
Enb_Interrupt();
wRdat = 0; // Output data counter
while (1)
{
/*Read_PCF8574(rDdat); // Read data
P2 = rDdat;*/
Write_PCF8574(wRdat); // Write data
wRdat++;
delay_ms (500);
}
}
void Write_PCF8574(uchar Data)
{
SMBus_Write(0x40,Data,0,1);
}
void Read_PCF8574(uchar *Data)
{
SMBus_Read(0x41,Data,1);
}