أخي الكريم, قم بتعديل الكود كالتالي:
كود:
void show_message(char *name_message)
{
lcd_out(1,1,name_message);
}
void input_password()
{
show_message(correct_pass);
}
أو
كود:
void show_message(char name_message[])
{
lcd_out(1,1,name_message);
}
void input_password()
{
show_message(correct_pass);
}
و هناك أيضا بعض النقاط تحتاج إلي توضيح:
- ما هو نوع معاملات دالة lcd_out, أظن أنه
كود:
lcd_out(int, int, char *)
فهل هذا صحيح, يمكنك التأكد من Help الخاصة بالدالة
- أنا لا أستخدم MikroC, فأرجو أن تخبرني إذا كان هناك طريقة إعلان متغير في ذاكرة الفلاش, مثلا في CodeVsionAVR هناك كلمة flash و في GCC كلمة PROG_MEM فإذا كان هناك كلمة مماثلة في MikroC فيجب استخدامها مع نوع معامل دالة show_message, فمثلا تكون في CodeVisionAVR كالتالي:
كود:
show_message(flash char * name_message)
|
سلام عليكم
ان رساله اذا كانت متكونه من 16 حرف فانها تحتاج الى 16 بايت اي ان كل حرف يحتاج بايت ومشكله ان حجم ذاكره رام صغير لايمكن خزن كل رسائل لذلك نخزنها في روم عن طريق وضع امام متغير كلمه const لان حجم ذاكره روم اكبر بكثير من رام ومشكله هنا عندما نريد عرض رساله على شاشه في مايكروسي لابد ان يكون متغير مخزون في رام وليس في روم وهنا نقوم بتحويل مصفوفه من نوع ثابت الى متغير وبعدها نعرضها على شاشه
======================================
اما بالنسبه لامر عرض رساله يكون من نوع char
كود:
void Lcd_Out(char row, char column, char *text);
========================================
انا قمت بطريقه عرض رسائل بطرق اخرى قللت كود لكني لاازال ارغب في ايجاد مشكله في استخدام pointer فارجوا من لديه خبره مساعده في ايجاد الحل
مره اخرى سعطيكم فكره اساسيه وهيه شبيه بفكره الي استخدمتها في عرض رساله فيها مفيده في تقليل حجم كود وخصوصا اذا كنت تريد تكرار رسائل بشكل كبير
ولكن لاتنسو ان الغايه هو استخدام pointer
لاحظو كود تالي وكيفيه التي تم عرض رسائل وهي ليست بجديد ولكنها محاوله لتقليل حجم كود
كود:
#define led portc.f0
#define led_dir trisc.f0
#define input 1
#define output 0
#define on 1
#define off 0
#define is ==
#define length 16 // max of length password
////////////////////////////////////////////
// LCD module connections
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RA2_bit;
sbit LCD_D5 at RA3_bit;
sbit LCD_D6 at RA4_bit;
sbit LCD_D7 at RA5_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISA2_bit;
sbit LCD_D5_Direction at TRISA3_bit;
sbit LCD_D6_Direction at TRISA4_bit;
sbit LCD_D7_Direction at TRISA5_bit;
char keypadPort at PORTB;
//////////////////////////////////variable/////////////
char kp=0, number=0 , x=0 , pp=0 , state_password=255 ;
char check_password=255 , password=0 , choice=0 ;
char my_txt[16], txt[length];
///////////////////////// message ///////////////////////////////
const char check_pass[] ="check password ";
const char correct_pass[] ="correct password" ;
const char input_pass[] ="input password ";
const char new_pass[] ="new password ";
const char uncorrect_pass[] ="vaild password ";
const char old_password[] ="old password ";
const char change_password[] ="change password ";
const char enter[] =" press enter ";
/////////// define function /////////////////////////////
char keypad();
char function_password();
//////////////////////////////////////////////////////////
void message(char message,char col)
{
if(message is 1 && col is 1 ) for(x=0;x<16;x++)my_txt[x]=correct_pass[x];
else if(message is 2 && col is 1) for(x=0;x<16;x++)my_txt[x]=input_pass[x];
else if(message is 3 && col is 2) for(x=0;x<16;x++)my_txt[x]=' ';
else if(message is 4 && col is 1) for(x=0;x<16;x++)my_txt[x]=new_pass[x];
else if(message is 5 && col is 1) for(x=0;x<16;x++)my_txt[x]=check_pass[x];
else if(message is 6 && col is 1) for(x=0;x<16;x++)my_txt[x]= uncorrect_pass[x];
else if(message is 7 && col is 1) for(x=0;x<16;x++)my_txt[x]=old_password[x];
else if(message is 8 && col is 1) for(x=0;x<16;x++)my_txt[x]=change_password[x];
else if(message is 9 && col is 2) for(x=0;x<16;x++)my_txt[x]=enter[x];
lcd_out(col,1,my_txt);
}
void init()
{
ansel=0;
anselh=0;
Lcd_Init();
// eecon1.f2 =1; //WREN: EEPROM Write Enable bit // 1 = Allows write cycles // see data sheet pic16f886 page=115
lcd_cmd(_LCD_CURSOR_OFF);
Keypad_Init();
led_dir=output;
led=off;
}
//////////////////////////////////////////////////////////////////////////////
void main()
{
init();
while(1)
{
lcd_out(1,1,"led off");
function_password();
if (state_password is 1)
{
lcd_out(1,1,"led ON ");
for(x=0;x<10;x++)
{
led=~led;
delay_ms(1000);
}
state_password=255;
lcd_cmd(1);
}
}
}
////////////////////////char keypad()///////////////////////////////////
char keypad()
{
kp=0;number=0;
while(1)
{
while( kp is 0)kp=Keypad_Key_Click();
if( kp is 1 ) number=7;
else if( kp is 2 ) number=4;
else if( kp is 3 ) number=1;
else if( kp is 5 ) number=8;
else if( kp is 6 ) number=5;
else if( kp is 7 ) number=2;
else if( kp is 8 ) number=0;
else if( kp is 9 ) number=9;
else if( kp is 10 ) number=6;
else if( kp is 11 ) number=3;
else if( kp is 12 ) kp=12;// inter
else if( kp is 4 ) kp=4;// delete number if writing worng number
else if(kp is 15 ) kp=15;// input password
else if(kp is 16 ) kp=16;// setting password
else if(kp is 14 ) kp=14;
else kp=255;
if(kp !=255)return number;
}
}
////////////////////////////////////////////////////////////////////////////////
char function_password()
{
pp=0; // start value
password=0; // start value
check_password=255; // randam value
state_password=255; // randam value
while(1)
{
keypad(); // must be choice either kp=16;(input password) or kp=15 (change password)
if(kp is 15)
{ choice=1;
message(8,1);// change password message
message(9,2);// press enter message
}
if (kp is 16)
{
choice=0;
message(2,1);// input password message
message(9,2);// press enter message
}
if( (choice is 0 && kp is 12) || ( choice is 1 && kp is 12) )
{
message(3,2);// message for delete press enter message
if( choice is 1) message(7,1); // old password message
break; // exit from while(1)
}
}
while(1)
{
keypad();
if( kp is 15 || kp is 16) kp=255;
if(kp !=12 && kp !=255 && password is 0 ) // password before change
{
if(kp is 4 && pp>0)
{
pp--;
eeprom_write(0,pp);
lcd_chr(2,pp+1,' ');
}
else if(kp !=4)
{
if(pp<(length-1)) // passaword length max. 15 can be change and one for store number of password
{ pp++;
eeprom_Write(pp,number); //must be write pp for write address start from 1
lcd_chr(2,pp,'*');
eeprom_write(0,pp);
}
}
}
while(kp is 12 && password is 0 && pp>0) // if switch(=) enter is pressed
{
for(x=0;x<=pp;x++)
{
if((eeprom_read(x+length)^ eeprom_read(x))is 0) state_password=1;
else { state_password=0; break;}
}
if( state_password is 0) break;// exit frow while
else if( choice is 1 && state_password is 1)
{
password=1;
check_password=0; // check password after input password ok value check_password=0
}
else if( choice is 0 && state_password is 1)
{
pp=0;
lcd_cmd(1);
message(1,1);
delay_ms(1000);
lcd_cmd(1);
return state_password;
}
kp=255; // exit from while because now kp=12
}
if ( state_password is 0 )
{
pp=0;
state_password=255;
lcd_cmd(1);
message(6,1);
delay_ms(1000);
lcd_cmd(1);
if( choice is 1) message(7,1);
if( choice is 0) message(2,1);
delay_ms(1000);
}
if(password is 1 && check_password is 0 )
{ pp=0;
lcd_cmd(1);
message(4,1);
delay_ms(1000);
password=2;
kp=255;// because now kp=12 and condition if( kp is 12 && password is 2) password=3; is active
}
if(kp !=12 && kp !=255 && check_password is 0 && password is 2)
{
if( kp is 4 && pp>0)
{
pp--;
lcd_chr(2,pp+1,' ');
eeprom_write(0,pp);
}
else if(kp !=4)
{
if(pp<(length-1)) // passaword length max. 15 can be change and one for store number of password
{ pp++;
eeprom_Write(pp,number); //must be write pp for write address start from 1
lcd_chr(2,pp,number+48);
eeprom_Write(0,pp);
}
}
}
if( kp is 12 && password is 2) password=3;
if( password is 3 && check_password is 0)
{
lcd_cmd(1);
message(5,1); //check password message
delay_ms(1000);
check_password=1;
pp=0;
kp=255;//because now kp=12 and condition if(kp is 12 && check_password is 1) is active
}
if(kp !=12 && kp!=255 && check_password is 1)// check password if true password change
{
if( kp is 4 && pp>0)
{
pp--;
lcd_chr(2,pp+1,' ');
eeprom_Write((2*length),pp);
}
else if(kp !=4)
{
if(pp<(length-1)) // passaword length max. 15 can be change and one for store number of password
{ pp++;
eeprom_Write((pp+(2*length)),number); //must be write pp for write address start from 1
lcd_chr(2,pp,number+48);
eeprom_Write((2*length),pp);
}
}
}
if(kp is 12 && check_password is 1 ) password=4;
if( password is 4 ) // if switch(=) enter is pressed
{
pp=eeprom_read(0);
for(x=0;x<=pp;x++)
{
if( ( eeprom_read(x) ^ eeprom_read((2*length)+x) ) is 0 )password=5;
else {
lcd_cmd(1);
password=1;
check_password=0;
message(6,1);// vaild password message
delay_ms(1000);
message(4,1);// new password message
}
}
}
if(password is 5)
{ pp = eeprom_read(0);
//for(x=0;x<= pp;x++)eeprom_write( (x+length) , eeprom_read(x) ); // this code cause eeror i dont konw
for(x=0;x<= pp;x++)txt[x]=eeprom_read(x);
for(x=0;x<= pp;x++)eeprom_write((x+16),txt[x]);
lcd_cmd(1);
message(8,1);// change password message
delay_ms(1000);
for(x=0;x<= pp;x++)eeprom_write(x,0xff);
state_password=255;
lcd_cmd(1);
return ;
}
}
}