Help!! LCD Problem..no character display..

Discussion in 'Embedded Systems and Microcontrollers' started by edski, Jan 18, 2011.

  1. edski

    Thread Starter Member

    Sep 22, 2010
    65
    0
    kindly help..i've been facing this problem for about 2 weeks. still i can't figure out. im using the PIC16F877A, IT works fine when i run it in simulator, but in actual only the 16 blocks of lcd appears. there's no character..here's my circuit http://img262.imageshack.us/i/uploadck.png/
    and my code
    Code ( (Unknown Language)):
    1.  
    2. // initialize function prototypes
    3. void initializePorts();
    4. void initializeLCD();
    5. void startGame();
    6. int checkForHit();
    7. void updateScore(int playerFlag, int score);
    8. void showWinner(int playerFlag);
    9. int showMenu();
    10.  
    11. // function main
    12. void main() {
    13.  
    14.  *// initialize components
    15.     initializePorts();
    16.     initializeLCD();
    17.  
    18.  *// start program proper
    19.  *do {
    20.  *  startGame();
    21.  * } while( showMenu() );
    22. } // end main
    23.  
    24. // start game proper
    25. void startGame() {
    26.  *int player1Score = 0;
    27.     int player2Score = 0;
    28.     int playerFlag = 1;     // who is playing
    29.     int previousPlayer = 1;
    30.     /*
    31.         1 -> player 1
    32.         2 -> player 2
    33.     */
    34.  
    35.     int yellowCtr = 0, greenCtr = 0, blueCtr = 0, redCtr = 0;
    36.     int hitFlag = 0;
    37.     /*
    38.         1 -> yellow
    39.         2 -> green
    40.         3 -> blue
    41.         4 -> red
    42.         5 -> switch player
    43.     */
    44.  
    45.  *LCD_Cmd(LCD_CLEAR);
    46.  
    47.     do {
    48.  * *hitFlag = 0;
    49.  * *
    50.  * *if( previousPlayer != playerFlag ) {
    51.  * * * *previousPlayer = playerFlag;
    52.  * *        yellowCtr = 0;
    53.  * * * *greenCtr = 0;
    54.  * *        blueCtr = 0;
    55.  * *        redCtr = 0;
    56.  * *        LCD_Cmd(LCD_CLEAR);
    57.  * * * *Lcd_Out(1, 3, "CHANGE PLAYER");
    58.  * * * *Delay_ms(1000);
    59.  * * * *LCD_Cmd(LCD_CLEAR);
    60.  * *}
    61.  * *
    62.  * *updateScore( playerFlag, playerFlag == 1? player1Score: player2Score );
    63.  * *
    64.         hitFlag = checkForHit(); // checks what color has been hit
    65.  
    66.         switch( hitFlag ) {
    67.             case 1:                 // yellow
    68.                 yellowCtr++;
    69.                 break;
    70.             case 2:                 // green
    71.                 greenCtr++;
    72.                 break;
    73.             case 3:                 // blue
    74.                 blueCtr++;
    75.                 break;
    76.             case 4:                 // red
    77.                 redCtr++;
    78.                 break;
    79.             case 5: * * * * * * * * * * * * * * * * *// switch
    80.  * * * *previousPlayer = playerFlag; * * * * * // set previous player
    81.  * * * *playerFlag = playerFlag == 1? 2: 1; * *// switch player
    82.                 continue; *              * * * * * * * * * * // go back to the start of *"do-while" loop
    83.         }
    84.  
    85.         if( yellowCtr >= 2 || greenCtr >= 2 || blueCtr >= 2 || redCtr >= 2 ) {
    86.             switch( playerFlag ) {
    87.                 case 1:
    88.                     player1Score += 5;
    89.                     break;
    90.                 case 2:
    91.                     player2Score += 5;
    92.                     break;
    93.             }
    94.  
    95.  * * *updateScore( playerFlag, playerFlag == 1? player1Score: player2Score );
    96.  
    97.         }
    98.  
    99.     } while( player1Score != 50 && player2Score != 50 ); // check for winner
    100.  
    101.     showWinner( playerFlag );
    102. }
    103.  
    104. void showWinner( int playerFlag ) {
    105.  * * int ctr;
    106.  * * char *line1Text = "";
    107.  * *
    108.  * * switch( playerFlag ) {
    109.  * *        case 1:
    110.  * *            strcpy(line1Text, "PLAYER 1 WINS!");
    111.  * *            break;
    112.  * *        case 2:
    113.  * *            strcpy(line1Text, "PLAYER 2 WINS!");
    114.  * *            break;
    115.  *   }
    116.  
    117.  * * for( ctr = 0; ctr < 7; ctr++ ) {
    118.  * * * * *Lcd_Out(1,2,line1Text);
    119.  * * * * *Delay_ms(400);
    120.  * * * * *LCD_Cmd(LCD_CLEAR);
    121.  * * * * *Delay_ms(400);
    122.  * * }
    123. }
    124.  
    125. int showMenu() {
    126.  * * int hit = 0;
    127.  
    128.  * * LCD_Cmd(LCD_CLEAR);
    129.  * * LCD_Out(1,1, " Press Any Key");
    130.  * * LCD_Out(2,1, " To Start Game");
    131.  
    132.  * * hit = checkForHit();
    133.  
    134.  * * if( hit ) {
    135.  * * * * LCD_Cmd(LCD_CLEAR);
    136.  * * * * return 1;
    137.  * * }
    138.  
    139.  * * return 0;
    140. }
    141.  
    142. void updateScore( int playerFlag, int score ) {
    143.     char *line1Text = "";
    144.     char *line2Text = "";
    145.     char scoreStr[7];
    146.  
    147.     LCD_Cmd(LCD_CLEAR);
    148.  
    149.     switch( playerFlag ) {
    150.         case 1:
    151.             strcpy(line1Text, "Player 1 Score");
    152.             break;
    153.         case 2:
    154.             strcpy(line1Text, "Player 2 Score");
    155.             break;
    156.     }
    157.  
    158.  *IntToStr( score, scoreStr );
    159.  *
    160.     LCD_Out(1,1, line1Text);
    161.     LCD_Out(2,4, scoreStr);
    162.  
    163. }
    164.  
    165. int checkForHit() {
    166.     int hit = 0;
    167.  
    168.     do {
    169.  * *// red
    170.         if ( Button(&PORTD, 0, 100, 0) ) { *// detect one-to-zero transition on RD0 pin
    171.             hit = 4;
    172.         }
    173.  
    174.         //for green
    175.         if ( Button(&PORTD, 1, 100, 0) ) { *// detect one-to-zero transition on RD1 pin
    176.             hit = 2;
    177.         }
    178.  
    179.         //for blue
    180.         if ( Button(&PORTD, 2, 100, 0) ) { *// detect one-to-zero transition on RD2 pin
    181.             hit = 3;
    182.         }
    183.  
    184.         //for yellow
    185.         if ( Button(&PORTD, 3, 100, 0) ) { *// detect one-to-zero transition on RD3 pin
    186.             hit = 1;
    187.         }
    188.  
    189.         //for Switch player button
    190.         if ( Button(&PORTD, 4, 100, 0) ) { *// detect one-to-zero transition on RD4 pin
    191.             hit = 5;
    192.         }
    193.  
    194.     } while( !hit ); // it will just exit if hit != 0
    195.  
    196.     return hit; // return what has been hit
    197. }
    198.  
    199. void initializePorts() {
    200.     TRISB = 0;          // output
    201.      * * * * * * * // initialize PORTB
    202.  
    203.     TRISD = 1;          // input
    204.     PORTD = 0xFF;       // initialize PORTD
    205.  
    206. }
    207.  
    208. void initializeLCD() {
    209.     Lcd_Init(&PORTB); * * * * * * // Lcd initialization with default settings
    210.  
    211.     LCD_Cmd(LCD_CLEAR); * * * * * // Clear display
    212.     LCD_Cmd(LCD_CURSOR_OFF); * * *// Turn cursor off
    213.  *Lcd_Out(1, 4, "Let's Play");
    214.  *Delay_ms(1000);
    215.  *LCD_Cmd(LCD_CLEAR);
    216. }
    217.  
    thanks in advance..
     
  2. Georacer

    Moderator

    Nov 25, 2009
    5,142
    1,266
    I guess that belongs to general electronics or project help... Unless the OP says it's homework.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    If your probelm is with displaying something to the LCD then post some simple code that does that. Something like displaying "Hello World". Please don't expect forum memembers to wade through all of your code that has nothing to do with the problem. A simple program may help you solve the problem on your own.

    Search this forum. This problem has been discussed many, many times.


    Check your suppy volatges on the LCD.

    Single step through your code and make sure all the bits are being set on the LCD the way you expect.

    Check your contrast on VO pin.
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    If you plug in an LCD to power, and give it no initialization or signals, it will be a row of blocks on the top row and a blank bottom row. Sort of a self test thingy.

    Check your wiring on the LCD ports, I'm having issues reading your code due to the number of asterisks.
     
  5. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You're missing a contrast pot on the LCD and 0.1uF decoupling caps.
     
Loading...