why this dont work in real simulation. :( help me

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
nayantha88
Posts: 33
Joined: 26 May 2012 14:36

why this dont work in real simulation. :( help me

#1 Post by nayantha88 » 26 May 2012 14:48

unsigned short kp;
char code1[10] ,user1[4],user2[4];


int i=0,j,cnt;


// Keypad module connections
char keypadPort at PORTD;
// End Keypad module connections


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

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


void code_read()
{
//delay_ms(20);
//user1[0] = EEPROM_Read(0x00);
//delay_ms(20);
user1[1] = EEPROM_Read(0x01);
delay_ms(20);
user1[2] = EEPROM_Read(0x02);
delay_ms(20);
user1[3] = EEPROM_Read(0x03);
delay_ms(20);
}


void code_write()
{
//delay_ms(20);
//EEPROM_Write(0x00,code1[0]);
//delay_ms(20);
EEPROM_Write(0x01,code1[1]);
delay_ms(20);
EEPROM_Write(0x02,code1[2]);
delay_ms(20);
EEPROM_Write(0x03,code1[3]);
delay_ms(20);
}


void keyp()
{
Vdelay_ms(1000);
PORTC =0b00000111;
Vdelay_ms(2000);
PORTC =0b00000000;
kp = 0; //Reset key code variable

do //Wait for key to be pressed and released
// Store key code in kp variable
kp = Keypad_Key_Click(); //Store key code in kp variable
while (!kp);

// Prepare value for output, transform key to it's ASCII value
switch (kp)
{
case 1: kp = 49; break; // 1 // Uncomment this block for keypad4x4
case 2: kp = 50; break; // 2
case 3: kp = 51; break; // 3
case 4: kp = 65; break; // DEL //delete
case 5: kp = 52; break; // 4
case 6: kp = 53; break; // 5
case 7: kp = 54; break; // 6
case 8: kp = 66; break; // B
case 9: kp = 55; break; // 7
case 10: kp = 56; break; // 8
case 11: kp = 57; break; // 9
case 12: kp = 67; break; // C
case 13: kp = 42; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 35; break; // #
case 16: kp = 68; break; // D
}
code1 = kp;
Lcd_Chr(2, i+1, code1); // Print key ASCII value on Lcd
i++;
delay_ms(20);

}


void ok()
{
PORTC =0x04;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Thank you");
delay_ms(10);
PORTC =0x04;
}


void main()
{
PORTC = 0;
TRISC = 0;

cnt = 0; // Reset counter
Keypad_Init(); // Initialize Keypad
ADCON1=0x07;

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 6, "welcome"); // Write message text on LCD
delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Enter passcode");
Lcd_Cmd(_LCD_SECOND_ROW);
Lcd_Cmd(_LCD_UNDERLINE_ON);
Lcd_Cmd(_LCD_BLINK_CURSOR_ON);

i=0;
keyp();
keyp();
keyp();
keyp();


if(code1[0]=='1' && code1[1]=='1' && code1[2]=='1' && code1[3]=='1')
{
keyp();
if(code1[4]==68)
{
ok();
}

}

else if(code1[0]=='1' && code1[1]=='1' && code1[2]=='1' && code1[3]=='2')
{
keyp();
if(code1[4]==68)
{
ok();
}
}

else if(code1[0]=='1' && code1[1]=='1' && code1[2]=='1' && code1[3]=='3')
{
keyp();
if(code1[4]==68)
{
ok();
}
}

while (1);
}

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: why this dont work in real simulation. :( help me

#2 Post by janko.kaljevic » 28 May 2012 12:48

Hello,

Please can you provide some more information?
Which controller do you use?
What behavior did you observe?
What exactly is not working in your code?

Best regards.

nayantha88
Posts: 33
Joined: 26 May 2012 14:36

Re: why this dont work in real simulation. :( help me

#3 Post by nayantha88 » 28 May 2012 13:11

im using a 16f877. in Proteus this works fine. but in real i cant light an led for each and every keypad button. but in relal this dont happen. im building a bike dock system. i need a passcode lock for 4 users.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: why this dont work in real simulation. :( help me

#4 Post by janko.kaljevic » 29 May 2012 10:37

Hello,

Do you use development system or custom PCB?
I have tested this on EasyPIC7 and it works fine.

Best regards.

nayantha88
Posts: 33
Joined: 26 May 2012 14:36

Re: why this dont work in real simulation. :( help me

#5 Post by nayantha88 » 29 May 2012 14:46

i am using a developed circuit. i think the problem is in my circuit or my programmer.
Thank you very much

Post Reply

Return to “mikroC PRO for PIC Beta Testing”