模拟IIC的方式 PIC16F887 XCV1.41
#define SCL_H TRISC0 = 0, RC0 = 1 /* SCL管脚置高 IIC两个通信端口 */
#define SCL_L TRISC0 = 0, RC0 = 0 /* SCL管脚置低 */
#define SDA_H TRISC1 = 0, RC1 = 1 /* SDA管脚置高 */
#define SDA_L TRISC1 = 0, RC1 = 0 /* SDA管脚置低 */
#define SDA_IN TRISC1 = 1 /* SDA输入模式 */
#define SDA_OUT TRISC1 = 0 /* SDA输出模式 */
#define SDA_VAL RC1 /* SDA的位值读取 */
#define TRUE 1
#define FALSE 0
#define PCF8591Address 0x90 /*PCF8591的设备地址*/
#define PCF8591Control 0x40 /* AD转换 开启 */
void start( void )
{
SCL_H;
SDA_H;
NOP();
SDA_L;
NOP();
SCL_L;
NOP();
}
void stop( void )
{
SDA_L;
NOP();
SCL_H;
NOP();
SDA_H;
NOP();
}
|