Numeric value for Photoresistor/LDR value


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    actually im trying to used pic to switch led at a different light falling to the ldr.

    now im connecting portb1 with an ldr(other end of the ldr leg to the portb1 and the other to the ground), portb6 and 7 will be the output led.

    v1 var byte

    main:
    pot portb.1,255,v1

    if v1 < 100 then lmp1
    if v1 > 100 then lmp2
    goto main


    lmp1:

    high 6
    pause 500
    low 6
    pause 500

    return


    lmp2:

    high 7
    pause 500
    low 7
    pause 500

    return

    is this the way to programm? or i got a wrong connection on the circuit..
    need help..thanks..

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do not use high ?. Use PORT?.? instead, works much better.
    Here is some code to look at. My LCD is on PORT B so the pins are different than yours but you can get the idea.

    Code:
    '#####################
    '16F877A
    
    DEFINE OSC 20
    
    '####################
    'LCD SET UP
    DEFINE LCD_DREG     PORTB
    define LCD_DBIT     4
    DEFINE LCD_RSREG    PORTB
    DEFINE LCD_RSBIT    1
    DEFINE LCD_EREG     PORTB
    DEFINE LCD_EBIT     0
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    2
    DEFINE LCD_COMMANDUS    2000
    DEFINE LCD_DATAUS   50
    
    '#####################
    V1		VAR	BYTE
    LED	VAR	PORTD.2
    
    PAUSE 1000
    
    RUN:
    LCDOUT $FE,1,"POT"
    LCDOUT $FE,$C0,DEC V1
    PAUSE 100
    POT PORTC.7,127,V1
    IF V1 < 100 THEN
    GOTO LMP1
    ELSE 
    GOTO LMP2
    ENDIF
    GOTO RUN
    
    LMP1:
    HIGH LED
    GOTO RUN
    
    LMP2:
    LOW LED
    GOTO RUN
    
    END
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Tech. I've used the LDR's in the past but read them with the ADCIN command. I've found ADCIN is easier & more accurate to work with. Also, your "if V1" statements have a slight glitch. If the value is exactly 100, the PIC will do nothing.

    v1 var byte
    portb = 0 'all off

    main:
    adcin 0,v1
    if v1 < 100 then lmp1
    if v1 >= 100 then lmp2 'added if equal to
    goto main

    lmp1:
    high portb.6
    pause 500
    low portb.6
    pause 500
    goto main 'return is for GOSUB's
    lmp2:
    high portb.7
    pause 500
    low portb.7
    pause 500
    goto main

  4. #4
    Join Date
    Apr 2007
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by peterdeco1 View Post
    Hi Tech. I've used the LDR's in the past but read them with the ADCIN command. I've found ADCIN is easier & more accurate to work with. Also, your "if V1" statements have a slight glitch. If the value is exactly 100, the PIC will do nothing.

    v1 var byte
    portb = 0 'all off

    main:
    adcin 0,v1
    if v1 < 100 then lmp1
    if v1 >= 100 then lmp2 'added if equal to
    goto main

    lmp1:
    high portb.6
    pause 500
    low portb.6
    pause 500
    goto main 'return is for GOSUB's
    lmp2:
    high portb.7
    pause 500
    low portb.7
    pause 500
    goto main
    im using picf16f84a..
    Found out ADCIN did not work for pic16f84..

Similar Threads

  1. DT's instant interupts compile problem
    By comwarrior in forum General
    Replies: 4
    Last Post: - 18th October 2009, 19:30
  2. Formating numeric values to text
    By Andre_Pretorius in forum General
    Replies: 2
    Last Post: - 1st August 2009, 08:39
  3. EDTP Ethernet MINI PICBASIC PRO DRIVER
    By edtp in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 1st May 2008, 22:00
  4. Saving numeric data to eeprom from array
    By joseph Degorio in forum Serial
    Replies: 5
    Last Post: - 14th December 2007, 05:18
  5. Numeric Values
    By Armando Herjim in forum General
    Replies: 8
    Last Post: - 28th June 2006, 01:54

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