View previous topic :: View next topic |
Author |
Message |
stephy
Joined: 26 Sep 2013 Posts: 4
|
hey everyone, if you can help me to correct my errors |
Posted: Thu Sep 26, 2013 7:37 am |
|
|
#include "16F873A.h"
#device ADC=8
#use delay(clock=4000000)
#fuses XT,NOWDT
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=data)
#int_ext // Interrupt name , External interrupt detect on RB0
void isrext() // Interrupt service routine
{
output_c; // ISR action
delay_ms(10);
}
void main(){
setup_adc_ports(ALL_ANALOG);//configuration des ADC
enable_interrupts(global);//configuration des iterruption
enable_interrupts(int_ext);//configuration interruption sur RB0
ext_int_edge(H_to_L); //FD
setup_uart(19200);//initialiser uart for read and write
float analin[3];
float disvolts[3];
int n;
int i,x,y;
while(true){
for (n=0;n<3;n++)
{
delay_ms(10);
set_adc_channel(n);
analin[n]=read_adc();//get input
x=get_sensor_data(y_axis);
y=get_sensor_data(x_axis);
if (UART1_Data_Ready()) { // If data has been received
i = UART1_Read(); // read it
UART1_Write(i); // and send it back
}
printf(&uart_stream,PSTR("y:f\r\n"));
printf(&uart_stream,PSTR("x:f\r\n"));
output_high(PIN_B1);
delay_ms(500);
output_low(PIN_B1);
delay_ms(500);
}
}
} |
|
|
stephy
Joined: 26 Sep 2013 Posts: 4
|
|
Posted: Thu Sep 26, 2013 8:07 am |
|
|
and spatially how do I define the variables n, i, x, y.
Thanks in advance |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Sep 26, 2013 8:27 am |
|
|
Hi,
You are off to a bad start as a new forum member. To begin, you should learn to use the 'Code' buttons when posting so that your code remains
properly formatted, and is easy to read. Look at any other post here on the forum, and compare it to yours. Next, we aren't mind readers and a lot of
us don't have time to cut-n-paste your code to try to compile it. Instead, you should tell us the specific errors you are getting, and let us help you that
way! Finally, you should always post your compiler version number!!
John |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 26, 2013 8:41 am |
|
|
Code: |
analin[n]=read_adc()
|
assign an INT to a FLOAT ??
the list of problems is much greater than this however
* add "ERRORS" to #use rs232
*enable global ints LAST after the individual are set up
* setup baud with the #USE stmt makes no sense to set 9600, then 19200 in main()
*what happens to execution after the FOR loop ends?
thats just for starters |
|
|
stephy
Joined: 26 Sep 2013 Posts: 4
|
|
Posted: Thu Sep 26, 2013 9:01 am |
|
|
hey, thank you john but how can i define my variables n and x,y |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 26, 2013 11:04 am |
|
|
Quote: |
define my variables n and x,y
|
you DECLARE them now as ints
do you mean preload them with a VALUE?
as in
int n=77;
also re:
#int_ext
get rid of the delay_ms(10);
and do a dumi read of portb as a byte to clear the ISR properly |
|
|
stephy
Joined: 26 Sep 2013 Posts: 4
|
hey |
Posted: Thu Sep 26, 2013 11:29 am |
|
|
for (n=0;n<3;n++) that's about the variable n
but I didn't understand what about the isr, I know that the isr is for the interruption |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 26, 2013 11:34 am |
|
|
since your isr
only outputs port C
( which the rest of the program appears to not have set
to any value)
and ends with a potentially damaging delay
how can your question be answered?
YES there is very much wrong with the program. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Sep 26, 2013 1:01 pm |
|
|
Hi,
At the end of the day, I think you are doing this dude a disservice by spoon-feeding him answers, and not insisting that he employ a methodical process to
troubleshoot his program. He'll probably learn something about this particular program, but the process will repeat the next time.
At a minimum he should tell us (1) what the program is supposed to do, and (2) how the current functionality differs from his expectations. Dumping a
large block of un-formatted code on us, and then saying "can you help find my errors" is not an effective/efficient troubleshooting technique.
John |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Sep 27, 2013 6:40 am |
|
|
I agree that Stephy should tell us what he wants to do with the program.
I searched Google for the function UART1_Data_Ready() and it turns out this is from the MikroC compiler. Stephy copied code from another project and has no clue as to what he is doing.
My advice is to start with a simple program to blink a LED every second and from there expand your program.
We can help with this but you will have to read a C language book first. |
|
|
|