Home - Search - Members
Full Version: i have problem with the display instruction and EEPROM writing
electronicfreak
Jun 17 2008, 4:23 AM
hi friends, i m facing a problem with display instruction in mikroC and EEPROM writing problem...... this is my digital code lockproject
here is my code...........
CODE:

unsigned char OPEN();
unsigned char read_mastercode();
unsigned char check_code();
unsigned short take;
unsigned short add=0x3F;
unsigned char comp_default();
unsigned int comp_old();
unsigned char EEPROMwrite();
void write_defult();
unsigned short print();
void error();
void key_read();
char var[5],input[5];
static char var2[5]={5,4,3,2,1};
unsigned short kp, curX, curY,i=0,j=0,k=0,a=0,l,b=0;
unsigned char *text="HI SACHIN !";
unsigned char *text1="ENTER PASSWORD";
unsigned char *text2="ENTER OLD PASS";
//unsigned char *text3="enter ";
unsigned char *text4="WRONG PASSWORD";
unsigned char *text5="ENTER NEW";
unsigned char *text6="press'OK'to SAVE";
unsigned char *text7=" Code too Long...";
unsigned char *text3="OPENING........";
//unsigned char *text9="CLOSED!";
// unsigned char *dis="ERROR...... ";
int *pv;
void main() {
int lockstatus;
// curX=1;
curY=0; // For keeping record of the 2x16 LCD cursor position
//pv=&var[0];
write_defult();
Keypad_Init(&PORTB); // Initialize Keypad on PORTC
TRISC=0x00;
Delay_ms(100);
TRISD=0x00;
Delay_ms(100);
Lcd8_Config(&PORTC,&PORTD,0,2,1,7,6,5,4,3,2,1,0); // Initialize LCD on PORTB, change to PORTD for EasyPIC4
Lcd8_Cmd(LCD_CLEAR); // Clear display
Lcd8_Cmd(LCD_BLINK_CURSOR_ON);
Lcd8_Cmd(LCD_SECOND_ROW);
Lcd8_Out(1,1,text);
Delay_ms(500);
Lcd8_Out(1,1,text1);
Lcd8_Out(2,1,":");
do{
key_read();
if(kp==16)
{ while(k<4)
{
comp_old();
}
}
else if(kp<10)
{
print();

}



//continue;

}while (1);
} //~!


unsigned char EEPROMwrite()
{ Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text5);
//Lcd8_Out(2,1,text3);
INTCON=0;
for(i=0;i<5;i++)
{ key_read();
if(kp<10){
Lcd8_Chr_CP(kp);
var[i]=kp;
}
else{i--;}
}
while(1)
{Lcd8_Out(1,1,text6);
key_read();
if(kp=='C')
{
for(i=0;i<6;i++)
{
EEprom_Write(i,var[i]);

}
return(i=0);
}

}
}
/*-------------display-------------*/

unsigned short print()
{
//if (curY <6) // change cursor position

/* if (curX == 1) {
Lcd_Cmd(LCD_SECOND_ROW);
curX = 2;
curY = 1;
}
else {
Lcd_Cmd(LCD_FIRST_ROW);
curX = 1;
curY = 1;
} */

// Print on LCD
if(kp=='#')
{

if(curY<=5)
{ Lcd8_Chr_CP(kp);
check_code();
if(b==1)
{
OPEN();
Delay_ms(500);

}
else
{
error();
}
}
else
{ Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text7);
Delay_ms(500);
Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text1);
Lcd8_Out(2,1,":");
}
return 0;
}
Lcd8_Chr_CP(kp);
input[i]=kp;
curY++;
i++;
/* else
{
if(kp=='#')
{
Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out_Cp("OK");
Delay_ms(500);
// Lcd8_Cmd(LCD_CLEAR);

} */



}

/*---------------------keypad read-------------------*/

