Help needed using MikroC with PicKit 3

Status
Not open for further replies.

elecgirl88

New Member
Hi guys, i recently found a program called MikroC Pro and im using it with a PIC18F4520.
Im just not sure how to program my micro because im getting a really wierd error. i ran the exact code the first time and it compiled successfully, now when i tried compiling it again, im getting an error "main function not defined"

please could u check out my code and tell me what im doing wrong

thanx

Code:
//////////////////////////////////////////////////////////////////////////////
//Variable declarations

unsigned char temp;
unsigned char serial_number[8];
unsigned char key1[8];
unsigned char key2[8];
unsigned char key3[8];
unsigned char key4[8];
unsigned char key5[8];
char i;

// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;

sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
// End LCD module connections
//////////////////////////////////////////////////////////////////////////////////////
//Constant declaration- Predefined dallas serail numbers
const unsigned char key1={0xA3,0x00,0x00,0x0F,0x2A,0xAE,0x6B,0x01};
const unsigned char key2={0xA3,0x00,0x00,0x0F,0x1A,0xBE,0x1B,0x02};      //dummy keys
const unsigned char key3={0xA3,0x00,0x00,0x0F,0x3A,0xAE,0x3B,0x03};
const unsigned char key4={0xA3,0x00,0x00,0x0F,0x4A,0xCE,0x4B,0x04};
const unsigned char key5={0xA3,0x00,0x00,0x0F,0x5A,0xDE,0x5B,0x05};

/////////////////////////////////////////////////////////////////////////////////////
//Prototypes
//void main(void);
void ReadDallasKey(void);
void CompareKey(void);

/////////////////////////////////////////////////////////////////////////////////////
void main()
{ do{
  ANSEL  = 0;                                    // Configure AN pins as digital I/O
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;

  Lcd_Init();                                    // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                           // Clear LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);                      // Turn cursor off

  ReadDallasKey();
  }
 while(1);

}

///////////////////////////////////////////////////////////////////////////////////////////////////
//ReadDallasKey-Reads serial number of scanned dallas key   (CHANGE PORT PINS)
void ReadDallasKey(void)
{
    Ow_Reset(&PORTA, 0);                         // Onewire reset signal
    Ow_Write(&PORTA, 0, 0x33);                   // Issue Read ROM command

    for(temp = 0; temp<8; temp++)
    {
      serial_number[temp] = OW_Read(&PortA, 2);      //Reads and stores 8 byte serial number
    }
    CompareKey();
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//CompareKey- Compares scanned Dallas key serial number to pre-defined keys
void CompareKey(void)
{
   if (serial_number = key1||key2||key3||key4||key5)
    {
      Lcd_Out(1,1,"Authorized");
      Delay_ms(50);
      //Move Display Text
      for (i=0; i<5;i++)
      {
       Lcd_Cmd(LCD_SHIFT_RIGHT);
       Move_Delay();
      }
     }
   else
    {
     Lcd_Out(1,1,"Not");
     Lcd_Out(2,1,"Authorized");
    }
    Delay_ms(5000);
 }
 
Last edited by a moderator:
Hmm, looks OK at first, second and third glance.

Why is the prototype for main() commented out? Hard to see why it would be needed, but I'm not familiar with this compiler.

There's a utility called "lint" that you can run code through before compiling to catch errors, problems, "gotchas". You might try looking for a copy of this.

Other than that, seems like you might have a mismatched set of braces somewhere, but I sure couldn't find it ...
 
Given that main is included in your program maybe you are not including this file as part of the project.
 
its just a single program file so everything is included here, i just wrote a short script to test my iButton reader. and the exact code compiled perfectly b4, i even reinstalled MikroC and theres still an error.
 
Fixed the immediate problem in chat. She had not included he source file in the project.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…