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 don't know where I did the mistake. Kindly watch the video first for the result.
Code:
Code:
Code:
// LCD module connections
sbit LCD_RS at RD7_bit;
sbit LCD_EN at RD6_bit;
sbit LCD_D4 at RC5_bit;
sbit LCD_D5 at RC4_bit;
sbit LCD_D6 at RD3_bit;
sbit LCD_D7 at RD2_bit;
sbit LCD_RS_Direction at TRISD7_bit;
sbit LCD_EN_Direction at TRISD6_bit;
sbit LCD_D4_Direction at TRISC5_bit;
sbit LCD_D5_Direction at TRISC4_bit;
sbit LCD_D6_Direction at TRISD3_bit;
sbit LCD_D7_Direction at TRISD2_bit;
// End LCD module connections
#define buzzer RD1_bit
#define led RD5_bit
char keypadPort at PORTB;
void lcd_rst()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Delay_ms(50);
}
void beep()
{
buzzer = 1;Delay_ms(50);
buzzer = 0;Delay_ms(50);
}
unsigned short kp, cnt, oldstate = 0;
char txt[6];
int n=0,k=0;
char number[12];
char phone[12];
void main()
{
TRISA = 0xFF;//all input
TRISD1_bit = 0;//output
TRISD5_bit = 0;//output
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "SET NUMBER_");
Keypad_Init(); // Initialize Keypad
beep();
while(1)
{
kp = 0;
kp = Keypad_Key_Click();
if(kp!=0)
{
n++;
beep();
}
// 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; // A
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
}
if(n<12)
{
number[n-1] = kp;
EEPROM_Write(n-1,number[n-1]);
while(WR_bit);//save number in eeprom
Delay_ms(60);
phone[n-1] = 0;
phone[n-1] = EEPROM_Read(n-1);
if(kp!=0)Lcd_Chr(2, n, phone[n-1]);
}
if(kp==42)// * pressed
{
lcd_rst();beep();beep();
Lcd_Out(1, 1, "CANCELED! "); Delay_ms(2000);lcd_rst();
Lcd_Out(1, 1, "SET NUMBER_");
for(k=0;k<12;k++)
{
EEPROM_Write(k,0); while(WR_bit);//save number in eeprom
Delay_ms(60);
}
EEPROM_Write(20,0);
while(WR_bit);//save number in eeprom
Delay_ms(60);
n = 0;
}
if(kp==35) // # pressed
{
lcd_rst();beep();beep();
Lcd_Out(1, 1, "NUMBER SAVED!");
for(k=0;k<12;k++)
{
phone[k] = EEPROM_Read(k);
Lcd_Chr(2, k, phone[k]);
}
Delay_ms(2000);
EEPROM_Write(20,1);
while(WR_bit);//save number in eeprom
Delay_ms(60);
lcd_rst();
n = 0;
}
if(EEPROM_Read(20)==1)
{
Lcd_Out(1, 1, "Device ready! ");
Lcd_Out(2, 1, "Num:");
for(k=0;k<12;k++)
{
phone[k] = EEPROM_Read(k);
Lcd_Chr(2, 5+k, phone[k]);
}
}
else
{
Lcd_Out(1, 1, "SET NUMBER_");
}
}
}//void main
Attachments
Last edited by a moderator: