|
|
View previous topic :: View next topic |
Author |
Message |
fariq23
Joined: 29 Nov 2010 Posts: 8
|
ADC interrupt |
Posted: Sun Dec 05, 2010 2:28 am |
|
|
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: 19504
|
|
Posted: Sun Dec 05, 2010 3:06 am |
|
|
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 |
|
|
|
|
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
|