void key_read()
{
// do {
kp = 0;

// Wait for key to be pressed and released
do {
kp = Keypad_Released();
Delay_ms(10);
}
while (!kp);

// Prepare value for output
switch (kp) {
case 1: kp = '1'; break;
case 2: kp = '2'; break;
case 3: kp = '3'; break;
case 4: kp = 'A'; break;
case 5: kp = '4'; break;
case 6: kp = '5'; break;
case 7: kp = '6'; break;
case 8: kp = 'B'; break;
case 9: kp = '7'; break;
case 10: kp = '8'; break;
case 11: kp = '9'; break;
case 12: kp = 'C'; break;
case 13: kp = '*'; break;
case 14: kp = '0'; break;
case 15: kp = '#'; break;
case 16:16; break;
}
// }while(1);
}

/*-----------compare the old password-----------*/

unsigned int comp_old()
{ Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text2);
Lcd8_Out(2,1,":");
//Lcd8_Out(2,9,":");

for(i=0;i<5;i++)
{
key_read();
Lcd8_Chr_CP(kp);
var[i]=kp;

}
//a=1;

if(a==0)
{
read_mastercode();
/* if(a==1)
{
Lcd8_Out(1,1,text2);
} */

}
if(a==1){
comp_default();
}


return 0;
}
/*------------default code compare---------*/
unsigned char comp_default()
{for(i=0;i<5;i++)
{
take = Eeprom_Read(add);
if(var[i]==take)
{
add++;
}
else
{
Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text4);
k++;
break;
}
}
EEPROMwrite();
return 0;
}

/*-----------default code----------------*/
void write_defult()
{INTCON=0x00;
for(i=0;i<6;i++)
{
EEprom_Write(add, var2[i]);
add++;
}
}
/*--------------masercode compare----------*/
unsigned char read_mastercode()
{for(l=0;l<5;l++)
{take=00;
take=EEPROM_Read(i) ;
if(var[i]==take)
{
i++;
}
else
{ a=1;
return a;
}
}
EEPROMwrite();
}
/*-----------verify the code----------------*/
unsigned char check_code()
{for(l=0;l<5;l++)
{
take=00;
take=EEPROM_Read(i) ;
if(input[i]==take)
{
i++;
}
else
{
Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out(1,1,text4);
k++;
return k;
}
}
return b;
}
/*--------------oening and closig the lock----------*/
unsigned char OPEN()
{
Lcd8_Out(1,1,text3);
while(1)
{
key_read();
if(kp==B)
{Lcd8_Cmd(LCD_CLEAR);
Lcd8_Out_Cp("CLOSED!");
return 0;
}
}
return 0;
}


void error()
{
Lcd8_Cmd(LCD_CLEAR);
// Lcd8_Out(1,1,dis);
}


 




any budy help me with this , this is my digital code lock project.....
i m writing the user password in EEPROM.....it looks like its not working ....
i m using the PIC16F877A uC.........
i m not getting any hex value in EEPROM page while burning the MCU ....
if u have such project code then plz send me....
Arun Kumar V
Jun 17 2008, 5:57 AM

Hello Sachin, chenna gidhira ?

Which EEprom are you using, some i2c eeproms require the write -protect pin to be grounded and some connected to Vcc.

if your code is correct and you are unable to write to eeprom ,then it may be write -protected, so bring it in unlock mode and try again


Arun
sashijoseph
Jun 17 2008, 11:27 AM
Think he's using the PIC's internal eeprom.
Sachin it seems you've written the default code in the eeprom at location 0x3F but are reading from a different address.Can you cross check?
And which software are you using to burn the pic(and see the eeprom contents)?
electronicfreak
Jun 18 2008, 12:55 AM
Arun Kumar V wrote ...


Hello Sachin, chenna gidhira ?

Which EEprom are you using, some i2c eeproms require the write -protect pin to be grounded and some connected to Vcc.

if your code is correct and you are unable to write to eeprom ,then it may be write -protected, so bring it in unlock mode and try again


Arun

nanu chennagidiini, nivu hegiddira ...............
i m using in built EEPROM , i m programmed it using mikroC compiler....................
but i m not getting it , plz check my code anywhere i made mistake while coding.......
electronicfreak
Jun 18 2008, 1:00 AM
i m using mikro C for C coding and IC prog for burning the uC.
when i was burning the hex code ,i m not getting any hex code in the EEPROM block of IC prog or even in PICflash......
PLZ help me...........
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007