caramoan tour package

caramoan tour package

Author Topic: NEED HELP in PIC PROG... MCU /w keypad interface to UART...  (Read 4218 times)

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #40 on: February 16, 2010, 12:19:16 PM »
I have an example project using tthread on my blog.
It is for a billiard shot timer, here: http://geekzone.freehostia.com/2008/10/27/billiard-shot-timer/
You could see there how it is applied.  It is running 4 separate tasks (pseudo)-simultaneously.
To do a blocking delay, TT_WAIT_XXX() or TT_SWITCH() must be used to pass the control to other tasks.
The Cebuano Geek

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #40 on: February 16, 2010, 12:19:16 PM »

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #41 on: February 17, 2010, 07:48:21 PM »
sir zerow1ng my other way pa po ba not using TTHREAD? nahirapan po ako e utilize ang code.

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #41 on: February 17, 2010, 07:48:21 PM »

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #42 on: February 18, 2010, 09:40:28 AM »
http://codepad.org/l07mGqBc

sir zerow1ng

sa current code ko na ito..

whenever i send the character "g"

to mcu

i have to press any value sa keypad before mcu will reply.
nagiging infinite loop na sya.

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #42 on: February 18, 2010, 09:40:28 AM »

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #43 on: February 19, 2010, 01:12:08 PM »
I think it is difficult to debug your program without the actual hardware.
I can't just "guess" what is happening without thoroughly checking it, which I can't due to time constraint.

Also, on your latest code above you made changes to the program structure that I had initially given.
For example, putting "while()" loop on the rx_poll() function.
rx_poll() should be unblocking and must return immediately to its caller avoiding delays and blocks.
Putting while(1) puts your MCU into and endless loop.

A tip also, is that you must keep a copy of a working program before making changes.
This way you could revert back to the last working one if possible.

Your current code has lots of bugs already and I think the previously working one after the initial corrections of my code is better.
The Cebuano Geek

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #43 on: February 19, 2010, 01:12:08 PM »

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #44 on: February 19, 2010, 10:39:43 PM »
I think it is difficult to debug your program without the actual hardware.
I can't just "guess" what is happening without thoroughly checking it, which I can't due to time constraint.

Also, on your latest code above you made changes to the program structure that I had initially given.
For example, putting "while()" loop on the rx_poll() function.
rx_poll() should be unblocking and must return immediately to its caller avoiding delays and blocks.
Putting while(1) puts your MCU into and endless loop.

A tip also, is that you must keep a copy of a working program before making changes.
This way you could revert back to the last working one if possible.

Your current code has lots of bugs already and I think the previously working one after the initial corrections of my code is better.

hello sir zerow1ng... currently sir where able to send data KEYPRESSED over uart and reply back.

problem kami sir... after the 1st process...
nagkaka problem kami sa 2nd sending data from mcu to vb.net

napuputol ang string length into 2 parts.

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #44 on: February 19, 2010, 10:39:43 PM »

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #45 on: February 20, 2010, 02:31:25 AM »
my other thread with concerns on error of data recieved...
http://www.electronicslab.ph/forum/index.php/topic,15391.0.html

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #46 on: February 24, 2010, 06:51:43 PM »
UPDATE QUESTION SA THREAD NA ITO:

current CODE: http://codepad.org/JmPFYWdM

sir zerowing....

currently working na po ang mcu code namin... ang prob na encounter namin...

meron kami character to be send over uart na di need ng "# HASH KEY" = ENTER key.

paano po namin magagawa yung sir zerowing?

yun na lang kulang sa code namin....

paano po namin magagawa na yung character "t" and "a" na dapat need ang "# HASH KEY" to initiate.

ano po mali sa code namin sir zerowing?

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #47 on: February 24, 2010, 07:11:11 PM »
As I understand, you need to receive "t" and "a" sent by the PC.
But this is not processed by the MCU.

The main problem is that you are using a blocking receive function getch().
This is called only after pressing #.

To solve this a non-blocking receive function is needed and should be always called within the main loop.

Give me a few minutes and I will give the corrections.
The Cebuano Geek

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #48 on: February 24, 2010, 07:14:45 PM »
Here:
Code: [Select]
#include <pic.h>
#include "delay.h"
#include "serial.h"


//configuration fuses
__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT & LVPDIS);


#define MAX_KEYS 6

char key_buffer[MAX_KEYS + 1];
unsigned char key_counter = 0;

const unsigned char led_map[7] = {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3f};/* LED SEQUENCE INDICATOR */
unsigned char scanned_key1 = 0x00;
unsigned char scanned_key2 = 0x00;
unsigned char decoded_key = 0x00;

void init_LED(void)
{
TRISA0 = 0; RA0 = 0; /* OK LED */
TRISA1 = 0; RA1 = 0; /* STANDBY LED */
TRISA2 = 0; RA2 = 0; /* ERROR LED */
TRISA5 = 0; RA5 = 0; /* ALARM PIN */
TRISE0 = 0; RE0 = 0; /* DOOR LOCK */
TRISE1 = 0; RE1 = 0; /* TIME ENDS */
TRISE2 = 0; RE2 = 0; /* TIME ALARM */
}

void init_KEYPAD(void)
{
TRISD |= 0x70; /*PORTD<6:4> input, COLUMNS */
TRISD &= ~0x0F; /*PORTD<3:0> output, ROWS */
PORTD |= 0x0F; /*PORTD<3:0> initially high */
}

unsigned char decode_key(unsigned char val)
{
unsigned char inputted_key;

switch(val)
{
case 0x60:     //1
inputted_key = '1';
break;
case 0x50: //2
inputted_key = '2';
break;
case 0x30: //3
inputted_key = '3';
break;
case 0x61: //4
inputted_key = '4';
break;
case 0x51: //5
inputted_key = '5';
break;
case 0x31: //6
inputted_key = '6';
break;
case 0x62: //7
inputted_key = '7';
break;
case 0x52: //8
inputted_key = '8';
break;
case 0x32: //9
inputted_key = '9';
break;
case 0x63: //*
inputted_key = '*';
break;
case 0x53: //0
inputted_key = '0';
break;
case 0x33: //#
inputted_key = '#' ;
break;
default:
inputted_key = decoded_key;
break;
}

return inputted_key;
}

unsigned char scan_keypad()
{
unsigned char val_1 = 0x00;
unsigned char val_2 = 0x00;
unsigned char count1;

for(count1=0;count1 < 4;count1++)
{
PORTD = ~(0x01 << count1); /*scan row*/
val_1 = PORTD & 0x70; /*read column, RD<6:4> */
/*while clearing RD<7> & RD<3:0> */
if (val_1 != 0x70) /*if a column is pressed */
{
val_2 = (val_1 | count1); /*column (high-nibble) and count (low-nibble) */
return val_2; /*return value*/
}
}

return 0xFF; /*return any value*/
}

void ALARM_delay(void)
{
DelayMs(500); /*1/2 seconds*/
}

void ERROR_delay(void)
{
DelayMs(3000); /*3 seconds*/
}

/*
 * Retrieve any received character from UART RX buffer.
 * WARNING: Blocking code
 */
 

#if 0
char getch(void)
{
char c;

/*
  * Clear any receive errors
  */
if(OERR) //check if there is error
{
CREN = 0; //clear
CREN = 1; //re-enable
}

while(!RCIF) //wait while no character is received
;
c = RCREG;
return c;
}
#endif


void rx_poll(void)
{
unsigned char val = 0x00;

if(OERR) //check if there is error
{
CREN = 0; //clear
CREN = 1; //re-enable
}

if (!RCIF)
    return;

val = RCREG;

switch(val)
{
case 'g':
RA0 = 1; /* toggle OK LED INDICATOR */
puts("PIN CODE is CORRECT\r\n");

RA5 = 0; /* toggle Security ALARM OFF */
//puts("Security ALARM Deactivated\r\n");

RE0 = 1; /* toggle Door Lock ON ("Pin should be HIGH TO DISABLE DOOR LOCK") */
//puts("Room Lock is Dis Engage\r\n");
break;
case 'G':
RA0 = 0; /* toggle OK LED INDICATOR */
puts("PIN CODE is CORRECT\r\n");

RA5 = 1; /* toggle Security ALARM OFF */
//puts("Room Security ALARM Deactivated\n");

RE0 = 0; /* toggle Door Lock OFF ("Pin should be HIGH TO DISABLE DOOR LOCK") */
//puts("Room Lock is Engage\n");
break;

case 'b':
RA2 = 1; ERROR_delay(); RA2 = 0; /* toggle ERROR LED INDICATOR */
puts("PIN CODE is INCORRECT\r\n");
break;

case 't':
RE1 = 1; /* toggle TIME LIGHT INDICATOR */
puts("10 minutes before ROOM TIME ENDS\r\n");
break;

case 'a':
RE2 = 1; ALARM_delay(); RE2 = 0; RE1=0;
puts("ROOM TIME ENDS\r\n");
break;
}
}



void main()
{

unsigned char i;

ADCON1 = 0x07;      /*Configure AN pins as digital*/
init_LED(); /*initialize PORTA1*/
init_UART(); /*initialize UART Connection*/
init_KEYPAD();          /*initialize PORTD*/
                        /*PORTD<3:0> as KEYPAD OUTPUT*/
                            /*PORTD<6:4> as KEYPAD INPUT*/

RA5 = 1;
RA1 = 1; /*STANDBY LED INDICATOR*/

TRISB &= 0xC0; /* make RB0-RB5 as outputs for LEDs*/
PORTB = 0; /* clear LEDs */

while(1)
{

rx_poll();

scanned_key1 = scan_keypad();
if (scanned_key1 != 0xFF)
{
/* debounce */
DelayMs(50);
scanned_key2 = scan_keypad();
 
if (scanned_key2==scanned_key1)
{
decoded_key = decode_key(scanned_key2);
}

/* wait for button release */
while (scan_keypad() != 0xFF)
continue;

switch (decoded_key)
{
case '*':
key_counter = 0;
break;
case '#':
for (i=0;i<key_counter;i++)
putch(key_buffer[i]);
//puts("\n");
key_counter = 0;
break;
default:
if (key_counter<MAX_KEYS)
{
key_buffer[key_counter] = decoded_key;
key_counter++;
}
}

/* show LED bargraph */
PORTB = led_map[key_counter & 0x3F];

}


}
The Cebuano Geek

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #49 on: February 24, 2010, 07:21:02 PM »
Thank you sir zerow1ng... e try po namin mamaya... tnx po ulit sa help

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #50 on: February 25, 2010, 04:04:16 PM »
Here:
Code: [Select]
#include <pic.h>
#include "delay.h"
#include "serial.h"


//configuration fuses
__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT & LVPDIS);


#define MAX_KEYS 6

char key_buffer[MAX_KEYS + 1];
unsigned char key_counter = 0;

const unsigned char led_map[7] = {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3f};/* LED SEQUENCE INDICATOR */
unsigned char scanned_key1 = 0x00;
unsigned char scanned_key2 = 0x00;
unsigned char decoded_key = 0x00;

void init_LED(void)
{
TRISA0 = 0; RA0 = 0; /* OK LED */
TRISA1 = 0; RA1 = 0; /* STANDBY LED */
TRISA2 = 0; RA2 = 0; /* ERROR LED */
TRISA5 = 0; RA5 = 0; /* ALARM PIN */
TRISE0 = 0; RE0 = 0; /* DOOR LOCK */
TRISE1 = 0; RE1 = 0; /* TIME ENDS */
TRISE2 = 0; RE2 = 0; /* TIME ALARM */
}

void init_KEYPAD(void)
{
TRISD |= 0x70; /*PORTD<6:4> input, COLUMNS */
TRISD &= ~0x0F; /*PORTD<3:0> output, ROWS */
PORTD |= 0x0F; /*PORTD<3:0> initially high */
}

unsigned char decode_key(unsigned char val)
{
unsigned char inputted_key;

switch(val)
{
case 0x60:     //1
inputted_key = '1';
break;
case 0x50: //2
inputted_key = '2';
break;
case 0x30: //3
inputted_key = '3';
break;
case 0x61: //4
inputted_key = '4';
break;
case 0x51: //5
inputted_key = '5';
break;
case 0x31: //6
inputted_key = '6';
break;
case 0x62: //7
inputted_key = '7';
break;
case 0x52: //8
inputted_key = '8';
break;
case 0x32: //9
inputted_key = '9';
break;
case 0x63: //*
inputted_key = '*';
break;
case 0x53: //0
inputted_key = '0';
break;
case 0x33: //#
inputted_key = '#' ;
break;
default:
inputted_key = decoded_key;
break;
}

return inputted_key;
}

unsigned char scan_keypad()
{
unsigned char val_1 = 0x00;
unsigned char val_2 = 0x00;
unsigned char count1;

for(count1=0;count1 < 4;count1++)
{
PORTD = ~(0x01 << count1); /*scan row*/
val_1 = PORTD & 0x70; /*read column, RD<6:4> */
/*while clearing RD<7> & RD<3:0> */
if (val_1 != 0x70) /*if a column is pressed */
{
val_2 = (val_1 | count1); /*column (high-nibble) and count (low-nibble) */
return val_2; /*return value*/
}
}

return 0xFF; /*return any value*/
}

void ALARM_delay(void)
{
DelayMs(500); /*1/2 seconds*/
}

void ERROR_delay(void)
{
DelayMs(3000); /*3 seconds*/
}

/*
 * Retrieve any received character from UART RX buffer.
 * WARNING: Blocking code
 */
 

#if 0
char getch(void)
{
char c;

/*
  * Clear any receive errors
  */
if(OERR) //check if there is error
{
CREN = 0; //clear
CREN = 1; //re-enable
}

while(!RCIF) //wait while no character is received
;
c = RCREG;
return c;
}
#endif


void rx_poll(void)
{
unsigned char val = 0x00;

if(OERR) //check if there is error
{
CREN = 0; //clear
CREN = 1; //re-enable
}

if (!RCIF)
    return;

val = RCREG;

switch(val)
{
case 'g':
RA0 = 1; /* toggle OK LED INDICATOR */
puts("PIN CODE is CORRECT\r\n");

RA5 = 0; /* toggle Security ALARM OFF */
//puts("Security ALARM Deactivated\r\n");

RE0 = 1; /* toggle Door Lock ON ("Pin should be HIGH TO DISABLE DOOR LOCK") */
//puts("Room Lock is Dis Engage\r\n");
break;
case 'G':
RA0 = 0; /* toggle OK LED INDICATOR */
puts("PIN CODE is CORRECT\r\n");

RA5 = 1; /* toggle Security ALARM OFF */
//puts("Room Security ALARM Deactivated\n");

RE0 = 0; /* toggle Door Lock OFF ("Pin should be HIGH TO DISABLE DOOR LOCK") */
//puts("Room Lock is Engage\n");
break;

case 'b':
RA2 = 1; ERROR_delay(); RA2 = 0; /* toggle ERROR LED INDICATOR */
puts("PIN CODE is INCORRECT\r\n");
break;

case 't':
RE1 = 1; /* toggle TIME LIGHT INDICATOR */
puts("10 minutes before ROOM TIME ENDS\r\n");
break;

case 'a':
RE2 = 1; ALARM_delay(); RE2 = 0; RE1=0;
puts("ROOM TIME ENDS\r\n");
break;
}
}



void main()
{

unsigned char i;

ADCON1 = 0x07;      /*Configure AN pins as digital*/
init_LED(); /*initialize PORTA1*/
init_UART(); /*initialize UART Connection*/
init_KEYPAD();          /*initialize PORTD*/
                        /*PORTD<3:0> as KEYPAD OUTPUT*/
                            /*PORTD<6:4> as KEYPAD INPUT*/

RA5 = 1;
RA1 = 1; /*STANDBY LED INDICATOR*/

TRISB &= 0xC0; /* make RB0-RB5 as outputs for LEDs*/
PORTB = 0; /* clear LEDs */

while(1)
{

rx_poll();

scanned_key1 = scan_keypad();
if (scanned_key1 != 0xFF)
{
/* debounce */
DelayMs(50);
scanned_key2 = scan_keypad();
 
if (scanned_key2==scanned_key1)
{
decoded_key = decode_key(scanned_key2);
}

/* wait for button release */
while (scan_keypad() != 0xFF)
continue;

switch (decoded_key)
{
case '*':
key_counter = 0;
break;
case '#':
for (i=0;i<key_counter;i++)
putch(key_buffer[i]);
//puts("\n");
key_counter = 0;
break;
default:
if (key_counter<MAX_KEYS)
{
key_buffer[key_counter] = decoded_key;
key_counter++;
}
}

/* show LED bargraph */
PORTB = led_map[key_counter & 0x3F];

}


}

hello sir zerow1ng... i tried the code last night... it seems it wont work...


Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #51 on: February 25, 2010, 04:30:05 PM »
It is very difficult to code and even debug without the hardware.
Could you elaborate what didn't work.
The Cebuano Geek

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #52 on: February 26, 2010, 11:39:59 AM »
It is very difficult to code and even debug without the hardware.
Could you elaborate what didn't work.
hello sir zerow1ng... madalas kasi brownout kya di ako nakaka reply agad... nakakinput po kami ng data and send sa vb.net pero ngayon po ang error nag readtimeout error ang vb code namin...

naka set a 1000 anf value ng readtimeout namin sa VB
pag e set ko sa default value which is -1

wala po ako narrcv sa vb na data from mcu

yun po yung error namin ngayon sir..

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #53 on: February 26, 2010, 11:47:00 AM »
kapag ang readtimeout is -1, it throws exception once wala siyang nakuhang data sa read buffer...

pag readtimeout is 1000, it waits for 1000msec and pag wala pang data w/in that time, doon lang siya nagre raise ng exception.

this applies sa mga serial read method na nag iimplement ng time out exception for serial port reading.
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #54 on: February 26, 2010, 03:09:01 PM »
kapag ang readtimeout is -1, it throws exception once wala siyang nakuhang data sa read buffer...

pag readtimeout is 1000, it waits for 1000msec and pag wala pang data w/in that time, doon lang siya nagre raise ng exception.

this applies sa mga serial read method na nag iimplement ng time out exception for serial port reading.

hello sir 7... i tried to simulate the mcu with hyperterminal and its working fine.. walang error... but with vb.net.. nag timeout sya if naka set sa 1 or 1000 ang readtimeout. and wala syang narrcv kpg naka -1

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #55 on: February 26, 2010, 03:16:24 PM »
hello sir 7... i tried to simulate the mcu with hyperterminal and its working fine.. walang error... but with vb.net.. nag timeout sya if naka set sa 1 or 1000 ang readtimeout. and wala syang narrcv kpg naka -1

it looks like walang narereceive ang program mo... havent check your source code yet. baka bukas ko pa masilip yan...
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #56 on: February 26, 2010, 04:03:18 PM »
it looks like walang narereceive ang program mo... havent check your source code yet. baka bukas ko pa masilip yan...

wala nga sya na rrcv sir 7. kapag naka .readline sya lumalabasa ng readtimeout error... pagn aka readexisting.. narrcv nya pero balik sa dating problem na part-by-part ang data na rrcv.

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #57 on: February 26, 2010, 04:09:31 PM »
wala nga sya na rrcv sir 7. kapag naka .readline sya lumalabasa ng readtimeout error... pagn aka readexisting.. narrcv nya pero balik sa dating problem na part-by-part ang data na rrcv.

we'll you can try this...

trigger the mcu to send data
wait for 1000msec (Sleep method in the Thread class inside the System.Threading namespace)
check for the bytesToRead property then pag di siya 0,execute the readexisting method para makita mo kung alin yung mga nareceive nya
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #58 on: February 26, 2010, 05:14:17 PM »
Quote
wait for 1000msec (Sleep method in the Thread class inside the System.Threading namespace)
Code: [Select]
  '-------------------------------------
    ' Event handler for the Data Received
    '-------------------------------------
    Private Sub DataReceived( _
      ByVal sender As Object, _
      ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
      Handles SerialPort.DataReceived

        txtDataRcvPIN.Invoke(New  _
                       myDelegate(AddressOf updateTextBox), _
                       New Object() {})
    End Sub
    '-------------------------------------------------------
    ' Delegate and subroutine to update the Textbox control
    '-------------------------------------------------------
    Public Delegate Sub myDelegate()
    '--------------------------------------
    ' Event handler for the Update Textbox
    '--------------------------------------
    Public Sub updateTextBox()
      [b]  Thread.Sleep(1000)[/b]
        txtDataRcvPIN.AppendText(SerialPort.ReadExisting)

        ' MessageBox.Show(txtDataRcvPIN.Text & ": " & txtDataRcvPIN.Text.Length)
        If txtDataRcvPIN.Text.Length = 7 Then
            'recieved 6 digit pin data via serial port
            If SerialPort.IsOpen Then

                CheckPINCode(txtDataRcvPIN.Text)
            End If
        ElseIf txtDataRcvPIN.Text.Length < 6 Then
            'Received less than 6 digit pin data via serial port
            If SerialPort.IsOpen Then
                SerialPort.Write("b")
                txtDataSend.AppendText("Invalid Password" & Environment.NewLine)
            End If
        End If
        With txtDataReceived
            .Font = New Font("Garamond", 10.0!, FontStyle.Bold)
            .AppendText(txtDataRcvPIN.Text)
            SerialPort.DiscardInBuffer()
            SerialPort.DiscardOutBuffer()
            .ScrollToCaret()
        End With
        txtDataRcvPIN.Clear()
        'Timer1.Enabled = True
    End Sub



Quote
check for the bytesToRead property then pag di siya 0,execute the readexisting method para makita mo kung alin yung mga nareceive nya
Posted on: Today at 04:03:18 PM Posted by: reaver26

bytesToRead = 6363636 narrcv nya
readexisting = kung ano yung input ko yung narcv nya pero di nag rereply ang MCU. pag continue ko pa pressed key ulit.. wla parin reply ang MCU still rcv nya yung inputted keypressed value ko

Offline reaver26

  • Size AAA Battery
  • ***
  • Posts: 99
  • Pogi/Ganda Points: 0
  • Gender: Male
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #59 on: February 26, 2010, 06:22:23 PM »
ok na sir 7 and sir zerow1ng

 nakak rcv na ang vb ng code. from mcu..

tnx po ulit sir zerow1ng sa mcu code

and to you sir 7 sa tip sa vb.net yung thread.sleep

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #59 on: February 26, 2010, 06:22:23 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com