I am going to do Password based smart door lock system for my project. I use atmega32 micro controller. I got an error when I compiling code. I got below error.
compiling C: Test01.c avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./Test01.lst -std=gnu99 -MMD -MP -MF .dep/Test01.o.d Test01.c -o Test01.o Test01.c: In function 'Getuserid': Test01.c:166: error: label 'start' used but not defined make.exe: *** [Test01.o] Error 1
Below is my code.Please help me to solve this error.
#include <avr/io.h>
#include <avr/eeprom.h> //the EEPROM library
#include <util/delay.h>
#include <lcd.h>
#include <avr/interrupt.h>
#include <math.h>
//define KEYPAD IN C PORTS
#define KEYPAD_PORT PORTC
#define KEYPAD_DDR DDRC
#define KEYPAD_PIN PINC
unsigned int failedAttempts;
///////////////////////////// EEPROM INITILIZE AND CONFIGURATION ///////////////////////////////////////////////////////////////
void EEPROM_write(unsigned int address, unsigned char data) {
/* Wait for completion of previous write */
while (EECR & (1 << EEWE));
/* Set up address and Data Registers */
EEAR = address;
EEDR = data;
/* Write logical one to EEMWE */
EECR |= (1 << EEMWE);
/* Start EEPROM write by setting EEWE */
EECR |= (1 << EEWE);
}
char EEPROM_read(unsigned int address) {
/* Wait for completion of previous write */
while (EECR & (1 << EEWE));
/* Set up address register */
EEAR = address;
/* Start EEPROM read by writing EERE */
EECR |= (1 << EERE);
/* Return data from Data Register */
return EEDR;
}
unsigned int readEEPROM(int pos) {
return ((EEPROM_read(pos + 1) * 100) + EEPROM_read(pos));
}
void writeEEPROM(unsigned int pos, unsigned int val) {
unsigned int a = val % 100; // Last two digits of the password
unsigned int b = val / 100; // First two digits of the password
EEPROM_write(pos, a);
EEPROM_write(pos + 1, b);
}
unsigned int validate_password(unsigned int entered_password) {
unsigned int EEPROM_pos = 0;
while (EEPROM_pos < 20) {
if (readEEPROM(EEPROM_pos) == entered_password) {
return 1;
}
EEPROM_pos += 2;
}
return 0;
}
////////////////////////////// KEYPAD INTERFACING /////////////////////////////////////////////////
unsigned int GetKeyPressed(void) {
uint8_t r, c;
KEYPAD_PORT |= 0x0F;
for (c = 0; c < 4; c++) {
KEYPAD_DDR &= ~(0xFF);
KEYPAD_DDR |= (0x80 >> c);
for (r = 0; r < 4; r++) {
if (!(KEYPAD_PIN & (0x08 >> r))) {
return (r * 3 + c);
}
}
}
return 0xFF; // Indicate No key pressed
}
unsigned int calcPass(unsigned int key, unsigned int position, unsigned int currentVal) {
unsigned multi = 0;
if (position == 0)
multi = 1000;
else if (position == 1)
multi = 100;
else if (position == 2)
multi = 10;
else if (position == 3)
multi = 1;
return currentVal + key * multi;
}
unsigned int Getpassword(void) {
unsigned int key;
unsigned int password = 0;
unsigned int position = 0;
LCDClear();
while (position < 4) {
while (GetKeyPressed() != 255) {
key = GetKeyPressed();
if (key < 10) {
password = calcPass(key, position, password);
LCDWriteStringXY(position, 0, "*");
position++;
_delay_ms(50);
} else if (key == 10) {
break;
}
}
}
return password;
}
unsigned int Getuserid(void) {
volatile unsigned int userid = 0;
volatile unsigned int position = 0;
volatile unsigned int currentval = 0;
volatile unsigned int multi;
LCDClear();
while (position < 2) {
if (GetKeyPressed() < 10) {
currentval = GetKeyPressed();
if ((position == 0) && (currentval > 1)) {
userid = currentval;
LCDWriteIntXY(position, 0, currentval, 1);
_delay_ms(50);
break;
}
if (position == 0)
multi = 10;
else
multi = 1;
userid += multi * currentval;
LCDWriteIntXY(position, 0, GetKeyPressed(), 1);
position++;
} else if (GetKeyPressed() == 10) {
break;
}
_delay_ms(50);
}
volatile unsigned int rem = userid % 2;
if ((userid > 18) || (rem == 1) || (userid >= EEPROM_read(20))) {
goto start;
}
return userid;
}
void openDoor(void) {
// Initially, the door is closed.
PORTC = 1 << PC5; // Open the door
LCDWriteStringXY(4, 0, "Welcome");
_delay_ms(60000); // Open for 1 minute
PORTC = 0;
}
void closeDoor(void) {
PORTC = 1 << PC4;
LCDClear();
LCDWriteStringXY(0, 0, "Door closed");
_delay_ms(200);
PORTC = 0;
}
int main(void) {
DDRC = 255;
if (EEPROM_read(21) != 5) {
// Runs only once
EEPROM_write(20, 2);
writeEEPROM(0x00, 1234); // Temporary user
EEPROM_write(21, 5);
}
LCDInit(0); // Initialize LCD module, no cursor blinking
LCDClear(); // Clear the screen
while (GetKeyPressed() == 255) {
LCDWriteStringXY(0, 0, "Please enter");
LCDWriteStringXY(4, 1, "the Password");
}
while (1) {
unsigned int password = Getpassword();
if (validate_password(password) == 1) {
LCDClear();
openDoor();
failedAttempts = 0; // Number of attempts
unsigned int m = 600; // Wait for 1 minute to add a new user
for (unsigned int i = 0; i < m; i++) {
if (GetKeyPressed() == 12) { // To add a new user, press # key
if (EEPROM_read(20) < 20) {
LCDWriteStringXY(2, 0, "Add a new user");
_delay_ms(100);
unsigned int newpassword = Getpassword();
// Save a new user in EEPROM
writeEEPROM(EEPROM_read(20), newpassword);
LCDClear();
LCDWriteStringXY(2, 0, "User ID:");
LCDWriteIntXY(2, 1, EEPROM_read(20), 2);
EEPROM_write(20, EEPROM_read(20) + 2);
i = 0;
_delay_ms(100);
} else {
LCDWriteStringXY(2, 0, "Max no of");
LCDWriteStringXY(6, 1, "users entered.");
_delay_ms(100);
}
} else if (GetKeyPressed() == 11) { // Reset the passwords, press 0 key
LCDWriteStringXY(2, 0, "Add user id");
_delay_ms(100);
unsigned int newuser = Getuserid();
_delay_ms(100);
LCDWriteStringXY(0, 0, "Add new password");
_delay_ms(100);
unsigned int newpassword = Getpassword();
_delay_ms(100);
writeEEPROM(newuser, newpassword);
LCDClear();
LCDWriteStringXY(0, 0, "Password Changed!");
_delay_ms(100);
i = 0;
}
LCDClear();
_delay_ms(1);
}
closeDoor();
} else {
LCDClear();
LCDWriteStringXY(1, 0, "Password Error!");
failedAttempts++;
if (failedAttempts > 3) {
LCDClear();
LCDWriteStringXY(0, 0, "Try Again Later!");
_delay_ms(180000);
}
_delay_ms(200);
}
}
}
At the end of
Getuserid
there isbut label
start
is never defined – just like the diagnostic tells you; it even spells out the source line: