Led as a sensor ?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    21

    Default Led as a sensor ?

    Why is He using TMR0 in this code?

    '************************************************* ***************
    '* Name : LedSensor.BAS *
    '* Author : Kifo *
    '* Notice : Copyright (c) 2004 kifo *
    '* : All Rights Reserved *
    '* Date : 15.01.2004 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    LedAnoda VAR GPIO.0
    LedKatoda VAR GPIO.1

    '************************************************* ***************


    GPIO = 0
    cmcon = 7 ' comparator (off , set as digital IO )
    TRISIO = %00000000 ' set GP 1,2,3,4,5 as outputs
    'WPU = %00110000 'pin gp3, gp4 - pull up enabled
    'option_reg.7 = 0 'global GPPU bit - za pull up enabled = 0
    'ANSEL = %00010001 'GP0 analog input , Fosc/8 ( A/D konverzija )
    'ADCON0 = %10000001 'chanel 0, stop AD, A/D On, Vdd = ref
    'ANSEL=0 'digital IO " samo za 12F675 "

    '************************************************* ***************
    INTCON = %00000000 ' Onemoguci prekide
    INTCON.2 = 0 ' brisanje flega prekoracenja Tmr0
    option_reg = %10000111 ' timer 0 prescaler rate 1:256

    '************************************************* **************



    Main:
    Low LedAnoda ' inverzni napon na led
    High LedKatoda ' led ne svijetli

    Input LedKatoda ' high Z na katodi led diode

    tmr0 = 0 ' reset timer 0

    WaitLow: IF TMR0 > 50 Then GoTo ukljuci ' tu određujemo razinu osvjetljenosti
    IF LedKatoda = 1 Then GoTo WaitLow ' čekamo kad padne nivo na nulu
    GoTo main ' ako ima dosta svjetla vraćamo se na main

    ukljuci: High LedAnoda ' ako nema dosta svjetla upalimo led diodu
    Low LedKatoda '

    Pause 400 ' led svjetli 400ms

    GoTo main


    End
    Attached Images Attached Images  

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    time base, free-running timer, to evaluate since how much time LedKatoda pin is high.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. can't even flash an LED
    By bruno333 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2005, 13:27

Members who have read this thread : 1

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