16F690 and i2c Com


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Port A .....

    Read this..http://www.picbasic.co.uk/forum/show...8252#post88252

    Read the datasheet

    Pull some hair from the head... read some more datasheet...

    Port A could have some extra features... also a search for "all digital" might give a few answers as well

  2. #2
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    OK the hair is pulled

    From all my reading I *think* what I need to do is add

    Code:
    ANSEL=%00000000
    ADCON1=%00000111
    Will be giving it a try when I get home, I appreciate the type of reply it is way better to be steered in the right direction compared to being given the answer. I struggle to make sense of the datasheets sometimes and I cant figure out why, it may be my lack of electronic knowledge or maybe it just takes time and practice.

    I understand what the registers do but I don't understand where the value "7" comes in, why not another value.
    Last edited by ross246; - 24th May 2010 at 11:07.

  3. #3
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Hello.
    Decimal 7 is same as binary 00000111, that's why mr. Jumper provided the link above. In order to disable analog functions of the portA you have to set first three bits (i.e. bit0, bit1, bit2) of the register, which is described in a datasheet.

  4. #4
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Another little question

    It worked perfectly thank you for explaining. I wanted to ask another question I thought I would just keep it in this thread since its small.

    I am thinking of ways to hook up a 3 digit seven segment display to my pic, it has a common cathode. I was wondering if it would work to hook up each anode to lets say portc.0 through to portc.7 (the dot) and connect the cathode for each digit to a different port say portb.4 through to say portb.6. That way when I want to write something to the first digit I set portb.4 low and set portb.5 and portb.6 to high. When I tried to connect it up this way, the numbers appeared very dim. I think I have the right idea because I can decrease the pause between switching to each digit and to the human eye it would appear like they are all on at the same time? I am new to both electronics and microcontrollers so i apologise if it's a stupid question I will post the code I was fiddling with:

    Code:
    define OSC 4
    
    LEDTOP         var     PORTC.0   
    LEDTOPLEFT     var     PORTC.1
    LEDTOPRIGHT    VAR     PORTC.2
    
    LEDMIDDLE      VAR     PORTC.3
    
    LEDBOTTOMRIGHT VAR     PORTC.4
    LEDBOTTOM      VAR     PORTC.5
    LEDBOTTOMLEFT  VAR     PORTC.6
    
    SEG1 VAR PORTB.4
    SEG2 VAR PORTB.5
    SEG3 VAR PORTB.6
    
    TRISC = %00000000       
    TRISB = %00000000
    
    ADCON1=%00000111
    ANSELH=0
    ANSEL=0
    CM1CON0=0
    CM2CON0=0
    
    
           
    loop:   
           gosub Selseg1
           gosub DisNo5
           pause 500
           
           goto Selseg2
           goto DisNo5
           pause 500
           
           goto Selseg3
           goto DisNo5
           pause 500
            
           goto loop  
    
    Selseg1:
         seg1 = 0
         seg2 = 1
         seg3 = 1
         RETURN
         
    Selseg2:
         seg1 = 1
         seg2 = 0
         seg3 = 1
         Return
         
    Selseg3:
         seg1 = 1
         seg2 = 1
         seg3 = 0
         RETURN
         
    DisNo1:
         LEDTOP = 0
         LEDTOPLEFT = 0
         LEDTOPRIGHT = 1
         LEDMIDDLE = 0
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 0
         LEDBOTTOMLEFT = 0
         return
    
         
    DisNo2:
         LEDTOP = 1
         LEDTOPLEFT = 0
         LEDTOPRIGHT = 1
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 0
         LEDBOTTOM = 1
         LEDBOTTOMLEFT = 1      
         return
         
    DisNo3:
         LEDTOP = 1
         LEDTOPLEFT = 0
         LEDTOPRIGHT = 1
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 1
         LEDBOTTOMLEFT = 0      
          return
          
     DisNo4:
         LEDTOP = 0
         LEDTOPLEFT = 1
         LEDTOPRIGHT = 1
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 0
         LEDBOTTOMLEFT = 0      
         return
         
    DisNo5:
         LEDTOP = 1
         LEDTOPLEFT = 1
         LEDTOPRIGHT = 0
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 1
         LEDBOTTOMLEFT = 0      
         return
         
     DisNo6:
         LEDTOP = 0
         LEDTOPLEFT = 1
         LEDTOPRIGHT = 0
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 1
         LEDBOTTOMLEFT = 1      
         return
         
      DisNo7: 
          LEDTOP = 1
         LEDTOPLEFT = 0
         LEDTOPRIGHT = 1
         LEDMIDDLE = 0
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 0
         LEDBOTTOMLEFT = 0      
         return
         
     DisNo8:
          LEDTOP = 1
         LEDTOPLEFT = 1
         LEDTOPRIGHT = 1
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 1
         LEDBOTTOMLEFT = 1      
         return
         
     DisNo9: 
         LEDTOP = 1
         LEDTOPLEFT = 1
         LEDTOPRIGHT = 1
         LEDMIDDLE = 1
         LEDBOTTOMRIGHT = 1
         LEDBOTTOM = 0
         LEDBOTTOMLEFT = 0              
         return        
    End

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I haven't looked at your code but remember that the pins can source and sink 25mA. This is probably enough for direct driving the segments but if you have 10mA thru each segment and all seven segments lit up the poor pin on PortB that is trying to sink 70mA is going to have a hard time.

    Otherwise your aproach is correct, called multiplexing. Since each digit is only "on" 1/3 of the time (or less) it's quite common to drive the segments harder than their continous rating to get more light out of them. That way the average current thru the segments is still kept below their rating.

    /Henrik.

  6. #6
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    So I have the theory correct the strange thing is when i set B.4 and B.5 to high and B.6 to low, it displays on the 3rd segment with correct brightness. But when I try set B.4 or B.5 low and the others high, those 2 segments (1st and 2nd) appear dim. Can only think it's my code I will keep reading and trying. Thanks for the response

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Yes, the theory is correct but 500ms per digit seems a bit slow, it'll definitely be flickering... ;-)

    I don't mean to step on any toes or anything but you DO have resistors in series with LED segments don't you? Don't connect them directly to the PIC. If you don't have any resistors you may have toasted some of the segments due to too much current.... And don't forget the driver/buffer for the common cathodes, don't try to sink all that current thru the PICs I/O's.

    /Henrik.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts