|
|
View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Thu Feb 10, 2011 12:05 pm |
|
|
CCS doesn't have a 'function', you have to create your own. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Mamat
Joined: 20 Jan 2011 Posts: 9
|
http://www.ccsinfo.com/forum/posting.php?mode=reply&t=32 |
Posted: Thu Feb 10, 2011 10:21 pm |
|
|
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
|
|
Posted: Fri Feb 11, 2011 7:15 am |
|
|
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. |
|
|
|
|
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
|