caramoan tour package

caramoan tour package

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

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 #20 on: February 09, 2010, 04:31:29 PM »
Quote
Sorry, I can't do this all for you now.  I have work and only find little time in helping.

ok sir... how can i make the "hash key" to be an Enter button  and "Asterisk key" clear button?


Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #20 on: February 09, 2010, 04:31:29 PM »

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 #21 on: February 09, 2010, 04:34:34 PM »
You have to store the keypresses in an array and add a keypress counter which the keys are stored in the array and the counter incremented each time a key is press.

Then if "hash" is pressed, decrease the keypress counter if >0.

If "asterisk" is pressed, send the array up to the the number of chars in the keypress counter.
The Cebuano Geek

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #21 on: February 09, 2010, 04:34:34 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 #22 on: February 09, 2010, 09:52:12 PM »
You have to store the keypresses in an array and add a keypress counter which the keys are stored in the array and the counter incremented each time a key is press.

Then if "hash" is pressed, decrease the keypress counter if >0.

If "asterisk" is pressed, send the array up to the the number of chars in the keypress counter.

meron po kayo code snippets nito sir na pwed namin makunan ng idea? we tried what you said pero di naman ma determine kung yung inputted key namin na accept sa array. and di po namin alam paano initiate na ENTER key ang "HASH key" at maging CLEAR key ang "ASTERISK KEY"

pwede mo po ma modify yung code nabigay mo sa amin.. na hindi sya mag auto end every enter ng digit? before nya e send... you must press a key to send that keypressed digit... 

naubos na talaga ideas namin kaya nag seek na kami help dito sa forum.....

Philippine Electronics Forum

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

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 #23 on: February 10, 2010, 07:52:56 AM »
Ok.

Here:
Code: [Select]
...

#define MAX_KEYS 8

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

void main (void)
{
unsigned char i;

....
....

while (1)
{
....
....
....

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

/* wait for button release */
while (scan_keypad() != 0xFF)
{
rx_poll();
}


switch (decoded_key)
{
case '*':
key_counter = 0;
key_buffer[key_counter++] = decoded_key;
break;

case '#':
for (i=0;i<key_counter)
putch(key_buffer[i]);
putch('#');
key_counter = 0;
break;

default:

if (key_counter<MAX_KEYS)
{
key_buffer[key_counter++] = decoded_key;
}
}
}

....
....

}
}  
The Cebuano Geek

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #23 on: February 10, 2010, 07:52:56 AM »

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 #24 on: February 11, 2010, 01:18:16 PM »
http://codepad.org/TMPRspNU

sir zerow1ng... working na po ang code ko... hindi na BOX ang narerecieve ng Vb.net

and di lang po magawa ipa work sa code yung

CLEAR button "* ASTERISK"

at yung

every keypress mag ilaw ang 6 LED INDICATOR corresponding to keypress

ex:

keypressed:        1          3             5             6               8           5
LED INDICATOR:   LED1    LED2         LED3        LED4          LED5       LED6

keypressed:        7          1             0             4               6           3
LED INDICATOR:   LED1    LED2         LED3        LED4          LED5       LED6

i want to utilized PINS <RB0,RB1,RB2,RB3,RB4,RB5> for LEDS.

after sending data it will turn all the LEDS to OFF.

yun lang po...

Philippine Electronics Forum

Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #24 on: February 11, 2010, 01:18:16 PM »

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 #25 on: February 11, 2010, 02:16:20 PM »
Here:
Code: [Select]

....
....

const unsigned char led_map[8] = {
0b00000000,
0b00000001,
0b00000011,
0b00000111,
0b00001111,
0b00011111,
0b00111111,
0b00111111 /* extra, to prevent overflow */
};

void main()
{
ADCON1 = 0x07;      // Configure AN pins as digital
init_UART(); //initialize UART Connection
init_LED();                  //initialize PORTB<3:0>, 4 LEDS connected
init_KEYPAD();                //initialize PORTD;
                        //PORTD<3:0> as output
                            //PORTD<6:4> as input


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

/* clear LEDs */
PORTB = 0;

....
....

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);
display_key(decoded_key);
// putch(decoded_key);
}
         
/* wait for button release */
while (scan_keypad() != 0xFF)
{
rx_poll();
}

