1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Help interfacing a ds1822 to pic16f88?

Discussion in 'Modding' started by hcker2000, 23 May 2005.

  1. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    I am just starting to get into pic programing and maby I picked a bad project to do it with but the simple fact of the mater is this seems like the best way to get the ds1822 temps into my pc and learn some thing.

    I don't have the pic in hand yet but I ordered it earlyer tonight along with a serial programer. I was planing on using the on board timing crystal but if it is to slow I also have a 20mhz ceramic resonator. I also ordered a max232 chip to go along with it for the serial portion of my project. I'm not sure if I need it for sure or not but I got it just in case.

    Below is how I would like the software to function.

    I would like the pic to poll all the ds1822's on the 1-wire bus every X amount of seconds (lets say 1 second).

    Then I want the pic to send the temperature readings back to the pc's serial port.

    Basicly I would like to know what are the first few things I need to do to get started making my software? I already downloaded the data sheet for the 16f88 and alot of the stuff in there is realy beyond me at this point. I also downloaded mplab and have it installed. Agine not sure if that is the best thing to use but seemed like alot of people use it.

    If any one would be willing to provide some sample code to help get me started that would be super great as I seem to learn best from examples that are explaned.
     
  2. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    for a starting project a 1 wire bus might give you some hassel, so i'd advise running that bus as slowly as possible!

    First off you want a PIC tutorial, there are lots of these about, but i'd recomend one that explains basic principles like the memory organisation (the fact its not a Von Nueman style). Then grab some LEDs and make them flash. Nice and easy way to start.

    once you've done that, then try making a project which talks to the serial port of the computer. Send it a message, make it send one back. Then you should have enough of an idea to be able to design ur own code to interface with the ds1822. Remeber thou you can just hook up a thermistor to the PIC's A/D pins and read the temp like that.
     
    Last edited by a moderator: 23 May 2005
  3. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    I thought about using a normal temp resistor but if I go with the 1-wire bus I can suport a ton more sensors than I can with just the resistors. Basicly I need to be able to suport as many temp sensors as I can.

    I checked out some tutorials they all in all didn't look to complicated to do some thing like blinking led's. Things I would realy need to know about are what are some of the differences when programing a pic16f88 compared to a PIC16F628A? If the code works on both with just a few adjustments of memory spaces and such then that would be nice. Also I think the 1-wire bus only has one speed that it operates at (I could be wrong about this).

    Lets start with this question. Should I use mplab to code with?
     
  4. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    1 wire bus, lots of differn't ones around, i didn't check which standard your sensor uses. Only memory differnces in effect, hardware stuff (like USARTs, watch dog timer, Brown out detection) are mapped into the data memory, but be aware of how different the config register is. Also the 88 has more config options than older 16 series (things like setting the speed of the internal oscilator).

    mplab is the best tool for coding with a PIC. I'd actually try the boring LED style tutorials, get your head firmly round programming these things. Some people don't have a problem learning howto use a PIC, some can't get their heads round the basics.

    i'd also do the LED style program to learn how to use ICSP (in circuit serial programming) because thats a hudge time saver when doing ur own code.
     
  5. ConKbot of Doom

    ConKbot of Doom Minimodder

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    As for getting the uart working, I would check out picuart.zip from http://redrival.com/mcgahee/ I've heard a lot a postive comments on it on the PIC list.

    Provided you can get the usart working with that, the 1-wire shoudnt be that much of a pain, just have make sure you have your timings down. Other than that, it doesn't seem like it should be that hard of a project.

    As for if you should use MPLAB? I would think so, it may be intimidating at first, but it all starts to make sense. Now, I don't see any reason not to use it.
     
  6. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Ok thats is one question down.

    I have programing know how in other languages (c++, c#, vb, perl, html, cgi, php) so I'm hoping I can pick up on this quickly.

    I read threw the picuart file and its a little confusing but I will keep at it tell I understand it.

    I also found this bit of code but i'm not sure what I would need to change to get it working on the 16f88.

    'display message on the 2 X 16 character LCD using pic16f84a and DS1820

    DEFINE LCD_DREG PORTA 'LCD data port
    DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
    DEFINE LCD_RSREG PORTA 'LCD register select port
    DEFINE LCD_RSBIT 4 'LCD register select bit
    DEFINE LCD_EREG PORTB 'LCD enable port
    DEFINE LCD_EBIT 3 'LCD enable bit
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8
    DEFINE LCD_LINES 4 'Number lines on LCD
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us
    DEFINE LCD_DATAUS 50 'Data delay time

    symbol DQ = PORTB.4
    temp var word
    cou var byte
    cou1 var byte
    pause 100
    main:
    owout DQ, 1,[$CC, $44]
    owin DQ, 4,[cou]
    if cou = 0 then
    owout DQ, 1, [$cc, $BE]
    owin DQ, 0,[temp.lowbyte, temp.highbyte, skip 4, cou,cou1]
    endif

    temp = (((temp >> 1) * 100) - 25 ) + (((cou - cou1) * 100) / cou)
    lcdout $fe,1," Environment Tempera"
    lcdout $fe, $c0, dec (temp / 100), " . " , dec temp, " C"
    pause 1000
    goto main
    end
     
  7. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    erm well that codes in one of the (more sh!tty) BASICs for the PIC.

    I can't emphasise the importance of reading background stuff on the PICs, will save you a lot of time later on. (I'm not speaking out of my arse her, i've taught PIC programming to school kids, and its just vital to make sure they grasp the fundimentals, which include, machine code - what it is).
     
  8. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Yea I have been reading threw ASM tutorials to get a grasp on the basic structure of it.

    Any realy good tutorials you would recomend?
     
  9. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
  10. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Thanks I'm going threw the tutorials now. They break every thing down nice so it is easy to under stand. I'm going to have to get used to the hex to binary I can see haha.
     
  11. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
    Yes, that makes it very easy. And it's to the point, not a whole bunch of junk that is useless and confusing to most. Definite "hats off" to Hazer :thumb:
     
  12. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    I need to know one thing that I have never figured out.

    In electronics diagrams how are the chips oriented? Is it like your looking at the pin side of the chip or is it like your chip is in a bead board and looking down on it?
     
  13. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
    That really depends on what type of "diagrams" you are looking at. If you are referring to PCB layouts, it could be either or. Usually, on a PCB if it is silkscreened (as if you were looking down on top of the IC), the IC outline will have an "indent" on the rectangle, indicating that pin 1 is to the left of the indent (with the indent facing up). On an actual schematic diagram, it's really irrelevent and really depends on the IC being used on how it's layed out on paper. Hope that helps a little.
     
  14. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Yea that dose help. I compleatly forgot about the notch on ic's.

    Could any one help me out with this code. It works but I would like to learn how to turn on just gpio 0.

    PHP:
    CC5X Version 3.1ICopyright (cB Knudsen Data
    C compiler for the PICmicro family
    ; ************  21. Jan 2004   9:09  *************

        
    processor  12F629
        radix  DEC

    Carry       EQU   0
    Zero_       EQU   2
    RP0         EQU   5
    GPIO        EQU   0x05
    TRISIO      EQU   0x85
    CM0         EQU   0
    CM1         EQU   1
    CM2         EQU   2
    x           EQU   0x20
    y           EQU   0x22

        
    GOTO main

      
    FILE D:\Pics\code\12F629\Blink\Blink.c
                
    ;/*
                ;    02/05/03
                ;    Copyright Spark Fun Electronics¬© 2003
                ;    
                ;    Blink on PIC12F629
                ;    
                ;    Flashes all pins on PIC - 4MHz operations
                ;    
                ;*/
                
    ;
                ;
    #include "d:\Pics\c\12F629.h"  // device dependent definitions
                
    ;
                ;
    #pragma config |= 0x0184 
                
    ;//Watch dog off, Power Up Timer on, Code Protect off, MCLR pin disabled - used as general IO
                
    ;//Internal 4MHz Osc with pin used at general IO
                
    ;//To change the config word for your desired setup, start ICProg and set options (Check boxes, etc). 
                
    ;//Then change the above 0x0184 to the 'Config Word: xxxxh' shown in the ICProg screen.
                
    ;
                ;
    void delay_ms(uns16);
                ;
                ;
    //Start main - this is the very first stuff the PIC will run
                
    ;void main()
                ;{
    main
                
    ;    GPIO 0b.1111.1111;
        
    MOVLW .255
        BCF   0x03
    ,RP0
        MOVWF GPIO
                
    ;    TRISIO 0b.0000.0000;  //0 = Output, 1 = Input
        
    BSF   0x03,RP0
        CLRF  TRISIO
                
    ;
                ;    
    //The analog and compare modules are turned on by default
                
    ;    CM2 1CM1 1CM0 1;//These turn the input pins back to digital I/O
        
    BCF   0x03,RP0
        BSF   0x19
    ,CM2
        BSF   0x19
    ,CM1
        BSF   0x19
    ,CM0
                
    ;    //ANSEL = 0; //Turn off ADC on the 12F675 - All pins digital
                
    ;
                ;    
    //Classic while loop, loops forever
                
    ;    while(1)
                ;    {
                ;
                ;        
    //GPIO port to low
                
    ;        GPIO 0x00;
    m001    CLRF  GPIO
                
    ;        delay_ms(1000);
        
    MOVLW .232
        MOVWF x
        MOVLW .3
        MOVWF x
    +1
        CALL  delay_ms
                
    ;
                ;        
    //GPIO port to high
                
    ;        GPIO 0xFF;
        
    MOVLW .255
        MOVWF GPIO
                
    ;        delay_ms(1000);
        
    MOVLW .232
        MOVWF x
        MOVLW .3
        MOVWF x
    +1
        CALL  delay_ms
                
    ;        
                ;    }
        GOTO  
    m001
                
    ;
                ;    
                ;} 
    //End Main
                
    ;
                ;
    //General short delay
                
    ;void delay_ms(uns16 x)
                ;{
    delay_ms
                
    ;    uns8 y;
                ;    for ( ; 
    x--)
    m002    MOVF  x,W
        IORWF x
    +1,W
        BTFSC 0x03
    ,Zero_
        
    GOTO  m005
                
    ;        for ( 108 y++);
        
    CLRF  y
    m003    MOVLW .108
        SUBWF y
    ,W
        BTFSC 0x03
    ,Carry
        
    GOTO  m004
        INCF  y
    ,1
        
    GOTO  m003
    m004    DECF  x
    ,1
        INCF  x
    ,W
        BTFSC 0x03
    ,Zero_
        DECF  x
    +1,1
        
    GOTO  m002
    m005    
    RETURN

        
    ORG 0x2007
        DATA 0184H
        END


    ; *** KEY INFO ***

    0x0018   17 word(s)  % : delay_ms
    0x0001   23 word(s)  % : main

    RAM usage3 bytes (3 local), 61 bytes free
    Maximum call level1
    Total of 41 code words (%)
    I got it from sparkfun.com and its nice to load up and know that I got the voltage regulator hooked up ok (thought I don't think I need the caps). For some reson even after the tutorial mentioned before I'm still having issues grasping the concept.
     
  15. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
    I've never gotten quite into this yet, so don't take what I say as correct. But, looking at the code, it would seem to me that the code concerning "m001" concerns the GPIO. If you removed, or just "remarked" m002 through m004, it would seem that only GPIO would be "turned on". I'm not even close to being sure about this, but you could try it and see what happens I guess. Or, you could wait until someone who knows what they are doing replies. :D
     
  16. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    Humm yea I'm not sure how those work out. If you load the HEX that is posted along with that asm file and load it into IC-Prog. Then click on the Assembly Viewer button it isn't exactly the same which is weird.

    On a side note dose any one know if you have to use caps with the 7805C voltage regulator?
     
  17. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
    Yes, on your input and output (I think .1uF). Those are decoupling caps and take care of ac ripple voltage going in to and out of your 7805.
     
  18. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    AC? You meen dc right?

    Alright I will leave them there. I used I think two 10v (sence I'm only feeding 7v in) 47uF caps sence thats all I had laying around and that works ok. I'm inputing 7vdc from my variac (I use a full wave rectifier to get dc from the ac of corse).
     
  19. One~Zero

    One~Zero What's a Dremel?

    Joined:
    9 Sep 2004
    Posts:
    214
    Likes Received:
    2
    I haven't seen the original circuit, so wasn't sure which caps you were referring to. There is usually a .1uf non-polarized cap on the input and output of your voltage regulator. It will block DC and couple ac to ground, giving you a "cleaner" DC voltage out. If I remember correctly (and I think I saw this on Hazer's site as well), those caps you are referring to are so the regulator doesn't have to work as "hard" to provide the regulated voltage to your IC's, since the charge/discharge of the cap doesn't require the regulator to provide a constant output per say. I know I read somewhere recently, just can't remember exactly what it said and where I saw it...sorry if it doesn't help clear things up for you.

    If you have a circuit drawn up, post it if you can. :D
     
  20. hcker2000

    hcker2000 What's a Dremel?

    Joined:
    21 Oct 2004
    Posts:
    109
    Likes Received:
    0
    I saw several 5v diagrams. They all used the decoupling caps on theres though I'm not sure it would matter much but yea I will just leave them there.
     

Share This Page