资源描述:
《利用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;===================================
2、=========MAINCLRFGPIOMOVLW20HTRISGPIOMOVLW05HOPTION;TIMER064分频,内部弱上拉CLRFGPIOCLRFSTATUSCLRFKTMCLRFKMCLRFKEYDQCLRFKOCALLINIT_IIC;----------------------------------------------READONEBIT;读一个字节MOVLW20HTRISGPIOCALLSTARTMOVLW0A0HCALLWRITE_IICMOVLW00HCALLWRITE_IICCALLSTARTMOVLW0A1HCA
3、LLWRITE_IICCALLREAD_IICMOVLW04HSUBWFMODE,0BTFSCSTATUS,CCLRFMODEGOTOMLOOP;-----------------------------------------------------------------MLOOPCLRFTMR0INCFKTM,1TABLE_MODEMOVFMODE,0ADDWFPCL,1GOTOMODE0GOTOMODE1GOTOMODE2GOTOMODE3MODE0BCFLED2BCFLED4GOTOMLDSMODE1BSFLED2BCFLED4GOTOM
4、LDSMODE2BCFLED2BSFLED4GOTOMLDSMODE3BSFLED2BSFLED4GOTOMLDS;--------------/////////////////////////////////以下按键检测MLDSBTFSCKEYGOTOTAIQIGOTOANXIATAIQIINCFKM,1CLRFKOMOVLW04HSUBWFKM,0BTFSSSTATUS,CGOTOMLDTSBSFKEYDQ,1CLRFKMGOTOMODE_TESTANXIAINCFKO,1CLRFKMMODE_TESTBTFSSKEYDQ,1GOTOMLDTS
5、MOVLW0AHSUBWFKO,0;kO是否大于10,按下消抖时间是否达到50MSBTFSSSTATUS,CGOTOMLDTSINCFMODE,1CLRFKTMMOVLW04HSUBWFMODE,0BTFSCSTATUS,CCLRFMODEWT;写一个字节CALLSTARTMOVLW0A0HCALLWRITE_IICMOVLW00HCALLWRITE_IICMOVFMODE,0CALLWRITE_IICCALLSTOPCLRFKOBCFKEYDQ,1;防止一直按下,键值发生变化。按键一次清一次键值。GOTOMLDTSMLDTSMOVLW4EH;一周
6、时间为5MSSUBWFTMR0,0BTFSSSTATUS,CGOTO$-3BCFSTATUS,5GOTOMLOOP;======================================================================================================;---------------------------IIc子程序------------------------------------------DELAYMOVLW06HMOVWFTDECFSZT,1GOTO$-1RETURN
7、;---------------------------------INIT_IICBSFSCLCALLDELAYBSFSDACALLDELAYRETURN;---------------------------------STARTBSFSDACALLDELAYBSFSCLCALLDELAYBCFSDACALLDELAYBCFSCLCALLDELAYRETURN;---------------------------------STOPBCFSDACALLDELAYBSFSCLCALLDELAYBSFSDARETURN;-------------
8、--------------------WRITE_IICMOVWFIIC_TEMPMOVLW08HMOVWFIIC_CT