16F690 and i2c Com


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    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.

  2. #2
    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

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    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.

  4. #4
    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

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


    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.

  6. #6
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Yea I had it at 500ms just to see if I could get each digit to display in sequence (which doesn't work). I have resistors in series with each segment but I will be honest I dont know what you mean by driver/buffer? I thought if it was a common ANODE you could use a transistor but as I said earlier my electronics is touch and go and I'm not sure how I would go about hooking that up

  7. #7
    Join Date
    May 2010
    Posts
    20


    Did you find this post helpful? Yes | No

    Default Solved

    I neatened up my code and it solved the problem why exactly it solved the problem I am not sure, but im glad it did

    Code:
    TRISC = %00000000       
    TRISB = %00000000
    
    ADCON1=%00000111
    ANSELH=0
    ANSEL=0
    CM1CON0=0
    CM2CON0=0
    
    
           
    loop:   
           GOSUB selseg1
           gosub disno1
           pause 5
           GOSUB selseg2
           gosub disno2
           pause 5
           GOSUB selseg3
           gosub disno3
           pause 5
    goto loop  
    
    Selseg1:
         portb = %01111111
         RETURN
    
    Selseg2:
         portb = %11011111
         Return
         
    Selseg3:
         portb = %10111111
         RETURN
    
    DisNo1:
      PORTC = %01000010
      Return
         
    DisNo2:
         PORTC = %01101101     
         return
         
    DisNo3:
         PORTC= %00111101
          return
          
     DisNo4:
         PORTC = %00011110     
         return
         
    DisNo5:
         PORTC = %00111011 
         return
         
     DisNo6:
         PORTC = %01111010     
         return
         
      DisNo7: 
        PORTC = %00010101      
         return
         
     DisNo8:
         PORTC = %01111111    
         return
         
     DisNo9: 
         PORTC = %00111111             
         return        
    End

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