switch (decoded_key)
{
case '*':
/*
key_counter = 0;
key_buffer[key_counter++] = decoded_key;
*/
if (key_counter)
{
--key_counter;
}
break;

case '#':
for (i=0;i<key_counter;i++)
{
putch(key_buffer[i]);
}
puts("\r\n");
key_counter = 0;
break;

default:
if (key_counter<MAX_KEYS)
{
key_buffer[key_counter++] = decoded_key;
}
}

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

}
....
....
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 #26 on: February 12, 2010, 12:01:23 AM »
Code: [Select]
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;
}

Sir zerow1ng.... pwede ba maka recieve ng string sa MCU?

the above code can only recieve a character..

im planning to using ang array recieving a string... but i dont know how...

can you help me in that manner sir?

thank you sir..

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 #27 on: February 12, 2010, 06:39:03 AM »
The function you posted above is blocking.
You should not use this.

If you have noticed on the code I posted i create a new function "recv()" which does not wait for the uart for any char but quits immediately if none is found.  I don't use getc() anymore.
http://www.electronicslab.ph/forum/index.php/topic,15025.msg262219.html#msg262219

Serial comms receive characters one at a time only.
If you want to receive a string of characters, you have to store them in an array.
If you follow the logic on how the keypresses are stored, you will have the idea on how it is done.

But to be simpler, I suggest to stick to a single character response from the PC/uart.
Why you need to send strings of data to the MCU btw?
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 #28 on: February 12, 2010, 11:36:46 AM »
The function you posted above is blocking.
You should not use this.

If you have noticed on the code I posted i create a new function "recv()" which does not wait for the uart for any char but quits immediately if none is found.  I don't use getc() anymore.
http://www.electronicslab.ph/forum/index.php/topic,15025.msg262219.html#msg262219

Serial comms receive characters one at a time only.
If you want to receive a string of characters, you have to store them in an array.
If you follow the logic on how the keypresses are stored, you will have the idea on how it is done.

But to be simpler, I suggest to stick to a single character response from the PC/uart.
Why you need to send strings of data to the MCU btw?

i want to send string of data to mcu because on the other part of our thesis... we got a suggestion from the panelist to use karnaugh map to specify action on outputs... which to tedious to use all charactere.. where sticking to alphabet characters.. where thing what if we utilized all alphabet from "a-z" how can we utilize "aa-zz". where jsut thinking of alternatives..

do you have a code snippet of recieving string data from uart sir?

thank you

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 #29 on: February 12, 2010, 06:16:12 PM »
hello sir zerow1ng sir... my code snippet ka po sa mcu rcv that could recv string data? tnx sir...

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 #30 on: February 15, 2010, 12:41:46 PM »
http://codepad.org/A7mFIkrE
sir zerow1ng bakit ayaw gumana ang rx_poll() function ko?.... i mean hindi sya pumapasok sa condition statement para itapon palabas sa uart.

i followed kasi yung NON-BLOCKING UART BUFFER.

data received function:
Code: [Select]
void rx_poll(void)
{
char rx;
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 */
init_UART();


RA1 = 1;
if (recv(&rx))
{

if (rx == 'G') /* received message from PC that key sequence is good */
{
RA0 ^= 1; /* toggle OK LED INDICATOR */
puts("PIN CODE is CORRECT");

RA5 ^= 0; /* toggle Security ALARM ON/OFF */
puts("Room Security ALARM Deactivated");

RE0 ^= 1; /* toggle Door Lock ON/OFF ("Pin should be HIGH TO DISABLE DOOR LOCK") */
     puts("Room Lock is Dis Engage");

RE1 ^= 1; /* toggle BULB 10mins before Time ENDS */

RE2 = 1; delay(); RE2 = 0; /* toggle Time END ALARM with .5 seconds Delay */

/*do stuff for OK confirmation
... turn on OK LED
...
*/
}
else if (rx=='B') /* received message from PC that key sequence is BAD */
{

RA2 = 1; delay(); RA2 = 0; /* toggle ERROR LED INDICATOR */
puts("PIN CODE is INCORRECT");


/*do stuff for NOT OK confirmation
 ... turn ON NT OK LED
 ...
*/
}
}
}

ano po mali sa declaration ko sa main function sir?
MAIN FUNCTION
Code: [Select]
void main()
{
init_UART(); /*initialize UART Connection*/
TRISA1 = 0; RA1 = 0;           /*initialize PORTA1*/
init_KEYPAD();           /*initialize PORTD*/
                         /*PORTD<3:0> as KEYPAD OUTPUT*/
                             /*PORTD<6:4> as KEYPAD INPUT*/


RA1 = 1; /*STANDBY LED INDICATOR*/

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

unsigned char i;
while(1)
{
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);
            display_key(decoded_key);
         }
        
         /* wait for button release */
         while (scan_keypad() != 0xFF)
         {
            rx_poll();
         }
   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++;
}
}
PORTB = led_map[key_counter & 0x3F]; /* show LED bargraph */
}
}  
}
}

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 #31 on: February 15, 2010, 01:30:48 PM »
Few errors on my first look:
- initUart on the rx_poll function, I did not include this on my original posted code.
- no more rx_poll() called on the main loop. Why is it removed?
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 #32 on: February 16, 2010, 04:25:27 AM »
http://codepad.org/gH4atOXh

sir zerow1ng gud morning/dawn.

sir i restored everything to what you posted last time...

still sir ayaw pumasok sa rx_poll() function.

i tried to combine the blocking function and the nonblocking function.. ayaw naman gumana...

ano po kaya ang prob dito? tinaggal ko narin ang display_key kasi di na sya kailangan...


Code: [Select]
void rx_poll(void)
{
char rx;
ADCON1 = 0xC0;      // Configure AN pins as digital
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 */


RA1 = 1;   /* STANDBY LED ALWAYS ON */
RA5 ^= 1; /* active when system is lock */
if (recv(&rx))
{

if (rx == 'G' ) /* received message from PC that key sequence is good */
{
RA0 ^= 1; /* toggle OK LED INDICATOR */
// puts("PIN CODE is CORRECT");

RA5 ^= 0; /* toggle Security ALARM ON/OFF */
// puts("Room Security ALARM Deactivated");

RE0 ^= 1; /* toggle Door Lock ON/OFF ("Pin should be HIGH TO DISABLE DOOR LOCK") */
    // puts("Room Lock is Dis Engage");

RE1 ^= 1; /* toggle BULB 10mins before Time ENDS */

RE2 = 1; delay(); RE2 = 0; /* toggle Time END ALARM with .5 seconds Delay */

/*do stuff for OK confirmation
... turn on OK LED
...
*/
}
if (rx== 'B' ) /* received message from PC that key sequence is BAD */
{

RA2 = 1; delay(); RA2 = 0; /* toggle ERROR LED INDICATOR */
// puts("PIN CODE is INCORRECT");


/*do stuff for NOT OK confirmation
  ... turn ON NT OK LED
  ...
*/
}
}
}


Main FUNCTION:
Code: [Select]
void main()
{

init_UART(); /*initialize UART Connection*/
TRISA1 = 0; RA1 = 0;          /*initialize PORTA1*/
init_KEYPAD();          /*initialize PORTD*/
                        /*PORTD<3:0> as KEYPAD OUTPUT*/
                            /*PORTD<6:4> as KEYPAD INPUT*/



RA1 = 1;

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

unsigned char i;
while(1)

{
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);
          // display_key(decoded_key);
          }
         
          /* wait for button release */
        while (scan_keypad() != 0xFF)
          {
            rx_poll();
          }
    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];
}
rx_poll();

    }
}

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 #33 on: February 16, 2010, 07:31:25 AM »
There are still errors:
- rx_poll() on main() is placed under the "if (scanned_key1 != 0xFF)" which should NOT be. Please check again my original code.
- you should not use blocking functions on this app because it should service immediately characters received from the uart.
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 #34 on: February 16, 2010, 08:44:15 AM »
There are still errors:
- rx_poll() on main() is placed under the "if (scanned_key1 != 0xFF)" which should NOT be. Please check again my original code.
- you should not use blocking functions on this app because it should service immediately characters received from the uart.

sir same parin sya kahit saan ko ilagay ang rx_poll().

main function:
Code: [Select]
void main()
{

init_UART(); /*initialize UART Connection*/
TRISA1 = 0; RA1 = 0;          /*initialize PORTA1*/
init_KEYPAD();          /*initialize PORTD*/
                        /*PORTD<3:0> as KEYPAD OUTPUT*/
                            /*PORTD<6:4> as KEYPAD INPUT*/

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



RA1 = 1;
    {
unsigned char i;
while(1)

{
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);
          // display_key(decoded_key);
          }
         
          /* wait for button release */
        while (scan_keypad() != 0xFF)
          {
            rx_poll();
          }
    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];
}

