一些整理
IIC
1. PCF8591
1.1 通道一:光敏电阻
//Light_read(0X01) uchar Light_read(uchar add) { uchar temp; IIC_Start(); IIC_SendByte(0X90); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Stop(); IIC_Start(); IIC_SendByte(0X91); IIC_WaitAck(); temp = IIC_RecByte(); IIC_Stop(); return temp; }
1.2 通道三:A/D转换(Rb2)
//Light_read(0X03) uchar AD_read(uchar add) { uchar temp; IIC_Start(); IIC_SendByte(0X90); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Stop(); IIC_Start(); IIC_SendByte(0X91); IIC_WaitAck(); temp = IIC_RecByte(); IIC_Stop(); return temp; }
2. AT24C02
EEPROM(寄存器)
/* EEPROM_write(0X01, 126); delayms(5) //延时5ms EEPROM_read(0X01) */ //读取 uchar EEPROM_read(uchar add) { uchar temp; IIC_Start(); IIC_SendByte(0XA0); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_Stop(); IIC_Start(); IIC_SendByte(0XA1); IIC_WaitAck(); temp = IIC_RecByte(); IIC_Stop(); return temp; } //写入 void EEPROM_write(uchar add, uchar dat) { unsigned char temp; IIC_Start(); IIC_SendByte(0XA0); IIC_WaitAck(); IIC_SendByte(add); IIC_WaitAck(); IIC_SendByte(dat); IIC_WaitAck(); IIC_Stop(); }
DS1302(时钟)
//Init_DS1302()就是初始化 //uchar shijian[] = {0, 30, 8, 0, 0, 0, 0}; //Read_DS1302()while里写 void Init_DS1302() { uchar i, add; add = 0X80; //写 Write_Ds1302(0X8e, 0X00); for(i = 0; i < 7; i++) { Write_Ds1302(add, shijian[i]); add = add + 2; } Write_Ds1302(0X8e, 0X80); } void Read_DS1302() { uchar i, add; add = 0X81; //读 Write_Ds1302(0X8e, 0X00); for(i = 0; i < 7; i++) { shijian[i] = Read_Ds1302(add); add = add + 2; } Write_Ds1302(0X8e, 0X80); }
onewire
以后更新
杂记
1.蜂鸣器和继电器的P0对应 (蜂鸣器:0X40,继电器:0X10,全关0X00)
2.数码管的对应图
3.NE555是Rb3,短接SIGNAL和P34
4.通道一(0X01)和通道三(0X03)是写入决定的
5.DS1302的驱动,不用翻8-12倍