资源描述:
《利用pic单片机io口模拟iic协议小程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#INCLUDE__CONFIG_OSC_IntRC&_WDT_OFF&_MCLRE_OFF&_CP_ON#DEFINELED2GPIO,2#DEFINELED4GPIO,4#DEFINEKEYGPIO,5#DEFINESCLGPIO,1#DEFINESDAGPIO,0KTMEQU08HKMEQU0AHMODEEQU0BHKOEQU0CHKEYDQEQU0DHIIC_TEMPEQU0EHIIC_CEQU0FHTEQU10HORG000HGOTOMAIN;============================================MAINCLRFGPIOM
2、OVLW20HTRISGPIOMOVLW05HOPTION;TIMER064分频,内部弱上拉CLRFGPIOCLRFSTATUSCLRFKTMCLRFKMCLRFKEYDQCLRFKOCALLINIT_IIC;----------------------------------------------READONEBIT;读一个字节MOVLW20HTRISGPIOCALLSTARTMOVLW0A0HCALLWRITE_IICMOVLW00HCALLWRITE_IICCALLSTARTMOVLW0A1HCALLWRITE_IICCALLREAD_IICMOVLW04HSUBWFMODE,0BT
3、FSCSTATUS,CCLRFMODEGOTOMLOOP;-----------------------------------------------------------------MLOOPCLRFTMR0INCFKTM,1TABLE_MODEMOVFMODE,0ADDWFPCL,1GOTOMODE0GOTOMODE1GOTOMODE2GOTOMODE3MODE0BCFLED2BCFLED4GOTOMLDSMODE1BSFLED2BCFLED4GOTOMLDSMODE2BCFLED2BSFLED4GOTOMLDSMODE3BSFLED2BSFLED4GOTOMLDS;--------
4、------/////////////////////////////////以下按键检测MLDSBTFSCKEYGOTOTAIQIGOTOANXIATAIQIINCFKM,1CLRFKOMOVLW04HSUBWFKM,0BTFSSSTATUS,CGOTOMLDTSBSFKEYDQ,1CLRFKMGOTOMODE_TESTANXIAINCFKO,1CLRFKMMODE_TESTBTFSSKEYDQ,1GOTOMLDTSMOVLW0AHSUBWFKO,0;kO是否大于10,按下消抖时间是否达到50MSBTFSSSTATUS,CGOTOMLDTSINCFMODE,1CLRFKTMMOVLW04H
5、SUBWFMODE,0BTFSCSTATUS,CCLRFMODEWT;写一个字节CALLSTARTMOVLW0A0HCALLWRITE_IICMOVLW00HCALLWRITE_IICMOVFMODE,0CALLWRITE_IICCALLSTOPCLRFKOBCFKEYDQ,1;防止一直按下,键值发生变化。按键一次清一次键值。GOTOMLDTSMLDTSMOVLW4EH;一周时间为5MSSUBWFTMR0,0BTFSSSTATUS,CGOTO$-3BCFSTATUS,5GOTOMLOOP;====================================================
6、==================================================;---------------------------IIc子程序------------------------------------------DELAYMOVLW06HMOVWFTDECFSZT,1GOTO$-1RETURN;---------------------------------INIT_IICBSFSCLCALLDELAYBSFSDACALLDELAYRETURN;---------------------------------STARTBSFSDACALLDELAY
7、BSFSCLCALLDELAYBCFSDACALLDELAYBCFSCLCALLDELAYRETURN;---------------------------------STOPBCFSDACALLDELAYBSFSCLCALLDELAYBSFSDARETURN;---------------------------------WRITE_IICMOVWFIIC_TEMPMOVLW08HMOVWFIIC_CT