|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機 | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
請教高手看看我的程序 |
| 作者:doherty 欄目:單片機 |
說明,這是一個簡單的i2c接口24LC01的程序 但是在icd上運行時,沒有反映,大家?guī)兔纯窗?br>源程序如下: list p=16F877 #include <p16F877.inc> ; DATA_W EQU 75h ;the Write reg DATA_R EQU 76h ;the Read reg DL1 EQU 77h ;delay parameter reg DL2 EQU 78h ;delay parameter reg SCL EQU 3 ;I2C clock LINE SDA EQU 4 ;I2C data LINE ADDRESS EQU 0 ;the SEEPROM address you want to write in VALUE EQU 55h ;the TEST VALUE you want to write ; ; org 000h nop clrf PCLATH call Init_I2C clrf DATA_R movlw VALUE movwf DATA_W ;load the VALUE which to be send to the SEEPROM call Write ;Write the SEEPROM call Delay10ms ;wait for the SEEPROM to compelte the update call Read ;Read-back the VALUE which has just send movf DATA_R,W movwf PORTD ;DISPLAY the Read-back VALUE Here goto Here ;loop ; ;*****************************************************************************************************8 Write call I2C_Idle ;check if the bus is free banksel SSPCON2 bsf SSPCON2,SEN ;generate a start signal banksel PIR1 btfss PIR1,SSPIF goto $-1 ;wait for the start signal to be generate bcf PIR1,SSPIF ;clear the SSPIF flag movlw b'10100000' banksel SSPBUF movwf SSPBUF ;send the DEVICE Address information banksel PIR1 btfss PIR1,SSPIF goto $-1 ;wait for the address to be send bcf PIR1,SSPIF ;clear the SSPIF flag movlw ADDRESS banksel SSPBUF movwf SSPBUF ;send the Write Address information banksel PIR1 btfss PIR1,SSPIF goto $-1 ;wait for the Write Address to be send bcf PIR1,SSPIF ;clear the SSPIF flag movf DATA_W,W banksel SSPBUF movwf SSPBUF ;send the VALUE to be send to the SEEPROM banksel PIR1 btfss PIR1,SSPIF goto $-1 ;wait for the VALUE to be send bcf PIR1,SSPIF ;clear the SSPIF flag banksel SSPCON2 bsf SSPCON2,PEN ;generate the stop signal banksel PIR1 btfss PIR1,SSPIF goto $-1 ;wait for the stop signal to be setup bcf PIR1,SSPIF ;clear the SSPIF flag return ; Read call I2C_Idle banksel SSPCON2 bsf &n |
| 2樓: | >>參與討論 |
| 作者: 羽翔 于 2003/6/5 10:38:00 發(fā)布:
你的$-1子程序在哪。 程序沒全吧? |
|
| 3樓: | >>參與討論 |
| 作者: 黃果樹 于 2003/6/5 20:06:00 發(fā)布:
re to 羽翔 $-1 當(dāng)前地址減一 to doherty 看程序太累.你到MICROCHIP的網(wǎng)站去找例子吧 |
|
| 4樓: | >>參與討論 |
| 作者: wesleyyan 于 2003/6/5 20:21:00 發(fā)布:
去看APPLICATION NOTE 看人家的程序?qū)嵲谑抢,我同意黃果樹的建議, PIC的APPLICATION NOTE我覺得是做的最好的! 去看就會有收獲:) |
|
|
|
| 免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號 |