|
|
View previous topic :: View next topic |
Author |
Message |
mierdogan
Joined: 22 Mar 2011 Posts: 7
|
Error 51 |
Posted: Tue Mar 22, 2011 4:40 am |
|
|
Code: | #include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#use fast_io(a)
#use fast_io(b)
#define portb=6
int1 x;
#int_ext
void ext_kestirmece ()
{
output_b(x);
delay_ms(500);
output_b(x);
delay_ms(500);
for (x=0;x<10;x++)
{
hede:
output_b(x);
delay_ms(1000);
output_b(x);
delay_ms(1000);
goto hede;
}
}
void main ()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
set_tris_a(0b0011111);
set_tris_b(0x00);
output_b(0x00);
basla:
x=input_a();
x=x&0x0b00011111;
portb=x;
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1);
}
|
The error:
Error 51"leeding.c" Line 53(9,10). A numeric expression must appear here
occurs after:
basla:
x=input_a();
x=x&0x0b00011111;
in the code above.
I can find no guidance on how to clear the error.
How can i reach this problem?
Thanks,
MahiR |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Mar 22, 2011 5:21 am |
|
|
this statement...
x=x&0x0b00011111;
is wrong..
I 'think' you meant to say..
x=x & 0b000111111;
x & 0x0b00011111;
.......| means hex notation
..........| means binary notation
you've got both.
probably an error from typing,long nights and not enought coffee !! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Mar 22, 2011 5:30 am |
|
|
Also, functionally, once the interrupt is called, it is never going to exit. Your 'Goto', leaves you looping for ever. Consider 'Goto' instruction, in the same vein, as using a sledgehammer to drive a screw. You _can_ do it, but the odds are you will break something....
Best Wsihes |
|
|
mierdogan
Joined: 22 Mar 2011 Posts: 7
|
|
Posted: Tue Mar 22, 2011 5:38 am |
|
|
Ttelmah wrote: | Also, functionally, once the interrupt is called, it is never going to exit. Your 'Goto', leaves you looping for ever. Consider 'Goto' instruction, in the same vein, as using a sledgehammer to drive a screw. You _can_ do it, but the odds are you will break something....
Best Wsihes |
thank you very much for your quick reply
I like this explanation
But I want to try interrupts with 5 leds and 5 buttons do you have a any ideas? for the codes?
How can i build this little project? I hope my codelist gives some ideas |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Mar 23, 2011 10:33 am |
|
|
If you are new to CCS I would get rid of your fast_io and tris() statements. Let the compiler take care of the switching of I/O's. Only start using them when you have much more experience and are sure of what you are doing.
When using interrupts, make the code inside as short as humanly possible. You have two 1 second delays and to .5 second delays inside. Delays, inside an interrupt, is a no-no. You are making the processor just sit there when it could be doing other things. Get in, do something quickly and then get out. If you need to massage data then simply set a flag (a 1 bit variable) and evaluate it in your main() section. Then, do your data massaging. Massages feel much better outside of an interrupt anyway. ;o)
Instead of assigning portb to it's register address so you can directly assign values to the port, use output_b(value). If you ever want to move the program to another pic you might need to go through and change all of your assigned ports. It's a better idea to keep your code portable as much as possible.
Clear as mud?
Ronald
- Never take a laxitive and a sleeping pill at the same time. |
|
|
mierdogan
Joined: 22 Mar 2011 Posts: 7
|
|
Posted: Thu Mar 24, 2011 2:26 am |
|
|
rnielsen wrote: | If you are new to CCS I would get rid of your fast_io and tris() statements. Let the compiler take care of the switching of I/O's. Only start using them when you have much more experience and are sure of what you are doing.
When using interrupts, make the code inside as short as humanly possible. You have two 1 second delays and to .5 second delays inside. Delays, inside an interrupt, is a no-no. You are making the processor just sit there when it could be doing other things. Get in, do something quickly and then get out. If you need to massage data then simply set a flag (a 1 bit variable) and evaluate it in your main() section. Then, do your data massaging. Massages feel much better outside of an interrupt anyway. ;o)
Instead of assigning portb to it's register address so you can directly assign values to the port, use output_b(value). If you ever want to move the program to another pic you might need to go through and change all of your assigned ports. It's a better idea to keep your code portable as much as possible.
Clear as mud?
Ronald
- Never take a laxitive and a sleeping pill at the same time. |
Hi!
Thank you for your reply
I have changed my codes as below;
Code: |
void main ()
{
setup_psp(PSP_DISABLED); // PSP birimi devre dışı
setup_timer_1(T1_DISABLED); // T1 zamanlayıcısı devre dışı
setup_timer_2(T2_DISABLED,0,1); // T2 zamanlayıcısı devre dışı
setup_adc_ports(NO_ANALOGS); // ANALOG giriş yok
setup_adc(ADC_OFF); // ADC birimi devre dışı
setup_CCP1(CCP_OFF); // CCP1 birimi devre dışı
setup_CCP2(CCP_OFF); // CCP2 birimi devre dışı
set_tris_b(0x00);
set_tris_d(0xFF);
output_b(0x00);
while(1)
{
if(input(pin_d0))
{
while(!input(pin_d1) && !input(pin_d2) && !input(pin_d3) && !input(pin_d4) && !input(pin_d5))
{
output_high(pin_b0);
delay_ms(4000);
output_low(pin_b0);
delay_ms(4000);
}
}
if(input(pin_d1))
{
while(!input(pin_d0) && !input(pin_d2) && !input(pin_d3) && !input(pin_d4) && !input(pin_d5))
{
output_high(pin_b1);
delay_ms(2000);
output_low(pin_b1);
delay_ms(2000);
}
}
if(input(pin_d2))
{
while(!input(pin_d0) && !input(pin_d1) && !input(pin_d3) && !input(pin_d4) && !input(pin_d5))
{
output_high(pin_b2);
delay_ms(1330);
output_low(pin_b2);
delay_ms(1330);
}
}
if(input(pin_d3))
{
while(!input(pin_d0) && !input(pin_d1) && !input(pin_d2) && !input(pin_d4) && !input(pin_d5))
{
output_high(pin_b3);
delay_ms(1000);
output_low(pin_b3);
delay_ms(1000);
}
}
if(input(pin_d4))
{
while(!input(pin_d0) && !input(pin_d1) && !input(pin_d2) && !input(pin_d3) && !input(pin_d5))
{
output_high(pin_b4);
delay_ms(50);
output_low(pin_b4);
delay_ms(50);
}
}
if(input(pin_d5))
{
while(!input(pin_d0) && !input(pin_d1) && !input(pin_d2) && !input(pin_d3) && !input(pin_d4))
{
output_high(pin_b5);
delay_ms(1500);
output_low(pin_b5);
delay_ms(1500);
}
}
}
} |
But there still some problem. when i was try in isis, only one led blinking when i was push to another button, other leds never starts to blinking
I think I have to use "else" or do you have any idea how can i improve my codes?
I confused
Regards
MahiR |
|
|
|
|
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
|