Help in ports configuration

Discussion in 'Programmer's Corner' started by FZA, Jul 31, 2007.

  1. FZA

    Thread Starter New Member

    Jul 31, 2007
    5
    0
    Hi i am using C8051F226 to program a 8x2 LCD in C language... I am using Port 3.0-3.7 to DB0-DB7 (Data Bus pins),Port 2.5 for RS ( Register Select pin),Port 2.6 for RW (Read/Write pin) and Port 2.7 for E (Enable pin)...I need help in configuring the ports..My LCD keep on displaying "rows of square dots" even though i had already initialize it...Below is how i configure the ports...I am just wondering whether I am configuring the ports correctly? It would be grateful if you guys can tell me.
    Thanks.


    // Configure the PRTnMX Registers
    PRT0MX = 0x00; // PRT0MX: Initial Reset Value
    PRT1MX = 0x00; // PRT1MX: Initial Reset Value
    PRT2MX = 0x00; // PRT2MX: Initial Reset Value

    // Port configuration (1 = Push Pull Output)
    PRT0CF = 0x00; // Output configuration for P0
    PRT1CF = 0x00; // Output configuration for P1
    PRT2CF = 0x00; // Output configuration for P2
    PRT3CF = 0xFF; // Output configuration for P3

    P0MODE = 0xFF; // Input configuration for P0
    P1MODE = 0xFF; // Input configuration for P1
    P2MODE = 0xFF; // Input configuration for P2
    P3MODE = 0xFF; // Input configuration for P3
     
  2. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Could you post the schematic of your hook ups from your ports and which LCD module you are using?
     
  3. FZA

    Thread Starter New Member

    Jul 31, 2007
    5
    0
    I don't really have a schematic of my hook ups from my ports... Below i have pdf files on the attachments of the pin assignment of the LCD and you can find the schematic of the C8051F226 target board in the C8051F2xx-DK.pdf ... The way I connected the LCD to the 8051 is something like in the picture that I had attached...I am using PC0802-A LCD from Powertip.
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Here is a good link to LCD INFO that may be helpful...

    One thing that can cause the dark squares is that the contrast setting is misadjusted. You may want to try turning the contrast control down.

    hgmjr
     
  5. FZA

    Thread Starter New Member

    Jul 31, 2007
    5
    0
    Ok i have already turned down the contrast down and the LCD did display but not the things that i want...Sometimes my LCD will not display anything and sometimes it will display something but it may take some time to display... Also it will display things like for eg. i wanted to display 'hi" on my LCD instead it display some letters,spreading all over the LCD...
     
  6. ajay_bhargav

    New Member

    May 9, 2007
    5
    0
    well usually the LCD doesn't get initialized properly, rather the internal reset circuit initialize it. Must check your program... and see if you are giving enough time for resetting the LCD or not..

    this might help you..
    http://www.8051projects.net/lcd-interfacing/
     
  7. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Maybe you could configure the control pins as push/pull instead of relying on the weak pullups.
     
  8. FZA

    Thread Starter New Member

    Jul 31, 2007
    5
    0
    So which ports should i configure in my case?
     
  9. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    P2^5 , P2^6 & P2^7
     
  10. ajay_bhargav

    New Member

    May 9, 2007
    5
    0
    @FZA can i see your program? i mean complete program..
     
  11. FZA

    Thread Starter New Member

    Jul 31, 2007
    5
    0
    These are my program:

    Code ( (Unknown Language)):
    1. //-----------------------------------------------------------------------------
    2. // Includes
    3. //-----------------------------------------------------------------------------
    4. #include <c8051F200.h>
    5. #include <string.h>
    6. #include <stdio.h>
    7. #include <stdlib.h>
    8. //-----------------------------------------------------------------------------
    9. // Global CONSTANTS
    10. //-----------------------------------------------------------------------------
    11.     unsigned int q;
    12.  
    13.     sbit RS = P2^5;     // RS (Register Select) for Port 2.5
    14.     sbit RW = P2^6;     // RW for Port 2.6
    15.     sbit E = P2^7;      // Enable for Port 2.7
    16.  
    17.     sbit DB0 = P3^0;    //DB = Data bus
    18.     sbit DB1 = P3^1;
    19.     sbit DB2 = P3^2;
    20.     sbit DB3 = P3^3;
    21.     sbit DB4 = P3^4;
    22.     sbit DB5 = P3^5;
    23.     sbit DB6 = P3^6;
    24.     sbit DB7 = P3^7;
    25.  
    26. //-----------------------------------------------------------------------------
    27. // Function PROTOTYPES
    28. //-----------------------------------------------------------------------------
    29. void config(void);
    30. void delay (unsigned int duration);
    31. void enable();
    32. void lcdinit (void);
    33. void command(unsigned char m);
    34. void print(unsigned char k);
    35. void hi();
    36.  
    37. //------------------------------------------------------------------------------------
    38. // Generating Delay
    39. //------------------------------------------------------------------------------------
    40. void delay (unsigned int duration)
    41. {
    42.    while (duration--!=0);
    43. }
    44.  
    45. //------------------------------------------------------------------------------------
    46. // Enable
    47. //------------------------------------------------------------------------------------
    48. void enable()
    49. {
    50.     E = 1;
    51.     delay(100);
    52.     E = 0;
    53.     delay(100);
    54. }
    55.  
    56. //------------------------------------------------------------------------------------
    57. // Initialize LCD
    58. //------------------------------------------------------------------------------------
    59. void lcdinit(void)
    60. {
    61.  
    62.         E = 0;
    63.         RS = 0;
    64.         RW = 0;
    65.  
    66.   P3 = 0x38;         //Function Set (8 bits,2 lines,5x7 fonts)
    67.   enable();    
    68.   P3 = 0x08;    //Off Display
    69.   enable();
    70.   P3 = 0x06;    //Entry Mode (increment cursor,no shift display)                                          
    71.   enable();    
    72.   P3 = 0x01;    // Clear Display
    73.   enable();
    74.   P3 = 0x0C;    //Display On
    75.   enable();
    76. }
    77.  
    78. //------------------------------------------------------------------------------------
    79. // Command Character to LCD
    80. //------------------------------------------------------------------------------------
    81. void command(unsigned char m)
    82. {
    83.     P3 = m;
    84.     RS = 0;
    85.     RW = 0;
    86.     enable();
    87. }
    88.  
    89. //------------------------------------------------------------------------------------
    90. // Print Character to LCD
    91. //------------------------------------------------------------------------------------
    92. void print(unsigned char k)    
    93. {
    94.     P3 = k;
    95.     RS = 1;
    96.     RW = 0;
    97.     enable();  
    98. }
    99.  
    100. //------------------------------------------------------------------------------------
    101. // Array for printing "HI"
    102. //------------------------------------------------------------------------------------
    103. void hi()
    104. {
    105.     unsigned char words[] = "hi";
    106.     for(q=0;q<3;q++)    //3 character stored
    107.     {
    108.         print(words[q]);
    109.     }
    110. }
    111.  
    112.  
    113. //-----------------------------------------------------------------------------
    114. // MAIN Routine
    115. //-----------------------------------------------------------------------------
    116.  
    117. void main()
    118. {
    119.   config();
    120.  
    121.   lcdinit();    //Initialize LCD
    122.   command(0x80);
    123.   hi();
    124.   delay(500000);
    125. }      
     
  12. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,790
    I don't think 8051's have push-pull outputs. Quasi-bidirectional is alll you get chum.
     
  13. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Do you mean quasi-bidirectional as in there is a weak pull-up always enabled?


    That is true of the older 8051s but Silabs (and others) have push-pull outputs available (along with many other enhancements).

    please see:

    8051 "bible"
    http://www.nxp.com/acrobat_download/various/80C51_FAM_HARDWARE_1.pdf

    and

    OP's device datasheet
    http://www.silabs.com/public/documents/tpub_doc/dsheet/Microcontrollers/Small_Form_Factor/en/C8051F2xx.pdf

    You'll probably agree they've come a long way :)

    John
     
Loading...