Registered Users          New User?
Picture of Maynard Demosthene
text messenger code problem
by Maynard Demosthene - Monday, February 8, 2010, 01:53 PM
 

I recived these errors and i don't know how to fix it.

Error:" _main (/home/moodle/sites/productions/codecompiler/compilers/PIC_L/lib/pclrt40c.obj)"

Line:-1

source: /text message code.c

Error:"undefined symbol." 

Line:-1

source: /text message code.c

#include "mxapi.h"
int keyscan(void)//Renames the main function, calling it keyscan
{
   int key = 0;      //Declares a variable called key and sets it equal to 0
   lcd_init();
   RBPU=0;
   TRISB0=0;
   TRISB1=0;
   TRISB2=0;
   TRISB3=0;
   TRISB4=1;
   TRISB5=1;
   TRISB6=1;
   TRISB7=1;
   while(1==1)
   {
 
RB3=0; 
 if(RB7==0)
   {
      key=1;
   }
   else if(RB6==0)
   {
      key=5;
   }
   else if(RB5==0)
   {
      key=9;
   }
   else if(RB4==0)
   {
      key=13;
   }   
RB3=1;
RB2=0;
   if(RB7==0)
   {
      key=2;
   }
   else if(RB6==0)
   {
      key=6;
   }
   else if(RB5==0)
   {
      key=10;
   }
   else if(RB4==0)
   {
      key=14;
   }
RB0=1;
return key;
   lcd_decimal(key);
   delay_ms(400);
   lcd_instruction(CLEAR);
   }
}

Me
Re: text messenger code problem
by Ivan Rudnicki - Tuesday, February 9, 2010, 07:04 AM
  In the Text Messenger project, the tutorial instructs you to create a library file to take care of scanning the keypad. This way, you have two code files that work together to create the behavior you want on the microcontroller: a library file and a main file. This can be a little confusing, so I'll try to explain it better here.

The library file is shown below. Note that, if you try to compile this file, you will get errors, because it doesn't have a main function. So you don't even need to compile it. Just save it in the same folder that your main file will be in, using the name "mxkeyscan.c".

int keyscan(void)
{
int key = 0;

RBPU=0;
TRISB0=0;
TRISB1=0;
TRISB2=0;
TRISB3=0;
TRISB4=1;
TRISB5=1;
TRISB6=1;
TRISB7=1;

/* Scan row 1*/
RB3=0;
if(RB7==0) //Scan column 1
{
key=1;
}
else if(RB6==0) //Scan column 2
{
key=5;
}
else if(RB5==0) //Scan column 3
{
key=9;
}
else if(RB4==0) //Scan column 4
{
key=13;
}
RB3=1;


/*Scan row 2*/
RB2=0;
if(RB7==0) //Scan column 1
{
key=2;
}
else if(RB6==0) //Scan column 2
{
key=6;
}
else if(RB5==0) //Scan column 3
{
key=10;
}
else if(RB4==0) //Scan column 4
{
key=14;
}
RB2=1;

/*Scan row 3*/
RB1=0;
if(RB7==0) //Scan column 1
{
key=3;
}
else if(RB6==0) //Scan column 2
{
key=7;
}
else if(RB5==0) //Scan column 3
{
key=11;
}
else if(RB4==0) //Scan column 4
{
key=15;
}
RB1=1;

/*Scan row 4*/
RB0=0;
if(RB7==0) //Scan column 1
{
key=4;
}
else if(RB6==0) //Scan column 2
{
key=8;
}
else if(RB5==0) //Scan column 3
{
key=12;
}
else if(RB4==0) //Scan column 4
{
key=16;
}
RB1=1;

return key; //Return the value of key to the main file

}

The main code file is shown below. At the top, you use an include statement to include all of the functions contained in "mxkeyscan.c" Then, down below in your while loop, when you want to get a value from the keypad, you simply have to call the keyscan() function.

Using library files is just a way to keep your main code files short and readable. Note that many other functions, like lcd_decimal() and lcd_instruction(), are contained in the "mxapi.h" header file.


#include "mxapi.h"
#include "mxkeyscan.c" //Include all the functions contained in the mxkeyscan.c file

void main(void)
{
int keynumber; //Initialize a variable called keynumber
lcd_init(); //Initialize the LCD
while(1==1)
{
keynumber=keyscan(); //Set keynumber equal to the value returned by the keyscan function (contained in "keyscan.c")
lcd_decimal(keynumber); //Display value of keynumber on the LCD
delay_ms(400); //Delay 400 ms
lcd_instruction(CLEAR); //Clear the LCD
}
}