Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with code for reading data from ADC after pressing button

Status
Not open for further replies.

ateyah

Newbie level 5
Joined
Jan 12, 2007
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,338
Hi all;

I work on My graduated project, so I need a help

I want to read data from ADC when I press on a button.
so that I wrote a code to active the INT when RB5=1,
but the INT does not answer,i used microbasic compiler.
this is the code:
*********************************
program abbad

dim sound as word[14]
dim a as byte
dim i as byte

sub procedure interrupt
if TestBit(INTCON,INTF) = 1 then
sound[a] = ADC_read(2)
if a=14 then
a=0
else
a=a+1
end if
clearbit (intcon,intf)
end if
end sub

main:
INTCON=%10010000
ADCON1 = $80 ' configure analog inputs and Vref
TRISA = $FF ' designate PORTA as input
TRISB.0 = 1 ' designate RB7, RB6 pins as outputs
TRISD = $00 ' designate PORTD as output
TRISC = $00
a=0
while true
sound[a] = ADC_read(2)
for i =0 to 14
if sound[a]=sound then
portd=$FF
end if
next i

wend
end.
**************



thanks
 

Re: heeeeeeeeeelp

Hi,
Assuming your interrupt sub procedure is correct, you have to :
1. Connect a Normally Closed switch from RB0 to ground and not to RB5.
2. Select pullup and Interrupt edge ( falling edge) bits in Option register.
3. Use a debounce delay in interrupt routine, and then start interrupt code.
4. Since 'a' is getting incremented in the interrupt routine, in your Main program, you only check if 'a'=14 to terminate the program under 'while true', do not read ADC there.

Regards,
Laktronics
 

Re: heeeeeeeeeelp

Thank you for ur reply
but the compiler does'nt compile


76_1206473917.jpg
 

Re: heeeeeeeeeelp

Hi,
Check your interrupt routine carefully, do you need to declare the function ADC_read(2), or, anything else as per the language specifications?

Regards,
Laktronics
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top