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

ADC interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fariq23



Joined: 29 Nov 2010
Posts: 8

View user's profile Send private message

ADC interrupt
PostPosted: Sun Dec 05, 2010 2:28 am     Reply with quote

Situation
1. Pic will continuously toggle LED at PORT RB1, RB2 and RB3, and toggle
buzzer ON and OFF in sequence every 1 sec.

2. When interrupt occur, ALL LED and buzzer will automatically turn
OFF, and only turn ON LED RB4.

3. After 2 sec, all sequence function back as normal.

Buzzer Q1-RD0
Buzzer GND-GND
SW1-Y1-RD3

Coding
Code:

#include <16f877a.h>
#device adc=8
#use delay (clock= 20000000)
#fuses hs,noprotect,nowdt,nolvp

#byte PORTa=5
#byte PORTb=6
#byte PORTc=7
#byte PORTd=8
#byte PORTe=9

Void main()
{

Set_tris_b(0b0000000);
Setup_port_a(ALL_ANALOG);
Setup_adc(ADC_CLOCK_INTERNAL);

do
{

portb=0b00000010;
delay_ms(1000);
portb=0b00000100;
delay_ms(1000);
portb=0b00001000;
delay_ms(1000);
output_high(pin_D0);
delay_ms(2000);
output_low(pin_D0);
delay_ms(2000);

if (input(pin_D1)==1)
{
Portb=0b00010000;
delay_ms(2000);
}

else(input(pin_D1)==0)
{
portb=0b00000010;
delay_ms(1000);
portb=0b00000100;
delay_ms(1000);
portb=0b00001000;
delay_ms(1000);
output_high(pin_D0);
delay_ms(2000);
output_low(pin_D0);
delay_ms(2000);
}

}
While(1);
}

Am I right write in this coding??
If have a problem can someone tell me where the problem is?
Thanks for your cooperation.
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Dec 05, 2010 3:06 am     Reply with quote

What interrupt?.

Do a search here on 'ADC_INTERRUPT'. Understand, that the ADC interrupt means just one thing, that the ADC has _finished_ performing a conversion. _Something else has to start it_.
Then understand that to use an interrupt, _you_ need to provide an interrupt handler (you don't show one).
Then read the data sheet. is 'ADC_CLOCK_INTERNAL' legal for a chip at 20MHz?.
Then realise that you need to tell the processor which pin to use for the ADC. Currently you are saying that all possible pins are available for use, but not selecting one.
As written, the code does not use the ADC at all.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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