CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem with A/D
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9135
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 10, 2011 12:05 pm     Reply with quote

CCS doesn't have a 'function', you have to create your own.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 10, 2011 12:46 pm     Reply with quote

Quote:

How to make code that have initial value for port analog a0, then when
port a0 change make led bright?

Examples of how to read the ADC and change the brightness of the
LED based on the analog voltage level:
http://www.ccsinfo.com/forum/viewtopic.php?t=40007
http://www.ccsinfo.com/forum/viewtopic.php?t=40222&start=1

Example of how to read the ADC and turn an LED on or off,
depending on the value of the analog voltage level:
http://www.ccsinfo.com/forum/viewtopic.php?t=42952&start=1

If you have problems, please start a new thread for your problem
instead of putting unrelated posts on to this old thread.
Mamat



Joined: 20 Jan 2011
Posts: 9

View user's profile Send private message Yahoo Messenger ICQ Number

http://www.ccsinfo.com/forum/posting.php?mode=reply&t=32
PostPosted: Thu Feb 10, 2011 10:21 pm     Reply with quote

I'm sorry. I not mean function but how to write coding.
Code:

#include <16F877.H>
#device adc=8
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define LED_PIN  PIN_B0
//==========================================
void main()
{
int8 adc_result;

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);

float new;
new=adc_result;

output_low(LED_PIN); // Set LED to Off

while(1)
  {
   adc_result = read_adc();
   
   if(adc_result !=new)
      output_high(LED_PIN);
      delay_ms(100);
      adc_result=new;
  }

}

This code I want to use for ldr that connect to pic pin_a0. I assume initial intensity light 1volt, suddenly intensity light change to 2volt. Led light 1minute. So 2volt will be current ref intensity. It always change. This project for movement detector. This using ne555 but I want using pic for more efficient.
http://www.electro-tech-online.com/attachments/general-electronics-chat/22685d1222869801-triggering-555-timer-ldr-circuit-2.gif
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 11, 2011 7:15 am     Reply with quote

Due to natural noise the value from the A/D will always be different. You need to decide on a threshold where the light level is "significantly" different. Subtract the new light level from the old light level. If the difference is small, positive or negative, then the light did not change significantly. If the difference is bigger then you trigger your LED.

Note that artificial lights tend to flicker at 50Hz or 60Hz depending on where you are. You may have to find a way to ignore this flicker.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group