rx_poll();   

}

}




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 #35 on: February 16, 2010, 08:56:06 AM »
How did you know that the rx_poll() or the reception of data from the UART is not working?
By the LEDs?
Take note the on the rx_poll() routine, you added some codes that TURNs OFF the LEDs everytime this is called.
These codes were not on my original code.
rx_poll() is always called within the main loop thus the all the LEDs are OFF always.
The Cebuano Geek

Offline akhen

  • Diesel Generator
  • *
  • Posts: 1294
  • Pogi/Ganda Points: 47
  • Gender: Female
  • "Learning is good but application is 100x better!"
Re: NEED HELP in PIC PROG... MCU /w keypad interface to UART...
« Reply #36 on: February 16, 2010, 08:57:27 AM »
@master zero

thank you so much for your all out support... I really appreciate your kindness and willingness to help not jut to ts but to all members who needs help... point for you sir...

@reaver26
keep going sir... you can do it...

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 #37 on: February 16, 2010, 09:40:48 AM »
How did you know that the rx_poll() or the reception of data from the UART is not working?
By the LEDs?
Take note the on the rx_poll() routine, you added some codes that TURNs OFF the LEDs everytime this is called.
These codes were not on my original code.
How did you know that the rx_poll() or the reception of data from the UART is not working?
By the LEDs?
Take note the on the rx_poll() routine, you added some codes that TURNs OFF the LEDs everytime this is called.
These codes were not on my original code.
rx_poll() is always called within the main loop thus the all the LEDs are OFF always.
rx_poll() is always called within the main loop thus the all the LEDs are OFF always.

isn't my declaration inside the routine sir will turn the LED ON and OFF vice versa if the said character is called?
sorry sir im just being dumb or i cant really get it to work. i have the idea but im missing something....

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 #38 on: February 16, 2010, 09:57:52 AM »
This will turn the LEDs OFF every time rx_poll() is called.
Code: [Select]
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 */

Move this before the main loop or maybe everytime you will press '*'.

Turning off the status LEDs must be on a separate routine, for example on TIME ALARM, which turns ON at the alarm time.
But this needs to be OFF, for example the alarm length is 30 seconds only, so you need to devise a non-blocking timer which will turn OFF the ALARM LED after 30 seconds.

IMHO, this type of application needs multitasking engine such as tthread (as my initial advice) to be simpler.
The example code is using a simplified state machine using "scanned_key1 != 0xFF" (keypad pressed) or the recv() function (uart data received) that has active an non-active states which is only serviced when TRUE.

For non-blocking timers, you need to add a timer interrupt and decrements a timer value inside and only service the timeout when the value is 0.

This will become complicated when you have additional tasks/states to be serviced as well such as DOOR, ALARM pin, TIME END etc.
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 #39 on: February 16, 2010, 12:13:29 PM »
This will turn the LEDs OFF every time rx_poll() is called.
Code: [Select]
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 */

Move this before the main loop or maybe everytime you will press '*'.

Turning off the status LEDs must be on a separate routine, for example on TIME ALARM, which turns ON at the alarm time.
But this needs to be OFF, for example the alarm length is 30 seconds only, so you need to devise a non-blocking timer which will turn OFF the ALARM LED after 30 seconds.

IMHO, this type of application needs multitasking engine such as tthread (as my initial advice) to be simpler.
The example code is using a simplified state machine using "scanned_key1 != 0xFF" (keypad pressed) or the recv() function (uart data received) that has active an non-active states which is only serviced when TRUE.

For non-blocking timers, you need to add a timer interrupt and decrements a timer value inside and only service the timeout when the value is 0.

This will become complicated when you have additional tasks/states to be serviced as well such as DOOR, ALARM pin, TIME END etc.

oh no.... kaya pala ayaw mag work... i've search the Net regarding TTHREAD sir.. but i can get the logic of it.

sir can i ask again your help regarding those routines mentioned? we will get the idea from it and modify it to fit our preference...
i know its to much sir..

Philippine Electronics Forum

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

 

Privacy Policy

Contact Us: elabph@yahoo.com