View previous topic :: View next topic |
Author |
Message |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Apr 30, 2014 1:54 am |
|
|
You need to add ERRORS to your #use rs232 statement.
The idea of defines is to give things meaningful names and make code more readable.
So this section of code :- Code: | //lcd_putc,("/f welcome to ETPL");
//lcd_putc,("/n LCD interface");
If(input(Pin_C4))
{
Printf(" Pin C4 is high\n\r");
output_B(0);
output_high(Pin_B4);
//PIN_B4=1;
}
Else
{
Printf("Pin C4 is low/n/r");
} |
Now becomes :-
Code: | If (input(Button))
{
Printf(" Pin Button is high\n\r");
output_high(Led);
}
Else
{
Printf("Pin Button is low/n/r");
output_low(Led);
} |
Does your complete code now work correctly?
Mike |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Wed Apr 30, 2014 6:27 am |
|
|
hi my code shows error when i put as you said "Led" instead of Pin_B4 for output.
i attach my working code below.
Code: |
#include <16f877a.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,Errors)
#define Button Pin_C4 60
#define Led Pin_B4 52
#include <lcd.c>
void main()
{
lcd_init();
delay_ms(1000);
while(0);
{
If(input(Pin_C4))
{
Printf(lcd_putc,"\fPin Button is high");
output_high(Pin_B4);
}
else
{
Printf(lcd_putc,"\fPin Button is low");
output_low(Pin_B4);
}
}
}
|
Link of output screen.
http://s27.postimg.org/4g7vj4lfn/Slide1.jpg
http://s30.postimg.org/q65807ay9/Slide2.jpg
http://s28.postimg.org/9ug9e87b1/Slide3.jpg
In the above code iam getting output when i put not (!) actin before input(PIN_B4),
MY requirement is whenever pin C4 goes high PIN_B4 should also,
whenever C4 is low B4 should be.
BUT now my output is not so,it checks the condition input is on,if not it is doing nothing.
Hope you understand the issue.
help me. _________________ uma
Application Engineer,
ETPL |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Apr 30, 2014 6:55 am |
|
|
hmmm...
while(0);
this says NEVER do the following code...
same as
while(false);
You should have
while(TRUE);
{
//do all of this forever...
}
while(1); is the same.
also
...
#define Button Pin_C4 60
#define Led Pin_B4 52
delete the 60 and 52, not required ,might cause 'problems'.
and
...
insert
delay_ms(500);
before the
lcd_init();
This allows the LCD module time to get 'organized' BEFORE your program tries to access it.
recode/recompile/retest/report back
cheers |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Apr 30, 2014 7:11 am |
|
|
Strange!!!!!
My compiler does the same.
The #define for button is accepted with the extra '60' for input
The #define for led generates an error with the '52' for both input and output.
Tried a few different tests, results were not consistent.
Do as Mr T says, remove the numbers following the pin defines, and, of course, change to while(1).
Mike |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Thu May 01, 2014 11:13 pm |
|
|
Code: |
#include <16f877a.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,Errors)
#define Button Pin_C4
#define Led Pin_B4
#include <lcd.c>
void main()
{
delay_ms(1000);
lcd_init();
while(1);
{
If(input(Pin_C4))
{
Printf(lcd_putc,"\fPin Button is high");
output_high(Pin_B4);
}
else
{
Printf(lcd_putc,"\fPin Button is low");
}
}
}
|
I have made changes and compiled my code as you people said,but there still is an issue no o/p is coming. My led is not switched on even after latching.
link:
http://s15.postimg.org/no9wm4i5n/attachment.jpg _________________ uma
Application Engineer,
ETPL |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
any one tell me how to check the input is high or not, |
Posted: Thu May 01, 2014 11:15 pm |
|
|
Anyone tell me how to check the input is high or not, if not high how to make the input high. _________________ uma
Application Engineer,
ETPL |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Thu May 01, 2014 11:53 pm |
|
|
I read the thread, but still i did not get what i have done. You mean to say that i have missed looping? _________________ uma
Application Engineer,
ETPL |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Fri May 02, 2014 12:08 am |
|
|
A semicolon terminates the instruction.
Are not the same as
|
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
RE: |
Posted: Fri May 02, 2014 12:33 am |
|
|
you are saying that just because iam using while with semicolon,it is checking the condition once ah?
if so how can declare it for looping? _________________ uma
Application Engineer,
ETPL |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri May 02, 2014 1:25 am |
|
|
This really is basic C.
An if statement, while, etc., executes the next 'code block'.
A 'code block', is a single instruction, terminated with a ';', _or_ a group of instructions, contained in '{}' brackets.
So:
while(something) xxx;
executes 'xxx'
while(something)
{
xxx;
yyy;
zzz;
}
executes 'xxx', then 'yyy', then 'zzz', then 'xxx' etc...
while(something) ;
executes nothing (empty statement).
It is continuously checking the 'something', and looping, but the loop does nothing....
You need to get a C primer. |
|
|
uma
Joined: 17 Apr 2014 Posts: 29 Location: chennai
|
i understood the concept.. |
Posted: Sat May 03, 2014 2:06 am |
|
|
i understood the concept..thanks for all your responses ,i successfully compiled my code and got output.Especially the last post was very usefull for me.. _________________ uma
Application Engineer,
ETPL |
|
|
|