• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 關於i2c
#11
中級會員
中級會員


查看用戶資訊
OpenLCD();
WriteCmdLCD(0x01);
LCD_Set_Cursor(0,0);
DelayUs(1);
putrsLCD("Welcome to PIC");
LCD_Set_Cursor(1,0);
DelayUs(1);
putrsLCD("Micro-Con");
LCD_Set_Cursor(0,0);
DelayUs(1);
putrsLCD(DQ);

Sleep();
while(1);
}

void DelayUs(long A){
int i,us2TCY;
us2TCY=(10*OSC_CLOCK)>>2;
for(i=0;i<A;i++) Delay100TCYx(us2TCY);
}

發表於: 2009/8/14 3:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#10
中級會員
中級會員


查看用戶資訊
這是我照說明操作寫的,Debugger正常,但是寫入IC卻無動作

請問是哪裡有出問題


#define OSC_CLOCK 10

void DelayUs(long A);

void Dir_DQ_L(void){
Dir_DQ=0;
}
void Dir_DQ_H(void){
Dir_DQ=0;
DelayUs(1);
Dir_DQ=1;
}

void DQ_W (void){
Dir_DQ=0x0C;
// Dir_DQ_L;
Dir_DQ_H;
DelayUs(120);
}

void main(){
int j;
Dir_DQ = 1;
DQ = 1;
DelayUs(1);
DQ = 0;
DelayUs(480);
do{
DQ = 1;
while(!DQ);
DelayUs(60);

DQ = 0;
DQ = 0;
DelayUs(240);
}while(DQ==1);
DelayUs(420);

DQ=0xAA;
for(j=0;j<8;j++){
int j;
Dir_DQ_L;
Dir_DQ_H;
DelayUs(120);
DQ=1;
}
for(j=0;j<8;j++){
DQ=0;
DelayUs(1);
DQ=1;
DelayUs(15);
DelayUs(120);
}

發表於: 2009/8/14 3:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#9
資深會員
資深會員


查看用戶資訊
整個的操作大概就是 

    call    bus_init

    movlw    0x07
    call    write_bus

    call    read_bus
    
    
......大概就是這樣

發表於: 2009/8/14 1:07
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#8
資深會員
資深會員


查看用戶資訊
;需要 3 byte ram
;    loop_timer
;    bus_data
;    bus_loop
;example    movlw    0x0c
        call    write_bus
write_bus
:
    
movwf    bus_data
    movlw    1
    movwf    bus_loop

    gotobank1
    bcf    wire_bus    
;output
    gotobank0
write_bus_loop
    btfss    bus_data
,7
    
goto    write_bus_0
    
write_bus_1
    bcf    wire_bus    
;pull low >1us
    
goto    $+.1        ;2us
    bsf    wire_bus    
;pull high 90us

    movlw    .30        
;90us
    movwf    loop_timer
    decfsz    loop_timer
,f
    
goto    $+.1
    
goto    write_bus_end

write_bus_0    
    bcf    wire_bus    
;pull low >1us
    
goto    $+.1        ;2us
    bcf    wire_bus    
;pull low 90us

    movlw    .30        
;90us
    movwf    loop_timer
    decfsz    loop_timer
,f
    
goto    $+.1
    
goto    write_bus_end

write_bus_end
    rlf    bus_data
,f
    rlf    bus_loop
,f    ;8bit 傳完
    skpc
    
goto    loop

    gotobank1
    bsf    wire_bus    
;input
    gotobank0
    
return

發表於: 2009/8/14 1:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#7
資深會員
資深會員


查看用戶資訊
;mcu 開機後 wire_bus 是 input ,pull high
;以下程式沒有經過驗證,只是照 datasheet 的描述寫出來的

;需要一個 ram 
;loop_timer
;4mhz

bus_init
:
;
1 拉low
    gotobank1
    bcf    wire_bus    
;output
    gotobank0
    bcf    wire_bus

;2 至少要 480us
    movlw    .200        
;delay 600cycle
    movwf    loop_timer
    decfsz    loop_timer
,f    ;1
    
goto    $-.1        ;23

;3 拉回來    
    bsf    wire_bus

;4 改成輸入,等 1821 reset
    gotobank1
    bsf    wire_bus    
;inputs
    gotobank0

;5 15~60 us 後,會被拉low
    movlw    .16        
;16*5us =80
    movwf    loop_timer
    btfss    wire_bus
    
goto    init_low
    decfsz    loop_timer
,f
    
goto    $-.3
    
goto    init_fail    ;1821 沒有反應

init_low
    movlw    .48        
;48*5us =240
    movwf    loop_timer
    btfsc    wire_bus
    
goto    init_high    ;1821 放開 
    decfsz    loop_timer
,f
    
goto    $-.3
    
goto    init_fail    ;1821 一直拉low

;切回輸出
init_high
    gotobank1
    bcf    wire_bus    
;output
    gotobank0
;1821 initilization 完成
    
return

發表於: 2009/8/14 1:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#6
資深會員
資深會員


查看用戶資訊
1821 datasheet 的 figure 7 figure 8 figure 9 看完,及那段說明看種就會操作了

這是 一線的溫度 ic ,線上mcu 及 ic 都是是 pull high

也就是說兩邊常態都是 input ,bus 上一直是 high 。

mcu 或 ic 將 bus 拉 low 之後,bus 上就會一直為 low ,直到拉low 的那一端放開。

當看到 low 時就能知道另一方有事要處理。

發表於: 2009/8/14 1:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#5
中級會員
中級會員


查看用戶資訊
不知道我還可以寄DS1821你嗎?

因為我研究了一大段時間都沒辦法搞定

可以麻煩你幫我一下嗎

發表於: 2009/8/13 21:49
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#4
管理員
管理員


查看用戶資訊
你好,
就我的認知 , 應該是利用軟體控制 I/O 的 Timing 來讀取 DS1821 的溫度就可以了. 你可以自己試試看 !
如果網站的各位英雄都沒人可以給你範例而你又無法完成 , 那麼你可以寄一顆 DS1821 給我 , 有空我可以 Try Try 看啦 :)

Address : 北市民權東路 3 段 4 號 12 樓 , 何仁杰收 ...

發表於: 2009/8/9 9:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#3
中級會員
中級會員


查看用戶資訊
嗯嗯

我懂 calvin 大哥的意思

也知道不能使用I2C做連接

難道要自己建一個模組來呼叫DS1821嗎??

可是該如何設計呢???

發表於: 2009/8/7 21:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於i2c
#2
管理員
管理員


查看用戶資訊
你好,

DS1821 應該是個 1-Wire interface 的溫度 Sensor 吧 ! 他是沒辦法用 I2C 直接和它 interface 並且通信的 . 一般都使用 I/O 直接經由程式 control 的方式來與其介面與控制 . 最好用 Open Drain 的接腳. 一般 PIC16F / PIC18F 的 RA4 是個不齰的選擇 .

至於範例 , 目前手中沒有 ! 就看其他的熱心朋友門是否能提供啦 :)

Regards,

發表於: 2009/8/7 21:17
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------