|
|
View previous topic :: View next topic |
Author |
Message |
jelodavid
Joined: 03 Apr 2005 Posts: 22 Location: Laguna Philippines
|
get_long |
Posted: Wed May 11, 2005 3:24 am |
|
|
hello everyone! Please help me what's wrong with my code... I always get "Undefined identifier get_long" error.
Code: | #include <16f876.h>
//#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,PUT,NOPROTECT
#use delay(clock=8000000)
#define GREEN_LED PIN_A5
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
#define PUSH_BUTTON PIN_A4
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
wait_for_one_press()
{
while(input(PUSH_BUTTON));
delay_ms(100);
while(!input(PUSH_BUTTON));
}
typedef enum {GREEN,YELLOW,RED} colors;
show_binary_on_leds(int n)
{
output_high(GREEN_LED);
output_high(YELLOW_LED);
output_high(RED_LED);
if (bit_test(n,0))
output_low(GREEN_LED);
if (bit_test(n,1))
output_low(YELLOW_LED);
if (bit_test(n,2))
output_low(RED_LED);
}
//#include <protoalone.h>
//#include <utility.c>
#include <input.c>
main()
{
long a,b,result;
char opr;
setup_timer_0(RTCC_INTERNAL);
while(TRUE)
{
printf("\r\nEnter the first number: ");
a=get_long();
do
{
printf("\r\nEnter the operator (+-*/): ");
opr=getc();
}while(!isamoung(opr,"+-/"));
printf("\r\nEnter the second number: ");
b=get_long();
switch(opr)
{
case '+' : result=a+b; break;
case '-' : result=a-b; break;
case '*' : result=a*b; break;
case '/' : result=a/b; break;
}
printf("\r\nThe result is %lu ",result);
}
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed May 11, 2005 3:59 am |
|
|
Look in the manual. Search for 'get_long'. Is it listed. No. This is not an 'intrinsic' function, so the compiler does not know how to handle this code. The function is an 'extra', defined in 'input.c', so this file must be included in the code, before it can be used.
Best Wishes |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed May 11, 2005 9:05 am |
|
|
Before using get_long you must include <stdlib.H> in the Header
#include <16f876.h>
#include <stdlib.H>
//#device ICD=TRUE
Best wishes,
Humberto |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed May 11, 2005 9:55 am |
|
|
Two additional commnets:
1) In your code you defined:
Code: |
main()
{
long a,b,result;
|
then you copied the obtained get_long in the variable a:
Be aware that get_long() returns a signed long value.
2) In the printf:
Code: |
printf("\r\nThe result is %lu ",result);
|
you are using long unsigned again, take in mind that result is a signed long value.
To read what you expect replace lu by ld in the printf statement:
Code: |
printf("\r\nThe result is %ld ",result);
|
best wishes,
Humberto |
|
|
jelodavid
Joined: 03 Apr 2005 Posts: 22 Location: Laguna Philippines
|
|
Posted: Thu May 12, 2005 5:34 am |
|
|
thanks for the great help...! |
|
|
|
|
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
|