Help:embedded programming 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 8255 with 8051 in address of 4000H.
    also connected keypad [4*4] in port c of 8255.
    We can use port c of 8255 into 2 parts using to set control word to MODE0
    1) PC0 - PC3
    2) PC4 - PC7

    While programming(Embedded C) how can i accessing the 2 parts of Port c individually?
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,339
    1,021
  3. 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..:)

    __________


    #include<reg51.h>
    #define sec 100
    char xdata lcdctr _at_ 0x4001;
    char xdata dataport _at_ 0x4000;
    char xdata keyr _at_ 0x4002;
    char xdata keyc _at_ 0x8001;
    xdata cw[4003]=0x88;
    xdata cw2[8003]=0x92;

    void delay(unsigned int msec) //Time delay function
    {
    int i,j ;
    for(i=0;i<msec;i++)
    for(j=0;j<1275;j++);
    }

    void lcd_cmd(unsigned char item) //Function to send command to LCD
    {
    dataport = item;
    lcdctr=0x04;
    delay(1);
    lcdctr=0x00;
    return;
    }

    void lcd_data(unsigned char item) //Function to send data to LCD
    {
    dataport = item;
    lcdctr=0x05;

    delay(1);
    lcdctr=0x01;
    return;
    }



    void lcd_data_string(unsigned char *str) // Function to send string on LCD
    {
    int i=0;
    while(str!='\0')
    {
    lcd_data(str);
    i++;
    delay(10);
    }
    return;
    }

    void lcd(unsigned char str[16]) // Funtion to Initialize LCD
    {
    lcd_cmd(0x38);
    lcd_cmd(0x0e);
    //delay(sec);
    lcd_cmd(0x01);
    //delay(sec);
    lcd_cmd(0x82);
    //delay(sec);
    lcd_data_string(str);
    }

    void display(int a) //Display functon for LCD

    {
    switch(a)
    {
    case 1:lcd("one 1");
    break;
    case 2:lcd("two 2");
    break;
    case 3:lcd("three 3");
    break;
    case 4:lcd("four 4");
    break;
    case 5:lcd("five 5");
    break;
    case 6:lcd("six 6");
    break;
    case 7:lcd("seven 7");
    break;
    case 8:lcd("EIGHT 8");
    break;
    case 9:lcd("NINE 9");
    break;
    case 0:lcd("ZERO 0");
    break;
    case 11:lcd("*");
    break;
    case 12:lcd("#");
    break;

    }
    }

    void check_col1() //Function for checking column one
    {
    int temp;//row1=row2=row3=row4=1;
    keyr=0xff;

    keyr=0xfe;//row1=0;
    temp=0x10&keyc;
    if(temp==0x00)//if(col1==0)
    {display(1);return;}

    //row1=1;
    keyr=0xfd;//row2=0;
    temp=0x10&keyc;//keyc*=0x10;
    if(temp==0x00)//if(col1==0)
    display(4);
    //row2=1;
    keyr=0xfb;//row3=0;
    temp=0x10&keyc;//keyc*=0x10;
    if(temp==0x00)//if(col1==0)
    display(7);
    keyr=0xf7;
    //row3=1;
    //row4=0;
    temp=0x10&keyc;//keyc*=0x10;
    if(temp==0x00)//if(col1==0)
    display(11);
    keyr=0xff;//row4=1;
    }

    void check_col2() //Function for checking column two
    {
    int temp;
    keyr=0xff;

    keyr=0xfe;//row1=0;
    temp=0x20&keyc;//keyc*=0x20;
    if(temp==0x00)//if(col1==0)
    display(1);
    //row1=1;
    keyr=0xfd;//row2=0;
    temp=0x20&keyc;//keyc*=0x20;
    if(temp==0x00)//if(col1==0)
    display(4);
    //row2=1;
    keyr=0xfb;//row3=0;
    temp=0x20&keyc;//keyc*=0x20;
    if(temp==0x00)//if(col1==0)
    display(7);
    keyr=0xf7;
    //row3=1;
    //row4=0;
    temp=0x20&keyc;//keyc*=0x20;
    if(temp==0x00)//if(col1==0)
    display(11);
    keyr=0xff;
    }

    void check_col3() //Function for checking column three
    {
    int temp;
    keyr=0xff;

    keyr=0xfe;//row1=0;
    temp=0x40&keyc;//keyc*=0x40;
    if(temp==0x00)//if(col1==0)
    display(1);
    //row1=1;
    keyr=0xfd;//row2=0;
    temp=0x40&keyc;//keyc*=0x40;
    if(temp==0x00)//if(col1==0)
    display(4);
    //row2=1;
    keyr=0xfb;//row3=0;
    temp=0x40&keyc;//keyc*=0x40;
    if(temp==0x00)//if(col1==0)
    display(7);
    keyr=0xf7;
    //row3=1;
    //row4=0;
    temp=0x40&keyc;//keyc*=0x40;
    if(temp==0x00)//if(col1==0)
    display(11);
    keyr=0xff;
    }

    void main()
    {
    //display(13);
    //col1=col2=col3=1; //Input Port
    while(1)
    {
    int temp;
    keyr=0x00;//row1=row2=row3=row4=0;
    temp=0x10&keyc;//keyc*=0x10;
    if(temp==0x00)
    check_col1();
    else
    {
    temp=0x20&keyc;//keyc*=0x20;
    if(temp==0x00)
    check_col2();
    else
    {
    temp=0x40&keyc;//keyc*=0x40;
    if(temp==0x00)
    check_col3();
    }
    }
    }

    }
     
Loading...