Discussion in "Project Help" started by    PsySc0rpi0n    Nov 27, 2014.
Thu Nov 27 2014, 08:00 pm
#1
Hi...

I'm new in forum and with programming 8051 compatible micro controllers.
I'm studying Electrotecnics Engineering and one of my classes is "Micro Controllers".

We have to build a project until the end of the academic semester. The project is to build a small game that uses an LCD (HD44780), a 4 character LCD to show the score and a set of 5 switches that will handle movement (up, down, left, right and difficulty level set).

The difficulty level will be selected upon the transition state of pin P3_4 which will be connected to a switch. So, when the user wants to play in basic mode, will let the switch open. If he wants to play in advanced mode, he will close the switch.
The question is, how do I check when a transition occurs in this pin, using C language?


[ Edited Thu Nov 27 2014, 08:35 pm ]
Fri Nov 28 2014, 10:14 am
#2
You can read status of pin before starting the game. Here is an example for reading port pin:
/* say we want to read P0.1 */
char pin;

pin = P0_1;
/* now pin has status value */
/* 1 - for high, 0 for low */

If you do not want to use a variable then, you can also use simple if loop like this:
if (P0_1) {
    /* Pin is high */
} else {
    /* Pin is low */
}
Fri Nov 28 2014, 12:35 pm
#3
Good morning. Thanks for replying.

The problem in that is that there is the possibility that the user doesn't have to turn On or Off the switch.

My idea was to wait until user choose a level or be able to continue with the current selection.
The code I already have, initiates the LCD, then shows 2 messages (the game's name and the game's authors) and then builds the custom characters in the CGRAM. The next step would be to ask the user which level he wants to play. Basic or Advanced. It's this step I need to implement. Like this:
1st: Show the message "Basic or Advanced?"
2nd: Wait for for the user to press the switch in P3_4 or let the user use the current level (the current s witch's state).

Note1: Yet 2 interrupts are available to use.
Note2: I'm using the MCU 8051 Ide with SDCC compiler.


[ Edited Fri Nov 28 2014, 12:48 pm ]
Mon Dec 01 2014, 01:05 am
#4
I need some help again...

The above task will be addressed later when I have a bit more ahead in the project codding.

I have created a few custom chars in CGRAM and already sent 2 of them into DDRAM of LCD. Now I need to know how to move one towards the other. Is there any dynamic process to do it? Like shifting bits right/left of the current char address I want to move????
Tue Dec 02 2014, 01:19 am
#5


I have created a few custom chars in CGRAM and already sent 2 of them into DDRAM of LCD. Now I need to know how to move one towards the other. Is there any dynamic process to do it? Like shifting bits right/left of the current char address I want to move????

PsySc0rpi0n


As far as I know CGRAM patterns can only be used the same way as
inbuilt chars, either displayed or not.

Each game character needs two patterns in CGRAM for every
left/right shift
Display them in pairs, to give the effect of a smooth movement.


The next step would be to ask the user which level he wants to play. Basic or Advanced. It's this step I need to implement. Like this:
1st: Show the message "Basic or Advanced?"
2nd: Wait for for the user to press the switch in P3_4 or let the user use the current level (the current s witch's state).

PsySc0rpi0n


Perhaps something like this.
If the user does not select "Advanced" mode within a few seconds
it defaults to basic.
int selectLevel()
{
  int count=500;  //set 5 second timeout
  print ("Press button for Advanced mode");
  while (count--)  //count down timeout
  {
   shortdelay()  // say 10 milliseconds
   if(button)
      break;
  }
           //return 0 for basic, none zero for Advanced
  return count;  
}




[ Edited Tue Dec 02 2014, 01:32 am ]
Tue Dec 02 2014, 02:10 am
#6
Thanks for replying...

I have used a ternary operator instead of using whiles and ifs. I think it's a bit faster

Here's how I did it:

#define GL P3_4

__bit set_game_level (void){
    return GL ? 0:1;
}


Now I need to know how to move chars around the LCD. I need to make the bullet move towards the target in the other corner of the LCD.
Any ideas?


[ Edited Tue Dec 02 2014, 02:18 am ]
Tue Dec 02 2014, 02:55 am
#7


Now I need to know how to move chars around the LCD. I need to make the bullet move towards the target in the other corner of the LCD.
Any ideas?

PsySc0rpi0n



Sorry, I have no experience in LCD graphics, so no ideas.
Even my last post might be wrong



I have used a ternary operator instead of using whiles and ifs. I think it's a bit faster

Here's how I did it:

#define GL P3_4

__bit set_game_level (void){
    return GL ? 0:1;
}

PsySc0rpi0n



It's aways good to try new things, but speed is not important for this
button press.
Ternary operators don't always create faster code, it depends on the
compiler.
In this case I'm not sure what it achieves as GL is seen as 0 or 1
and your routine returns 0 or 1.
Tue Dec 02 2014, 06:26 am
#8



Now I need to know how to move chars around the LCD. I need to make the bullet move towards the target in the other corner of the LCD.
Any ideas?

PsySc0rpi0n



Sorry, I have no experience in LCD graphics, so no ideas.
Even my last post might be wrong



I have used a ternary operator instead of using whiles and ifs. I think it's a bit faster

Here's how I did it:

#define GL P3_4

__bit set_game_level (void){
    return GL ? 0:1;
}

PsySc0rpi0n



It's aways good to try new things, but speed is not important for this
button press.
Ternary operators don't always create faster code, it depends on the
compiler.
In this case I'm not sure what it achieves as GL is seen as 0 or 1
and your routine returns 0 or 1.

ExperimenterUK



Well, maybe you're right. Need to look once again at the code. Tomorrow I'll do it.
Thanks for your help.

Psy
Tue Dec 02 2014, 10:44 am
#9
As your lcd has a fixed size then I suggest to use a local buffer for it and fill data in the buffer then flush the buffer on lcd. Its the same technique used in linux framebuffers too. The best thing about this method is you can manipulate lcd buffer with data you want and you dont have to worry about what was the last state of lcd. Hope you get my idea.
Tue Dec 02 2014, 12:35 pm
#10


As your lcd has a fixed size then I suggest to use a local buffer for it and fill data in the buffer then flush the buffer on lcd. Its the same technique used in linux framebuffers too. The best thing about this method is you can manipulate lcd buffer with data you want and you dont have to worry about what was the last state of lcd. Hope you get my idea.

ajay_bhargav



You mean to set a block of memory aside (of the same size as LCD) and perform all motion actions in memory and then send them to the LCD?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am