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
thanks in advance..
and my code
Rich (BB code):
// initialize function prototypes
void initializePorts();
void initializeLCD();
void startGame();
int checkForHit();
void updateScore(int playerFlag, int score);
void showWinner(int playerFlag);
int showMenu();
// function main
void main() {
*// initialize components
initializePorts();
initializeLCD();
*// start program proper
*do {
* startGame();
* } while( showMenu() );
} // end main
// start game proper
void startGame() {
*int player1Score = 0;
int player2Score = 0;
int playerFlag = 1; // who is playing
int previousPlayer = 1;
/*
1 -> player 1
2 -> player 2
*/
int yellowCtr = 0, greenCtr = 0, blueCtr = 0, redCtr = 0;
int hitFlag = 0;
/*
1 -> yellow
2 -> green
3 -> blue
4 -> red
5 -> switch player
*/
*LCD_Cmd(LCD_CLEAR);
do {
* *hitFlag = 0;
* *
* *if( previousPlayer != playerFlag ) {
* * * *previousPlayer = playerFlag;
* * yellowCtr = 0;
* * * *greenCtr = 0;
* * blueCtr = 0;
* * redCtr = 0;
* * LCD_Cmd(LCD_CLEAR);
* * * *Lcd_Out(1, 3, "CHANGE PLAYER");
* * * *Delay_ms(1000);
* * * *LCD_Cmd(LCD_CLEAR);
* *}
* *
* *updateScore( playerFlag, playerFlag == 1? player1Score: player2Score );
* *
hitFlag = checkForHit(); // checks what color has been hit
switch( hitFlag ) {
case 1: // yellow
yellowCtr++;
break;
case 2: // green
greenCtr++;
break;
case 3: // blue
blueCtr++;
break;
case 4: // red
redCtr++;
break;
case 5: * * * * * * * * * * * * * * * * *// switch
* * * *previousPlayer = playerFlag; * * * * * // set previous player
* * * *playerFlag = playerFlag == 1? 2: 1; * *// switch player
continue; * * * * * * * * * * * // go back to the start of *"do-while" loop
}
if( yellowCtr >= 2 || greenCtr >= 2 || blueCtr >= 2 || redCtr >= 2 ) {
switch( playerFlag ) {
case 1:
player1Score += 5;
break;
case 2:
player2Score += 5;
break;
}
* * *updateScore( playerFlag, playerFlag == 1? player1Score: player2Score );
}
} while( player1Score != 50 && player2Score != 50 ); // check for winner
showWinner( playerFlag );
}
void showWinner( int playerFlag ) {
* * int ctr;
* * char *line1Text = "";
* *
* * switch( playerFlag ) {
* * case 1:
* * strcpy(line1Text, "PLAYER 1 WINS!");
* * break;
* * case 2:
* * strcpy(line1Text, "PLAYER 2 WINS!");
* * break;
* }
* * for( ctr = 0; ctr < 7; ctr++ ) {
* * * * *Lcd_Out(1,2,line1Text);
* * * * *Delay_ms(400);
* * * * *LCD_Cmd(LCD_CLEAR);
* * * * *Delay_ms(400);
* * }
}
int showMenu() {
* * int hit = 0;
* * LCD_Cmd(LCD_CLEAR);
* * LCD_Out(1,1, " Press Any Key");
* * LCD_Out(2,1, " To Start Game");
* * hit = checkForHit();
* * if( hit ) {
* * * * LCD_Cmd(LCD_CLEAR);
* * * * return 1;
* * }
* * return 0;
}
void updateScore( int playerFlag, int score ) {
char *line1Text = "";
char *line2Text = "";
char scoreStr[7];
LCD_Cmd(LCD_CLEAR);
switch( playerFlag ) {
case 1:
strcpy(line1Text, "Player 1 Score");
break;
case 2:
strcpy(line1Text, "Player 2 Score");
break;
}
*IntToStr( score, scoreStr );
*
LCD_Out(1,1, line1Text);
LCD_Out(2,4, scoreStr);
}
int checkForHit() {
int hit = 0;
do {
* *// red
if ( Button(&PORTD, 0, 100, 0) ) { *// detect one-to-zero transition on RD0 pin
hit = 4;
}
//for green
if ( Button(&PORTD, 1, 100, 0) ) { *// detect one-to-zero transition on RD1 pin
hit = 2;
}
//for blue
if ( Button(&PORTD, 2, 100, 0) ) { *// detect one-to-zero transition on RD2 pin
hit = 3;
}
//for yellow
if ( Button(&PORTD, 3, 100, 0) ) { *// detect one-to-zero transition on RD3 pin
hit = 1;
}
//for Switch player button
if ( Button(&PORTD, 4, 100, 0) ) { *// detect one-to-zero transition on RD4 pin
hit = 5;
}
} while( !hit ); // it will just exit if hit != 0
return hit; // return what has been hit
}
void initializePorts() {
TRISB = 0; // output
* * * * * * * // initialize PORTB
TRISD = 1; // input
PORTD = 0xFF; // initialize PORTD
}
void initializeLCD() {
Lcd_Init(&PORTB); * * * * * * // Lcd initialization with default settings
LCD_Cmd(LCD_CLEAR); * * * * * // Clear display
LCD_Cmd(LCD_CURSOR_OFF); * * *// Turn cursor off
*Lcd_Out(1, 4, "Let's Play");
*Delay_ms(1000);
*LCD_Cmd(LCD_CLEAR);
}