Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
I'm doing a password based load control in microC. everything working fine but only the problem is the LCD is not ok. it displaying wrong. here is my code:
and ISIS file:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 /******************************************************************************* * Program for 'Password Based Load Control' * * Program Written by Engr. Mithun K. Das * * MCU:PIC16F877A; X-Tal: 8MHz * * Driver:ULN2003 * * 16-May,14 * *******************************************************************************/ unsigned short kp, cnt,cnt1; // Keypad module connections char keypadPort at PORTD; // End Keypad module connections char key=0; short mode=0; short lock=0; unsigned int Password1,password2; // LCD module connections sbit LCD_RS at RB7_bit; sbit LCD_EN at RB6_bit; sbit LCD_D4 at RB5_bit; sbit LCD_D5 at RB4_bit; sbit LCD_D6 at RB3_bit; sbit LCD_D7 at RB2_bit; sbit LCD_RS_Direction at TRISB7_bit; sbit LCD_EN_Direction at TRISB6_bit; sbit LCD_D4_Direction at TRISB5_bit; sbit LCD_D5_Direction at TRISB4_bit; sbit LCD_D6_Direction at TRISB3_bit; sbit LCD_D7_Direction at TRISB2_bit; // End LCD module connections void main() { TRISC = 0x00;//all out PORTC = 0x00; cnt = 0; // Reset counter Keypad_Init(); // Initialize Keypad Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,"Password Based "); Lcd_Out(2,1,"MultiLoad Cntrol"); Delay_ms(1000); Lcd_Cmd(_LCD_CLEAR); cnt = 0; cnt1 = 0; password2 = EEPROM_Read(10)*1000+EEPROM_Read(11)*100+EEPROM_Read(12)*10+EEPROM_Read(13); while(1) { if(lock==0) { top: if(mode==0) { Lcd_Cmd(_LCD_CLEAR); if(RC0_bit)Lcd_Out(1,1,"L1:ON "); if(!RC0_bit)Lcd_Out(1,1,"L1:OFF"); if(RC1_bit)Lcd_Out(1,11,"L2:ON "); if(!RC1_bit)Lcd_Out(1,11,"L2:OFF"); if(RC2_bit)Lcd_Out(2,1,"L3:ON "); if(!RC2_bit)Lcd_Out(2,1,"L3:OFF"); if(RC3_bit)Lcd_Out(2,11,"L3:ON "); if(!RC3_bit)Lcd_Out(2,11,"L3:OFF"); Lcd_Out(1,7," "); Lcd_Out(2,7," "); } if(mode==1) { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Enter Password"); cnt=0; } if(mode==2) { Lcd_Out(1,1,"Enter Password:"); if(cnt==4) { Lcd_Out(2,11," "); cnt=0; password2 = EEPROM_Read(10)*1000+EEPROM_Read(11)*100+EEPROM_Read(12)*10+EEPROM_Read(13); Password1 = EEPROM_Read(1)*1000+EEPROM_Read(2)*100+EEPROM_Read(3)*10+EEPROM_Read(4); if(Password1==password2) { Lcd_Out(2,1,"Matched"); lock = 1; } } else { cnt++; EEPROM_Write(cnt,kp); Delay_ms(50); kp = EEPROM_Read(cnt); Lcd_Chr(2, 11+cnt, kp); // Print key ASCII value on LCD } } if(mode==3) { Lcd_Cmd(_LCD_CLEAR); } if(mode==4)// pressed # button { Lcd_Out(1,1,"NEW Password? "); if(cnt1>4) { Lcd_Out(2,11," "); cnt1=0; Delay_ms(1000); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Password"); Lcd_Out(2,1,"Changed..."); Delay_ms(1000); Lcd_Cmd(_LCD_CLEAR); mode = 0;//go to main screen goto top; } else { cnt1++; EEPROM_Write(cnt1+9,kp); Delay_ms(50); kp = EEPROM_Read(cnt1+9); Lcd_Chr(2, 10+cnt1, kp); // Print key ASCII value on LCD password2 = EEPROM_Read(10)*1000+EEPROM_Read(11)*100+EEPROM_Read(12)*10+EEPROM_Read(13); } } } else { Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"PRESS A/B/C/D"); if(key==4) RC0_bit=~RC0_bit;//pressed A if(key==8) RC1_bit=~RC1_bit;//pressed A if(key==12) RC2_bit=~RC2_bit;//pressed A if(key==16) RC3_bit=~RC3_bit;//pressed A if(key==13) lock=0; } kp = 0; // Reset key code variable // Wait for key to be pressed and released do kp = Keypad_Key_Click(); // Store key code in kp variable while (!kp); key = kp; if(key==13)// pressed * { if(mode<4)mode++; else mode = 0; } // 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: break; // A case 5: kp = 52; break; // 4 case 6: kp = 53; break; // 5 case 7: kp = 54; break; // 6 //case 8: break; // B case 9: kp = 55; break; // 7 case 10: kp = 56; break; // 8 case 11: kp = 57; break; // 9 case 12: break; // C //case 13: break; // * case 14: kp = 48; break; // 0 //case 15: break; // # //case 16: break; // D } }//while(1) }//void /******************************************************************************* * * * End Of the Program * * * * * *******************************************************************************/
and ISIS file: