Matrix Switch

Discussion in 'Embedded Systems and Microcontrollers' started by beeson76, Oct 19, 2010.

  1. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    I have a post in the microcontroller section of the forums with my code and schematic. But I have a few quetions just about matrix switches. The matrix switch I am messing around with is 3 columns and 4 rows. I have it connected to PORTB using the internal pullups.

    From what I am reading, I have to pulse PORTB high (or at least the pins connected to my columns (which in this case would be RB0, RB1, RB7)). I simply do this with the statement(s):

    Code ( (Unknown Language)):
    1.  
    2. RB0 = 1;
    3. RB1 = 1;
    4. RB7 = 1;
    5.  
    Is that correct?

    Then I have to read the status of the rows (RB3..RB6) to see which one is high. Should I use maybe an if statement, to read that status?

    Thanks for any help given.

    Much appreciated.
     
  2. DonQ

    Active Member

    May 6, 2009
    320
    11
    Set only one of them and read all the inputs. Then set the next one of them and read all the inputs again. Rotate through all the columns. Only when a column that is activated has a closed switch will you see it on reading the inputs.

    Generally, you delay slightly between scans, and even between setting an output and reading inputs so that the signals can settle.
     
  3. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    OK. You have enable pullups on all port B input pins so these pin will normally read a HIGH. Now makes RB0, RB1 and RB7 an output and set to HIGH too.

    So without any key press, a read from port B pins should be all HIGH.

    Now there is a logic problem here. All yours portB input pins are at logic HIGH because of internal pullups, if there is no key presses.

    What you should do is to place(output) a LOW on one of the RB0, RB1 or RB7, then read the port again.

    If there is any LOW on any of the RB3~RB6, then a key is being pressed on that row. If there isn't any LOW, moves to another column and do the same check.
     
  4. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    I appreciate the replies. I am looking forward to getting this thing programmed. I will post the program through its various stages here so if anyone needs it to use or for an example, it will be here. I find that C examples for matrix switches on PICs are very hard to come by. Even information about PICs with matrix switches is very hard to find, though you can find generic information here and there.

    But I appreciate the replies and help. Thanks.
     
  5. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Here is what I have programmed so far. This is only for Column 1 Rows 1-4. So eventually I will program Columns 2 through 3 pretty much the exact same. By this program, what it is doing is displaying Switch 1, Switch 2, etc on the LCD every second without any key press. In other words, it is mainly scrolling through the Switch names every second.

    What I did is make all Columns high and as inputs. And at the same time I made all Rows Low and as outputs.

    I then made Column 1 low, and read the outputs. If any ROW (output) is a low, I then displayed that on the LCD.

    I understand making Columns inputs and Rows output, but what I don't understand is that wouldn't the weak pullups make all Pins on PORTB HIGH? So should I make all PINS on PORTB high instead of making Columns HIGH and Rows LOW?

    I am keeping is very simple for right now using an IF statement. Don't really want any macros for right because they make following the program harder.

    Thanks for your replies.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <htc.h>
    4. #include "lcd.h"
    5.  
    6. #define COL_1   RB0
    7. #define COL_2   RB1
    8. #define COL_3   RB7
    9. #define ROW_1   RB3
    10. #define ROW_2   RB4
    11. #define ROW_3   RB5
    12. #define ROW_4   RB6
    13. #define  DelayS(T)              {unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}    //Delay Macro
    14. #define  _XTAL_FREQ             4000000                             //Needs to be set for __delay_ms
    15.  
    16. __CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
    17.  
    18. main()
    19. {
    20.    
    21. PORTA = 0x00;                                       //PORTA is cleared and set low
    22.  
    23. PORTB = 0x83;                   //(0b10000011 binary) (0x83 hex)--COLUMNS set to HIGH  
    24.                                                     //PORTB7:B0 is set to high,low,low,low,low,low,high,high
    25.                                                     //ROWS set to LOW
    26. PORTC = 0x00;                                       //PORTC is cleared and set low
    27. TRISA = 0x00;                                       //Set PORTA to outputs
    28.  
    29. TRISB = 0x7C;                                       //(0b01111100 binary) (0x7C hex)--COLUMNS set to INPUT
    30.                                                     //PORTB7:B0 is set to output,input,input,input,input,input,output,output,
    31.  
    32. TRISC = 0x00;                                       //Set PORTC to outputs
    33. RBPU = 0;                                           //PORTB Weak Internal Pullups enabled
    34. ANSEL = 0;                                          //Initialize A/D Ports off
    35. ANSELH = 0;                                         //Initialize ........
    36. CM1CON0 = 0;                                        //Initialize Comparator 1 off
    37. CM2CON0 = 0;                                        //Initialize Comparator 2 off
    38.  
    39. OPTION = 0b01010101;                                //OPTION REG
    40.                                                     //xbxxxxx101  1:64
    41.                                                     //xbxxxx0xxx  Prescaler set to Timer0
    42.                                                     //xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
    43.                                                     //xbxx0xxxxx  (T0CS) Internal instruction cycle clock
    44.                                                     //xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
    45.                                                     //xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
    46.  
    47. lcd_init();                                         //LCD Display is Initialized...See LCD.C file and LCD.h
    48.  
    49. while (1)
    50.     {
    51.         COL_1 = 0;                                  //COLUMN 1 is set LOW
    52.         if (ROW_1 = 0)                              //If ROW 1 is low...
    53.             {                                       //...
    54.                 lcd_clear();                        //...
    55.                 lcd_goto(0);                        //...
    56.                 lcd_puts("Switch 1");               //Display "Switch 1"
    57.                 __delay_ms(150);
    58.                 __delay_ms(150);
    59.                 __delay_ms(150);
    60.                 __delay_ms(150);
    61.                 __delay_ms(150);
    62.                 __delay_ms(150);
    63.                 __delay_ms(100);
    64.             }
    65.         if (ROW_2 = 0)                              //if ROW 2 is low...
    66.             {                                       //...
    67.                 lcd_clear();                        //...      
    68.                 lcd_goto(0);                        //...
    69.                 lcd_puts("Switch 4");               //Display "Switch 4"
    70.                 __delay_ms(150);           
    71.                 __delay_ms(150);
    72.                 __delay_ms(150);
    73.                 __delay_ms(150);
    74.                 __delay_ms(150);
    75.                 __delay_ms(150);
    76.                 __delay_ms(100);
    77.             }
    78.         if (ROW_3 = 0)                              //If ROW 3 is LOW
    79.             {                                       //...
    80.                 lcd_clear();                        //...
    81.                 lcd_goto(0);                        //...
    82.                 lcd_puts("Switch 7");               //Display "Switch 7"
    83.                 __delay_ms(150);
    84.                 __delay_ms(150);
    85.                 __delay_ms(150);
    86.                 __delay_ms(150);
    87.                 __delay_ms(150);
    88.                 __delay_ms(150);
    89.                 __delay_ms(100);
    90.             }
    91.         if (ROW_4 = 0)                              //if ROW 4 is LOW
    92.             {                                       //...
    93.                 lcd_clear();                        //...
    94.                 lcd_goto(0);                        //...
    95.                 lcd_puts("Switch 10");              //Display "Switch 10"
    96.                 __delay_ms(150);
    97.                 __delay_ms(150);
    98.                 __delay_ms(150);
    99.                 __delay_ms(150);
    100.                 __delay_ms(150);
    101.                 __delay_ms(150);
    102.                 __delay_ms(100);
    103.             }
    104.     }
    105. }
    106.  
    107.  
    108.  
     
    Last edited: Oct 21, 2010
  6. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    I just read in the PIC16F886 data sheet that when a pin is configured as an output, then the weak pullups are automatically disabled. So if I have my ROWS set as output (the weak pullups are disabled on it). So keep from having to put external resistors on it, wouldn't I have to have all of PORTB as input, and then pull my Columns LOW and then read which ROW is low and then display that on the LCD?
     
  7. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    You have made the Global /RBPU active in OPTION register but have you set the correct bits of WPUB register to activate the individual pull up inside port B?

    [​IMG]
     
  8. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    To activate the pullups for PORTB wouldn't I use the statement:

    RBPU = 0;
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Yes, and the default for WPUB is 1 (the 1 in the R/W-1 in post 7) so you don't need to do anything unless you want to disable some of them.
     
  10. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks Markd77. Can you see if this is correct then.

    Here is my latest code. I added the WPUB statements and I changed some things around as far as how the code runs--Im read the COLUMNS first then the ROWS second. Here is what I am doing:

    1. I set ROWS as INPUTS (RB3-RB6)
    2. I set ROWS as HIGH
    3. I set COLUMNS as OUTPUTS (RB0,RB1,RB7)
    4. I set COLUMNS as HIGH
    5. I enable Weak Pullups on ROWS. This will make these PINs HIGH because Weak PULLUPS pull HIGH these PINS
    6. In the code I make COL_1 LOW and read the ROW to see if any are LOW.
    7. If any are LOW I display that switch on the LCD.

    Code ( (Unknown Language)):
    1.  
    2. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3. //
    4. //This program controls a Matrix Switch.  The Switch consists of 3 columns and 4 rows.
    5. //Whenever a button is pushed, that button is displayed on an LCD Display.
    6. //PIC16F886 Microcontroller from Microchip is being used.
    7. //
    8. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    9.  
    10. #include <htc.h>
    11. #include "lcd.h"
    12.  
    13. #define COL_1   RB0
    14. #define COL_2   RB1
    15. #define COL_3   RB7
    16. #define ROW_1   RB3
    17. #define ROW_2   RB4
    18. #define ROW_3   RB5
    19. #define ROW_4   RB6
    20. #define  DelayS(T)              {unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}    //Delay Macro
    21. #define  _XTAL_FREQ             4000000                             //Needs to be set for __delay_ms
    22.  
    23. __CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
    24.  
    25. main()
    26. {
    27.    
    28. PORTA = 0x00;                                       //PORTA is cleared and set low
    29.  
    30. PORTB = 0xFF;                                       //(0b11111111 binary) (0xFF hex)--ROWS set to HIGH, COLUMNS set to HIGH  
    31.                                                     //PORTB7:B0 is set to high,high,high,high,high,high,high,high
    32.                                                    
    33. PORTC = 0x00;                                       //PORTC is cleared and set low
    34. TRISA = 0x00;                                       //Set PORTA to outputs
    35.  
    36. TRISB = 0x7C;                                       //(0b01111100 binary) (0x7C hex)--ROWS set to INPUT, COLUMNS set to OUTPUT
    37.                                                     //PORTB7:B0 is set to output,input,input,input,input,input,output,output,
    38.                                                     //ROWS set to INPUT
    39.  
    40. TRISC = 0x00;                                       //Set PORTC to outputs
    41.  
    42.  
    43. ANSEL = 0;                                          //Initialize A/D Ports off
    44. ANSELH = 0;                                         //Initialize ........
    45. CM1CON0 = 0;                                        //Initialize Comparator 1 off
    46. CM2CON0 = 0;                                        //Initialize Comparator 2 off
    47.  
    48. OPTION = 0b01010101;                                //OPTION REG
    49.                                                     //xbxxxxx101  1:64
    50.                                                     //xbxxxx0xxx  Prescaler set to Timer0
    51.                                                     //xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
    52.                                                     //xbxx0xxxxx  (T0CS) Internal instruction cycle clock
    53.                                                     //xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
    54.                                                     //xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
    55. RBPU = 0;                                           //Don't think I need this, but to be safe...PORTB Weak Internal Pullups enabled
    56. WPUB0 = 0;                                          //COL_1 Weak pullup is individually DISABLED--OUTPUT
    57. WPUB1 = 0;                                          //COL_2 Weak Pullup is inidivdually DISABLED--OUTPUT
    58. WPUB2 = 0;                                          //Not being used...Weak Pullup is individually DISABLED
    59. WPUB3 = 1;                                          //ROW_1 Weak Pullup is individually ENABLED--INPUT
    60. WPUB4 = 1;                                          //ROW_2 Weak Pullup is individually ENABLED--INPUT
    61. WPUB5 = 1;                                          //ROW_3 Weak Pullup is individually ENABLED--INPUT
    62. WPUB6 = 1;                                          //ROW_4 Weak Pullup is individually ENABLED--INPUT
    63. WPUB7 = 0;                                          //COL_3 Weak Pullup is individually DISABLED--INPUT
    64.  
    65.  
    66. lcd_init();                                         //LCD Display is Initialized...See LCD.C file and LCD.h
    67.  
    68. while (1)
    69.     {
    70.         lcd_clear;                                  //Clear LCD
    71.         lcd_goto(0);                                //Go to Line 1 Position 1
    72.         lcd_puts("Matrix Switch");                  //Display "Matrix Switch"
    73.         lcd_goto(40);                               //Go to Line 2 Position 1
    74.         lcd_puts("Press Button");                   //Display "Press Button"
    75.        
    76.         COL_1 = 0;                                  //COLUMN 1 is set LOW
    77.         if (ROW_1 = 0)                              //and If ROW 1 is LOW...
    78.             {                                       //...
    79.                 lcd_clear();                        //...
    80.                 lcd_goto(0);                        //...
    81.                 lcd_puts("Switch 1");               //Display "Switch 1"
    82.                 __delay_ms(150);
    83.                 __delay_ms(150);
    84.                 __delay_ms(150);
    85.                 __delay_ms(150);
    86.                 __delay_ms(150);
    87.                 __delay_ms(150);
    88.                 __delay_ms(100);
    89.             }
    90.                
    91.         if (ROW_2 = 0)                              //if ROW 2 is LOW...
    92.             {                                       //...
    93.                 lcd_clear();                        //...      
    94.                 lcd_goto(0);                        //...
    95.                 lcd_puts("Switch 4");               //Display "Switch 4"
    96.                 __delay_ms(150);           
    97.                 __delay_ms(150);
    98.                 __delay_ms(150);
    99.                 __delay_ms(150);
    100.                 __delay_ms(150);
    101.                 __delay_ms(150);
    102.                 __delay_ms(100);
    103.             }
    104.         if (ROW_3 = 0)                              //If ROW 3 is LOW
    105.             {                                       //...
    106.                 lcd_clear();                        //...
    107.                 lcd_goto(0);                        //...
    108.                 lcd_puts("Switch 7");               //Display "Switch 7"
    109.                 __delay_ms(150);
    110.                 __delay_ms(150);
    111.                 __delay_ms(150);
    112.                 __delay_ms(150);
    113.                 __delay_ms(150);
    114.                 __delay_ms(150);
    115.                 __delay_ms(100);
    116.             }
    117.         if (ROW_4 = 0)                              //If ROW 4 is LOW
    118.             {                                       //...
    119.                 lcd_clear();                        //...
    120.                 lcd_goto(0);                        //...
    121.                 lcd_puts("Switch 10");              //Display "Switch 10"
    122.                 __delay_ms(150);
    123.                 __delay_ms(150);
    124.                 __delay_ms(150);
    125.                 __delay_ms(150);
    126.                 __delay_ms(150);
    127.                 __delay_ms(150);
    128.                 __delay_ms(100);
    129.             }
    130.     }
    131. }
    132.  
    133.  
    What happens when I run this code is that it constantly scrolls through the switches on LCD -- Switch 1, Switch 4 etc. with 1 second delays. Then when I push a switch (say switch 1) it skips that switch -- goes from switch 10 to switch 4 when it scrolls. So It is reading the push, just isn't displaying it right.
     
  11. beeson76

    Thread Starter Member

    Apr 19, 2010
    185
    1
    Thanks Alberto for the reply. I will look into what you suggested.

    Here is what I have, and it seems to work great. I am going to try to make it more efficient code now, maybe incorporating some macros and functions in it.

    Code ( (Unknown Language)):
    1.  
    2. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3. //
    4. //This program controls a Matrix Switch.  The Switch consists of 3 columns and 4 rows.
    5. //Whenever a switch is pushed, that switches name is displayed on an LCD Display.
    6. //The PIC16F886 Microcontroller from Microchip is being used.
    7. //2x16 LCD Display being used
    8. //
    9. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    10.  
    11. #include <htc.h>
    12. #include "lcd.h"
    13.  
    14. #define COL_1           RB0
    15. #define COL_2           RB1
    16. #define COL_3           RB7
    17. #define ROW_1           RB3
    18. #define ROW_2           RB4
    19. #define ROW_3           RB5
    20. #define ROW_4           RB6
    21. #define  DelayS(T)      {unsigned char i; for (i = 0; i < T * 10; i++) __delay_ms(100);}    //Delay Macro
    22. #define  _XTAL_FREQ             4000000                             //Needs to be set for __delay_ms
    23.  
    24.  
    25. //Master Clear Reset enabled & Internal RC No Clock & Watchdog Timer Disable & Power Up Timer On & Brown Out Reset Disabled &
    26. // Low Voltage Porgramming Disabled & Code Unprotect
    27. __CONFIG (MCLREN & INTIO & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT);
    28.  
    29. main()
    30. {
    31.    
    32. PORTA = 0x00;                                       //PORTA is cleared and set low
    33. PORTB = 0xFF;                                       //(0b11111111 binary) (0xFF hex)--ROWS set to HIGH, COLUMNS set to HIGH  
    34.                                                     //PORTB7:B0 is set to high,high,high,high,high,high,high,high
    35.                                                    
    36. PORTC = 0x00;                                       //PORTC is cleared and set low
    37. TRISA = 0x00;                                       //Set PORTA to outputs for LCD--RA1, RA2, RA4 are Control lines for LCD
    38.  
    39. TRISB = 0x7C;                                       //(0b01111100 binary) (0x7C hex)--ROWS set to INPUT, COLUMNS set to OUTPUT
    40.                                                     //PORTB7:B0 is set to output,input,input,input,input,input,output,output,
    41.                                                     //ROWS set to INPUT
    42.  
    43. TRISC = 0x00;                                       //Set PORTC to outputs for LCD--RC0:RC3 are Data Lines for LCD
    44.  
    45.  
    46. ANSEL = 0;                                          //Initialize A/D Ports off
    47. ANSELH = 0;                                         //Initialize ........
    48. CM1CON0 = 0;                                        //Initialize Comparator 1 off
    49. CM2CON0 = 0;                                        //Initialize Comparator 2 off
    50.  
    51. OPTION = 0b01010101;                                //OPTION REG
    52.                                                     //xbxxxxx101  1:64
    53.                                                     //xbxxxx0xxx  Prescaler set to Timer0
    54.                                                     //xbxxx1xxxx  (T0SE) set to Increment on high-to-low transition on T0CKI pin
    55.                                                     //xbxx0xxxxx  (T0CS) Internal instruction cycle clock
    56.                                                     //xbx1xxxxxx  (INTEDG) Interrupt on rising edge of INT pin
    57.                                                     //xb0xxxxxxx  (RBPU) PORTB pull-ups are enabled by individual PORT latch values
    58. RBPU = 0;                                           //Don't think I need this, but to be safe...PORTB Weak Internal Pullups enabled
    59. WPUB0 = 0;                                          //COL_1 Weak pullup is individually DISABLED--OUTPUT
    60. WPUB1 = 0;                                          //COL_2 Weak Pullup is inidivdually DISABLED--OUTPUT
    61. WPUB2 = 0;                                          //Not being used...Weak Pullup is individually DISABLED
    62. WPUB3 = 1;                                          //ROW_1 Weak Pullup is individually ENABLED--INPUT
    63. WPUB4 = 1;                                          //ROW_2 Weak Pullup is individually ENABLED--INPUT
    64. WPUB5 = 1;                                          //ROW_3 Weak Pullup is individually ENABLED--INPUT
    65. WPUB6 = 1;                                          //ROW_4 Weak Pullup is individually ENABLED--INPUT
    66. WPUB7 = 0;                                          //COL_3 Weak Pullup is individually DISABLED--INPUT
    67.  
    68.  
    69. lcd_init();                                         //LCD Display is Initialized...See LCD.C file and LCD.h
    70.  
    71. while (1)
    72.     {
    73.         lcd_clear;                                  //Clear LCD
    74.         lcd_goto(0);                                //Go to Line 1 Position 1
    75.         lcd_puts("Matrix Switch");                  //Display "Matrix Switch"
    76.         lcd_goto(40);                               //Go to Line 2 Position 1
    77.         lcd_puts("Press Button");                   //Display "Press Button"
    78.        
    79.         COL_1 = 0;                                  //COLUMN 1 is set LOW
    80.         if (ROW_1 == 0)                             //and If ROW 1 is LOW...
    81.             {                                       //...
    82.                 lcd_clear();                        //...
    83.                 lcd_goto(0);                        //...
    84.                 lcd_puts("Switch 1");               //Display "Switch 1"
    85.                 __delay_ms(150);
    86.                 __delay_ms(150);
    87.                 __delay_ms(150);
    88.                 __delay_ms(150);
    89.                 __delay_ms(150);
    90.                 __delay_ms(150);
    91.                 __delay_ms(100);
    92.             }
    93.                
    94.         if (ROW_2 == 0)                             //if ROW 2 is LOW...
    95.             {                                       //...
    96.                 lcd_clear();                        //...      
    97.                 lcd_goto(0);                        //...
    98.                 lcd_puts("Switch 4");               //Display "Switch 4"
    99.                 __delay_ms(150);           
    100.                 __delay_ms(150);
    101.                 __delay_ms(150);
    102.                 __delay_ms(150);
    103.                 __delay_ms(150);
    104.                 __delay_ms(150);
    105.                 __delay_ms(100);
    106.             }
    107.         if (ROW_3 == 0)                             //If ROW 3 is LOW
    108.             {                                       //...
    109.                 lcd_clear();                        //...
    110.                 lcd_goto(0);                        //...
    111.                 lcd_puts("Switch 7");               //Display "Switch 7"
    112.                 __delay_ms(150);
    113.                 __delay_ms(150);
    114.                 __delay_ms(150);
    115.                 __delay_ms(150);
    116.                 __delay_ms(150);
    117.                 __delay_ms(150);
    118.                 __delay_ms(100);
    119.             }
    120.         if (ROW_4 == 0)                             //If ROW 4 is LOW
    121.             {                                       //...
    122.                 lcd_clear();                        //...
    123.                 lcd_goto(0);                        //...
    124.                 lcd_puts("Switch 10");              //Display "Switch 10"
    125.                 __delay_ms(150);
    126.                 __delay_ms(150);
    127.                 __delay_ms(150);
    128.                 __delay_ms(150);
    129.                 __delay_ms(150);
    130.                 __delay_ms(150);
    131.                 __delay_ms(100);
    132.             }
    133.            
    134.         COL_1 = 1;                                  //COLUMN 1 is set HIGH again
    135.         COL_2 = 0;                                  //COLUMN 2 is set LOW
    136.         if (ROW_1 == 0)                             //and If ROW 1 is LOW...
    137.             {                                       //...
    138.                 lcd_clear();                        //...
    139.                 lcd_goto(0);                        //...
    140.                 lcd_puts("Switch 2");               //Display "Switch 2"
    141.                 __delay_ms(150);
    142.                 __delay_ms(150);
    143.                 __delay_ms(150);
    144.                 __delay_ms(150);
    145.                 __delay_ms(150);
    146.                 __delay_ms(150);
    147.                 __delay_ms(100);
    148.             }
    149.                
    150.         if (ROW_2 == 0)                             //if ROW 2 is LOW...
    151.             {                                       //...
    152.                 lcd_clear();                        //...      
    153.                 lcd_goto(0);                        //...
    154.                 lcd_puts("Switch 5");               //Display "Switch 5"
    155.                 __delay_ms(150);           
    156.                 __delay_ms(150);
    157.                 __delay_ms(150);
    158.                 __delay_ms(150);
    159.                 __delay_ms(150);
    160.                 __delay_ms(150);
    161.                 __delay_ms(100);
    162.             }
    163.         if (ROW_3 == 0)                             //If ROW 3 is LOW
    164.             {                                       //...
    165.                 lcd_clear();                        //...
    166.                 lcd_goto(0);                        //...
    167.                 lcd_puts("Switch 8");               //Display "Switch 8"
    168.                 __delay_ms(150);
    169.                 __delay_ms(150);
    170.                 __delay_ms(150);
    171.                 __delay_ms(150);
    172.                 __delay_ms(150);
    173.                 __delay_ms(150);
    174.                 __delay_ms(100);
    175.             }
    176.         if (ROW_4 == 0)                             //If ROW 4 is LOW
    177.             {                                       //...
    178.                 lcd_clear();                        //...
    179.                 lcd_goto(0);                        //...
    180.                 lcd_puts("Switch 11");              //Display "Switch 11"
    181.                 __delay_ms(150);
    182.                 __delay_ms(150);
    183.                 __delay_ms(150);
    184.                 __delay_ms(150);
    185.                 __delay_ms(150);
    186.                 __delay_ms(150);
    187.                 __delay_ms(100);
    188.             }
    189.         COL_2 = 1;                                  //COLUMN 2 is set HIGH again
    190.         COL_3 = 0;                                  //COLUMN 3 is set LOW
    191.         if (ROW_1 == 0)                             //and If ROW 1 is LOW...
    192.             {                                       //...
    193.                 lcd_clear();                        //...
    194.                 lcd_goto(0);                        //...
    195.                 lcd_puts("Switch 3");               //Display "Switch 3"
    196.                 __delay_ms(150);
    197.                 __delay_ms(150);
    198.                 __delay_ms(150);
    199.                 __delay_ms(150);
    200.                 __delay_ms(150);
    201.                 __delay_ms(150);
    202.                 __delay_ms(100);
    203.             }
    204.                
    205.         if (ROW_2 == 0)                             //if ROW 2 is LOW...
    206.             {                                       //...
    207.                 lcd_clear();                        //...      
    208.                 lcd_goto(0);                        //...
    209.                 lcd_puts("Switch 6");               //Display "Switch 6"
    210.                 __delay_ms(150);           
    211.                 __delay_ms(150);
    212.                 __delay_ms(150);
    213.                 __delay_ms(150);
    214.                 __delay_ms(150);
    215.                 __delay_ms(150);
    216.                 __delay_ms(100);
    217.             }
    218.         if (ROW_3 == 0)                             //If ROW 3 is LOW
    219.             {                                       //...
    220.                 lcd_clear();                        //...
    221.                 lcd_goto(0);                        //...
    222.                 lcd_puts("Switch 9");               //Display "Switch 9"
    223.                 __delay_ms(150);
    224.                 __delay_ms(150);
    225.                 __delay_ms(150);
    226.                 __delay_ms(150);
    227.                 __delay_ms(150);
    228.                 __delay_ms(150);
    229.                 __delay_ms(100);
    230.             }
    231.         if (ROW_4 == 0)                             //If ROW 4 is LOW
    232.             {                                       //...
    233.                 lcd_clear();                        //...
    234.                 lcd_goto(0);                        //...
    235.                 lcd_puts("Switch 12");              //Display "Switch 12"
    236.                 __delay_ms(150);
    237.                 __delay_ms(150);
    238.                 __delay_ms(150);
    239.                 __delay_ms(150);
    240.                 __delay_ms(150);
    241.                 __delay_ms(150);
    242.                 __delay_ms(100);
    243.             }
    244.         COL_3 = 1;                                  //COLUMN 3 is set HIGH again
    245.     }
    246. }
    247.  
    If you see anything that needs to be changed, please let me know. Hopefully this code can be of use to someone who needs a place to start. Thanks again for all the help.
     
Loading...