Manchester code problem with 4x4 keypad input

General discussion on mikroBasic.
Post Reply
Author
Message
Rush453019
Posts: 7
Joined: 23 Oct 2015 02:17

Manchester code problem with 4x4 keypad input

#1 Post by Rush453019 » 23 Oct 2015 03:11

Hi team

I have tested the man_send() and man_receive() funtions with the given examples in MikroC and they worked on hardware. So I am now struggling with the code to send the inputs from the Keypad (not hard coded characters).

Further more, I want to send those inputs as a string of characters.

May I get help on how to code, because this is for my final year project. I will appreciate the help.

Regards
Rush Mosola

The Transmitting code is as Follows:

unsigned short kp, cnt, oldstate = 0;
char row =1;
char txt[10];
char m_num;
char amount;
// Keypad module connections
char keypadPort at PORTB;
// End Keypad module connections

// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_DIRECTION at TRISD4_bit;
sbit LCD_EN_DIRECTION at TRISD5_bit;
sbit LCD_D4_DIRECTION at TRISD0_bit;
sbit LCD_D5_DIRECTION at TRISD1_bit;
sbit LCD_D6_DIRECTION at TRISD2_bit;
sbit LCD_D7_DIRECTION at TRISD3_bit;
// End LCD module connections

// Manchester module connections
sbit MANRXPIN at RC7_bit;
sbit MANRXPIN_Direction at TRISC7_bit;
sbit MANTXPIN at RC6_bit;
sbit MANTXPIN_Direction at TRISC6_bit;
// End Manchester module connections

void main() {
cnt = 1; // set counter
Keypad_Init(); // Initialize Keypad
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
Lcd_Init();
Man_Send_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(row, 1, "METER #:"); // Write message text on LCD
Lcd_out(2, 1, "AMOUNT :M");

do {
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);
// 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 = 129; break; // C
case 13: kp = 144; break; // *
case 14: kp = 48; break; // 0
case 15: kp = 143; break; // #
case 16: kp = 141; break; // D

}

if (cnt<=8)
{ // Pressed key differs from previou
lcd_chr(row,cnt+9,kp);
m_num = kp;
cnt++;
if(kp == 144)
{
row=2;
cnt=0;
lcd_chr(row,cnt,kp);
amount = kp;
cnt++;
}
if(kp == 141)
{
Lcd_out(1, 9," ");
Lcd_out(2, 10," ");
row = 1;
cnt = 1;
}

if(kp == 143)
{
Man_Send(0x0B); // Send "start" byte
delay_ms(100); // Wait for a while
while (amount)
{ // String ends with zero
Man_Send(amount); // Send character
Delay_ms(30); // Wait for a while
}
Man_Send(0x0E); // Send "end" byte
Delay_ms(1000);
}
}

} while (1);
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Manchester code problem with 4x4 keypad input

#2 Post by filip » 27 Nov 2015 08:39

Hi,

I believe you have been answered on the other topic regarding the same issue.

Regards,
Filip.

Post Reply

Return to “mikroBasic General”