embedded c error for 8051 using 8255

Discussion in 'Embedded Systems and Microcontrollers' started by logu_, Apr 4, 2013.

  1. logu_

    Thread Starter New Member

    Apr 3, 2013
    3
    0
    I connected two 8255 ppi to 8051 to accessing keypad and lcd and other modules are connected in that.
    I attached here my schematic diagram and embedded c programming for that.
    while i simulating that i cant find out error.
    Can anyone findout?

    I connected lcd data port with port a of 8255 ppi1
    I connected lcd control signal(wr,rd,cr) port with port b of 8255 ppi1(4000H)
    I connected keypad(4*3) row pins with port c(pc0,pc1,pc2,pc3) of 8255 ppi1(8000H)
    I connected keypad(4*3) column pins with port b(pb4,pb5,pb6) of 8255 ppi1

    BElow is embedded c program for that,

    Thanks in advance..:)

    __________


    Code ( (Unknown Language)):
    1.  
    2. #include<reg51.h>
    3. #define sec 100    
    4. char xdata lcdctr _at_ 0x4001;
    5. char xdata dataport _at_ 0x4000;
    6. char xdata keyr _at_ 0x4002;
    7. char xdata keyc _at_ 0x8001;
    8. xdata cw[4003]=0x88;
    9. xdata cw2[8003]=0x92;
    10.  
    11. void delay(unsigned int msec) //Time delay function
    12. {
    13. int i,j ;
    14. for(i=0;i<msec;i++)
    15.   for(j=0;j<1275;j++);
    16. }
    17.  
    18. void lcd_cmd(unsigned char item)  //Function to send command to LCD
    19. {
    20. dataport = item;
    21. lcdctr=0x04;
    22. delay(1);
    23. lcdctr=0x00;
    24. return;
    25. }
    26.  
    27. void lcd_data(unsigned char item) //Function to send data to LCD
    28. {
    29. dataport = item;
    30. lcdctr=0x05;
    31.  
    32. delay(1);
    33. lcdctr=0x01;
    34. return;
    35. }
    36.  
    37.  
    38.  
    39. void lcd_data_string(unsigned char *str) // Function to send string on LCD
    40. {
    41. int i=0;
    42. while(str[i]!='\0')
    43. {
    44.   lcd_data(str[i]);
    45.   i++;
    46.   delay(10);
    47. }
    48. return;
    49. }
    50.  
    51. void lcd(unsigned char str[16])  // Funtion to Initialize LCD
    52. {
    53. lcd_cmd(0x38);
    54. lcd_cmd(0x0e);
    55. //delay(sec);
    56. lcd_cmd(0x01);
    57. //delay(sec);
    58. lcd_cmd(0x82);
    59. //delay(sec);
    60. lcd_data_string(str);
    61. }  
    62.  
    63. void display(int a) //Display functon for LCD
    64.  
    65. {
    66. switch(a)
    67. {
    68.   case 1:lcd("one 1");
    69.     break;
    70.   case 2:lcd("two 2");
    71.     break;
    72.   case 3:lcd("three 3");
    73.     break;
    74.   case 4:lcd("four 4");
    75.     break;
    76.   case 5:lcd("five 5");
    77.     break;
    78.   case 6:lcd("six 6");
    79.     break;
    80.   case 7:lcd("seven 7");
    81.     break;
    82.   case 8:lcd("EIGHT 8");
    83.     break;
    84.   case 9:lcd("NINE 9");
    85.     break;
    86.   case 0:lcd("ZERO 0");
    87.     break;
    88.   case 11:lcd("*");
    89.     break;
    90.   case 12:lcd("#");
    91.     break;
    92.    
    93. }
    94. }
    95.  
    96. void check_col1() //Function for checking column one
    97. {
    98. int temp;//row1=row2=row3=row4=1;
    99. keyr=0xff;
    100.  
    101. keyr=0xfe;//row1=0;
    102.    temp=0x10&keyc;
    103.   if(temp==0x00)//if(col1==0)
    104. {display(1);return;}
    105.  
    106. //row1=1;
    107. keyr=0xfd;//row2=0;
    108.  temp=0x10&keyc;//keyc*=0x10;
    109.   if(temp==0x00)//if(col1==0)
    110. display(4);
    111. //row2=1;
    112. keyr=0xfb;//row3=0;
    113.  temp=0x10&keyc;//keyc*=0x10;
    114.   if(temp==0x00)//if(col1==0)
    115. display(7);
    116. keyr=0xf7;
    117. //row3=1;
    118. //row4=0;
    119.  temp=0x10&keyc;//keyc*=0x10;
    120.   if(temp==0x00)//if(col1==0)
    121. display(11);
    122. keyr=0xff;//row4=1;
    123. }
    124.  
    125. void check_col2() //Function for checking column two
    126. {
    127. int temp;
    128. keyr=0xff;
    129.  
    130. keyr=0xfe;//row1=0;
    131.    temp=0x20&keyc;//keyc*=0x20;
    132.   if(temp==0x00)//if(col1==0)
    133. display(1);
    134. //row1=1;
    135. keyr=0xfd;//row2=0;
    136.  temp=0x20&keyc;//keyc*=0x20;
    137.   if(temp==0x00)//if(col1==0)
    138. display(4);
    139. //row2=1;
    140. keyr=0xfb;//row3=0;
    141.  temp=0x20&keyc;//keyc*=0x20;
    142.   if(temp==0x00)//if(col1==0)
    143. display(7);
    144. keyr=0xf7;
    145. //row3=1;
    146. //row4=0;
    147.  temp=0x20&keyc;//keyc*=0x20;
    148.   if(temp==0x00)//if(col1==0)
    149. display(11);
    150. keyr=0xff;
    151. }
    152.  
    153. void check_col3() //Function for checking column three
    154. {
    155. int temp;
    156. keyr=0xff;
    157.  
    158. keyr=0xfe;//row1=0;
    159.    temp=0x40&keyc;//keyc*=0x40;
    160.   if(temp==0x00)//if(col1==0)
    161. display(1);
    162. //row1=1;
    163. keyr=0xfd;//row2=0;
    164.  temp=0x40&keyc;//keyc*=0x40;
    165.   if(temp==0x00)//if(col1==0)
    166. display(4);
    167. //row2=1;
    168. keyr=0xfb;//row3=0;
    169.  temp=0x40&keyc;//keyc*=0x40;
    170.   if(temp==0x00)//if(col1==0)
    171. display(7);
    172. keyr=0xf7;
    173. //row3=1;
    174. //row4=0;
    175.  temp=0x40&keyc;//keyc*=0x40;
    176.   if(temp==0x00)//if(col1==0)
    177. display(11);
    178. keyr=0xff;
    179. }
    180.  
    181. void main()
    182. {
    183. //display(13);
    184. //col1=col2=col3=1;  //Input Port
    185. while(1)
    186. {
    187. int temp;
    188.   keyr=0x00;//row1=row2=row3=row4=0;
    189.   temp=0x10&keyc;//keyc*=0x10;
    190.   if(temp==0x00)
    191.   check_col1();
    192.   else
    193.   {
    194.   temp=0x20&keyc;//keyc*=0x20;
    195.    if(temp==0x00)
    196.    check_col2();
    197.    else
    198.    {
    199.    temp=0x40&keyc;//keyc*=0x40;
    200.     if(temp==0x00)
    201.     check_col3();
    202.      }
    203.    }
    204. }
    205.  
    206. }
    207. [/i][/i]
     
    Last edited by a moderator: Apr 7, 2013
  2. Droidrellik

    New Member

    Apr 7, 2013
    2
    0
    C, there is our problem
     
  3. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    If you have connected A0 to the RS pin of the LCD then the Control is at 4000 and the data is on address 4001

    RS = high data, low command
     
    absf likes this.
  4. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    I dont see any schematic....or are you unable to attach it to your post?

    Allen
     
  5. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    You can actually combine the 3x4 keyboard onto port c. The directions of upper & lower nibble can be set separately. There was an example on 8085 addressing the keypad using 8255 not long ago.

    Allen
     
Loading...