4x4 Keypad Issues

Discussion in 'The Projects Forum' started by steveG567, Nov 4, 2008.

  1. steveG567

    Thread Starter New Member

    Nov 4, 2008
    1
    0
    I have written a program in C on a freescale 8 bit micro.

    The code is:


    Code ( (Unknown Language)):
    1.  
    2.   while (column==1)
    3.   {
    4.      
    5.    PTBD = 0xFE;
    6.  
    7.     if (PTBD == 0xEE)
    8.      {
    9.       PTDD = 0x01;
    10.       lcd_delay(2000000);
    11.       PTDD = 0x00;
    12.      }
    13.      
    14.      if (PTBD == 0xDE)
    15.      {
    16.       PTDD = 0x02;
    17.       lcd_delay(2000000);
    18.       PTDD = 0x00;      
    19.      }
    20.      
    21.      
    22.      if (PTBD == 0xBE)
    23.      {
    24.       PTDD = 0x03;
    25.       lcd_delay(2000000);
    26.       PTDD = 0x00;
    27.      }
    28.      
    29.      if (PTBD == (0x7E))
    30.      {    
    31.       PTDD = 0x04;
    32.       lcd_delay(2000000);
    33.       PTDD = 0x00;
    34.      }    
    35.      else column = 2;
    36.   }
    37.  
    38.  
    39.   while (column==2)
    40.   {
    41.      
    42.     PTBD = 0xFD;
    43.  
    44.      
    45.     if (PTBD == 0xED)
    46.      {
    47.       PTDD = 0x05;
    48.       lcd_delay(2000000);
    49.       PTDD = 0x00;
    50.      }
    51.      
    52.      if (PTBD == 0xDD)
    53.      {
    54.       PTDD = 0x06;
    55.       lcd_delay(2000000);
    56.       PTDD = 0x00;      
    57.      }
    58.      
    59.      
    60.      if (PTBD == 0xBD)
    61.      {
    62.       PTDD = 0x07;
    63.       lcd_delay(2000000);
    64.       PTDD = 0x00;
    65.      }
    66.      
    67.      if (PTBD == (0x7D))
    68.      {
    69.       PTDD = 0x08;
    70.       lcd_delay(2000000);
    71.       PTDD = 0x00;
    72.      }
    73.      else column = 3;
    74.   }
    75.        
    76.    
    77.    
    78.    
    79.   while (column==3)
    80.   {
    81.      
    82.     PTBD = 0xFB;
    83.  
    84.      
    85.     if (PTBD == 0xEB)
    86.      {
    87.       PTDD = 0x09;
    88.       lcd_delay(2000000);
    89.       PTDD = 0x00;
    90.      }
    91.      
    92.      if (PTBD == 0xDB)
    93.      {
    94.       PTDD = 0x0A;
    95.       lcd_delay(2000000);
    96.       PTDD = 0x00;      
    97.      }
    98.      
    99.      
    100.      if (PTBD == 0xBB)
    101.      {
    102.       PTDD = 0x0B;
    103.       lcd_delay(2000000);
    104.       PTDD = 0x00;
    105.      }
    106.      
    107.      if (PTBD == (0x7B))
    108.      {
    109.      
    110.       PTDD = 0x0C;
    111.         lcd_delay(2000000);
    112.       PTDD = 0x00;      
    113.      }
    114.      else column = 4;
    115.   }  
    116.  
    117.    
    118.   while (column==4)
    119.   {
    120.      
    121.    PTBD = 0xF7;
    122.  
    123.      
    124.     if (PTBD == 0xE7)
    125.      {
    126.       PTDD = 0x0D;
    127.       lcd_delay(2000000);
    128.       PTDD = 0x00;
    129.      }
    130.      
    131.      if (PTBD == 0xD7)
    132.      {
    133.       PTDD = 0x0E;
    134.       lcd_delay(2000000);
    135.       PTDD = 0x00;      
    136.      }
    137.      
    138.      
    139.      if (PTBD == 0xB7)
    140.      {
    141.       PTDD = 0x0F;
    142.       lcd_delay(2000000);
    143.       PTDD = 0x00;
    144.      }
    145.      
    146.      if (PTBD == (0x77))
    147.      {
    148.       PTDD = 0x10;
    149.       lcd_delay(2000000);
    150.       PTDD = 0x00;
    151.      }    
    152.      else column = 1;
    153.    }
    154.  
    Pins 4,5,6,7 are inputs pulled high
    the rows are outputs pins 0,1,2,3 and polled.


    Now, the 4th column works perfect. The first three dont. When I put an o-scope up to the pull up resistors, I get a voltage drop of around 0.5V, so the votlage is dropping, but not from 5-0V. I have NO IDEA why this is happening. ALl the code seems the same to me, why does column 4 work and not 1,2 or 3??

    Any help would be great.
     
    Last edited by a moderator: Nov 5, 2008
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    A schematic would be most helpful.
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    In addition to a schematic, you will need to post the rest of your source code.

    The value of the variable "column" may be getting unintentionally altered somewhere else in your code.

    hgmjr
     
Loading...