赞
踩
代码片
.
#include"reg52.h" sbit sda = P0^0; typedef unsigned char u8, uint8; void Delay1us (int T) { T = T - 70; do { ; } while ( T-- ); } void SendData ( u8 addr ) { u8 i; EA = 0;/*发送时关掉中断,防止中断影响时序 */ sda = 1;/*开始拉搞 */ Delay1us ( 2000 ); sda = 0;/*开始引导码*/ Delay1us ( 3200 );/*此处延时最少要大于2ms,此参数延时为310ms */ for ( i = 0; i < 8; i++ ) /*总共8位数据 */ { sda = 1; if ( addr & 0x01 ) /*3:1表示数据位1,每个位用两个脉冲表示 */ { Delay1us ( 600 ); sda = 0; Delay1us ( 200 ); } else /*1:3表示数据位0 ,每个位用两个脉冲表示 */ { Delay1us ( 200 ); sda = 0; Delay1us ( 600 ); } addr >>= 1; } sda = 1; EA = 1; } int main() { SendData(0x0a); SendData(0x02); SendData(0x0b); while(1) { } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。