It is currently Fri May 24, 2013 9:08 pm

All times are UTC + 10 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Wed May 25, 2011 5:12 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Thanks for posting that Jay, I forgot my version on Proton Basic comes with a demo version of Proteus :)

Looks like captalex has somewhere to start now for his GLCD project :D


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Thu May 26, 2011 5:45 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
odessa wrote:
Hi,

It works fine in the test code using your Bitmap instead of the truck

There isn't anything in the code you posted there to draw the bitmap

Jay

i've included the whole array into the source file because the compiler wouldnt let me use the #include<eva.c> header.
here is a sample of my code, with the eva.c header added to my c source files.

Code:
unsigned short j,k;
const unsigned short eva_bmp[1024]
void main()
{



ADCON1 = 0x0F;            // Set AN pins to Digital I/O
Glcd_Init(&PORTB, 0, 1, 2, 3, 5, 4, &PORTD);//Glcd_Init_EP4,see Autocomplete//(CONTROL PORT,cs1,cs2,(d/i)/rs),r/w,rst,en,DATAPORT)


     do {

    // Draw circles
    Glcd_Fill(0);  // Clear screen
    Glcd_Write_Text("ALEXISTHEKING",3,20,2);
    j = 4;
      delay_ms(300);
      Glcd_Fill(0);
    while (j < 25) {
      Glcd_Circle(63,25,j,2);
      j += 3;
    }
    delay_ms(40);
                  //draw an image
            Glcd_image(eva_bmp);
            delay_ms(300);


    // Draw Lines
    Glcd_Fill(0);  // Clear screen
    Glcd_Write_Text("HEISBACKRUNCOWRUN",2,10,2);                             //(text,page(0-7),x coordinate,color,0ff,on,invert)

    delay_ms(400);

  } while (1);

}


Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Thu May 26, 2011 7:57 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
bitfogav wrote:
captalex wrote:



finally man!!, bitfogav this is what i have been looking for /trying to do using the mikro C glcd libraries , but i didnt know how. i hope you could help me with porting your code to mikro C using a pic18f4550 and a wg12864b ks0108 based lcd display. and also adding an additional paddle and scoring! hence(pong).



Hi captalex, Im not familiar with mikroC, but looking at your test code, aren't you missing the GLCD librarys Or Headers? and dont you have to include the header file for which microchip you are using?, also I cant test your schematics as I dont have proteus :(

And as for your display backlight not working, all Ive done on mine is connect it up as this, im using a 10k potentiometer going to my 5volt supply and then the other two connections connect directly to the GLCD pin 3 and 18, this is to control the contrast of the display, you also need to connect pins 19 to 5+ and pin 20 to ground to operate the backlight.
Attachment:
GLCD Pot connections.jpg


hey bitfogav, how's the pong game coming. i was hoping that i could get a sneak at your code for movibg the paddles and generating the ball . thanks.


Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Fri May 27, 2011 2:35 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
captalex wrote:
hey bitfogav, how's the pong game coming. i was hoping that i could get a sneak at your code for moving the paddles and generating the ball . thanks.


Hey Alex, sure. ive done it using Swordfish Basic, so it might help if you download the Swordfish SE version which you can get from here http://www.sfcompiler.co.uk/swordfish/download/index.html your probably need the modules that come with Swordfish to understand my code better?. I haven't had much time the last week to do much more with it yet.

Code:
Device = 18F2620                    // select our device
Clock = 32                          // internal 8Mhz * 4 PLL 32Mhz Clock
Config OSC = INTIO67                // configure OSC for internal

// User options
#Option GLCD_MODEL = KS0108         // GLCD driver   
#option GLCD_SCREEN_WIDTH = 128     // Screen Width in Pixels
#option GLCD_SCREEN_HEIGHT = 64     // Screen Height in Pixels
#Option GLCD_DATA = PORTB           // data port
#Option GLCD_RS  = PORTC.0          // RS pin
#Option GLCD_RW  = PORTC.1          // RW pin
#Option GLCD_EN  = PORTC.2          // EN pin
#Option GLCD_CS1 = PORTC.3          // chip select
#Option GLCD_CS2 = PORTC.4          // chip select
#Option GLCD_RST = PORTC.5          // reset pin
#Option GLCD_ASPECT_RATIO = 100     // aspect ratio, smaller number will squeeze y for GLCD circles and box
#Option GLCD_INIT_DELAY = 50        // initialisation delay (ms)
#Option GLCD_INVERT_CS = true       // invert CS lines...

// Modules
Include "glcd.bas"           // main GLCD module
Include "graphics.bas"       // support for GLCD
Include "utils.bas"          // support to make all MCU pins Digital
Include "fixedfont.bas"      // include support for Fonts

// Constants, Variables and Identifiers

Const topScreen    = 2,       // set paddle max travel (top display)
      bottomScreen = 41,      // set paddle max travel (bottom display)
      wall_Left     =  1,     // set left wall position for hit detection   
      wall_Bottom   =  60,    // set bottom wall position for hit detection   
      wall_Top      =  1,     // set top wall position for hit detection 
      ballMissPaddle = 130    // set max value for ball missing paddle

Dim button1 As PORTA.1,   //
    button2 As PORTA.2,   // button pins
    button3 As PORTA.3,   //
    button4 As PORTA.4,   //
    button5 As PORTA.5    //
   
Dim ballX As Byte,        //
    ballY As Byte,        // ball data variables
    ballSize As Word,     //
    ballSpeed As Byte     // ball speed
   
Dim Ball_Hit_Top,         // ball direction booleans
    Ball_Direct_Up,
    Ball_Direct_Left,
    Ball_Hit_Left As Boolean 
   
Dim paddleX1,            //
    paddleY1,            // paddle position data
    paddleX2,            //
    paddleY2 As Byte     //

// Subroutines

Sub init_border()
    GLCD.Line(0,0,127,0)          // draws line (top of screen)
    GLCD.Line(0,0,0,63)           // draws line (left of screen)
    GLCD.Line(0,63,127,63)        // draws line (bottom of screen)
End Sub

Sub init_variables()
    ballX      = 64            // starting position X for ball
    ballY      = 36            // starting position Y for ball
    ballSize   = 2             // ball size fixed
   
    ballSpeed  = 30            // ball speed
   
    Ball_Hit_Top = false          // wall flags
    Ball_Direct_Up   = false      //
    Ball_Direct_Left = false      //
    Ball_Hit_Left    = false      //
   
    paddleX1 = 120          //
    paddleY1 = 15           // starting point of paddle X,Y
    paddleX2 = 121          //
    paddleY2 = 35           //     
End Sub

Sub ball(ballX1 As Word, ballY1 As Word, ballSize1 As Word)   
    GLCD.Square(ballX1,ballY1,ballSize1)   // draw ball on screen X,Y (ball size)
End Sub

Sub ballDirect()
        If Ball_Direct_Left = true Then       // ball direction X
            Dec(ballX)
        Else
            Inc(ballX)
        EndIf
        If Ball_Direct_Up = true Then         // ball direction Y
            Dec(ballY)
        Else
            Inc(ballY)
        EndIf
End Sub

Sub checkWalls()
        If ballX = wall_Left And Ball_Hit_Left = true Then            // check wall left
            Ball_Direct_Left = false
            Ball_Hit_Left = false
        EndIf                         
        If ballY = wall_Top And Ball_Hit_Top = true Then              // check wall top
            Ball_Direct_Up = false
            Ball_Hit_Top = false
        EndIf
        If ballY = wall_Bottom And Ball_Hit_Top = false Then          // check wall bottom
            Ball_Direct_Up = true
            Ball_Hit_Top = true
        EndIf
End Sub

Sub drawBall()
    ball(ballX,ballY,ballSize)      // draw new ball on screen
    SetPixel(ballX+1,ballY+1)       // set pixel in middle of ball
    DelayMS(ballSpeed)               // delay so we see ball on screen, also ball speed
        Pen.Color = 0                 //
        ball(ballX,ballY,ballSize)    // clears ball previous pos (can only be done by deleting pixels)
        Pen.Color = 1                 //
       
    ball(ballX,ballY,ballSize)      // draw new ball on screen
    SetPixel(ballX+1,ballY+1)       // set pixel in middle of ball
    DelayMS(10)                      // delay so we see ball on screen, also ball speed
        Pen.Color = 0                 //
        ball(ballX,ballY,ballSize)    // clears ball previous pos (can only be done by deleting pixels)
        Pen.Color = 1                 //
End Sub

Sub update_paddle1()
        If button2 = 0 And paddleY1 >= topScreen Then           // check button up & check paddle max travel top
            Pen.Color = 0                                        //
            GLCD.Rectangle(paddleX1,paddleY1,paddleX2,paddleY2)  // clear paddle previous data
            Pen.Color = 1                                        //
            paddleY1 = paddleY1 -1                               // set paddle to go up on display
            paddleY2 = paddleY2 -1                               //
            DelayMS(3)                                           // delay to slow down paddle movement
        EndIf
        If button1 = 0 And paddleY1 <= bottomScreen Then        // check button down & check paddle max travel bottom
            Pen.Color = 0                                        //
            GLCD.Rectangle(paddleX1,paddleY1,paddleX2,paddleY2)  // clear paddle previous data
            Pen.Color = 1                                        //
            paddleY1 = paddleY1 +1                               // set paddle to go down on display
            paddleY2 = paddleY2 +1                               //
            DelayMS(3)                                           // delay to slow down paddle movement
        EndIf
        GLCD.Rectangle(paddleX1,paddleY1,paddleX2,paddleY2)     // update our NEW paddle pos data
End Sub

Sub checkBallHitPaddle()
    // check to see if our ball has hit the paddle
    If ballX >= paddleX1-2 And ballX <= paddleX2-2 And ballY >= paddleY1 And ballY <= paddleY2 Then
        Ball_Direct_Left = true           // change ball direction
        Ball_Hit_Left = true              // change ball direction
           
        ElseIf ballX = ballMissPaddle Then     // check to see if ball missed our paddle
       
        // reset game
        init_variables   // setup variables
        GLCD.Cls         // clear display before we start main prog
        init_border      // setup display border
            GLCD.SetFont(Fixed)
            GLCD.WriteAt(8,12,"GLCD")
            GLCD.WriteAt(12,22,"Game")
            GLCD.WriteAt(15,32,"by")
            GLCD.WriteAt(8,42,"bitfogav") 
    EndIf
End Sub

// PORT setup and PLL Multiplier (set internal Osc to 32Mhz)     
TRISA = %00111110               // set PORTA bits 1-5 Inputs (buttons)
TRISB = %00000000               // Set all Ports output
TRISC = %00000000               //
OSCCON = %01111100              // Sets up the internal oscillator for 8Mhz
OSCTUNE.6 = 1                   // Frequency Multiplier PLL for INTOSC Enable bit (Enabled)
                   
  SetAllDigital                 // set MCU pins as digital
 
init_variables                 // setup variables

GLCD.Cls                       // clear display before we start main prog
init_border                    // setup display border

    GLCD.SetFont(Fixed)
    GLCD.WriteAt(8,12,"GLCD")
    GLCD.WriteAt(12,22,"Game")
    GLCD.WriteAt(15,32,"by")
    GLCD.WriteAt(8,42,"bitfogav")

// Main Programme
While true

        ballDirect      // ball direction
        checkWalls      // check to see if ball hit any walls
        drawBall        // draws ball on display
       
        update_paddle1  // update paddle on display
 
        checkBallHitPaddle  // check to see if ball has hit our paddle       
Wend


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Fri May 27, 2011 6:16 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
thanks bitfogav, you used a similar approach to what i tried to do in allegro, here's my very scary code. i have yet to setup interrupts, initialize buttons(PORTA) and so on...
i'm also using this link
http://www.ritrivi.1free.ws/index.php?o ... icle&id=69

i'll use your code gracefully!


Attachments:
File comment: my pong sketch,
Cool pong.rar [4.15 KiB]
Downloaded 62 times
Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Sat May 28, 2011 7:46 am 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Mar 26, 2010 10:30 pm
Posts: 1863
Thanks for sharing the code bitfogav!


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 12:30 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
hey bitfogav,

i ported your code to mikro c
but for the ball prototype your created in swordfish with the GLCD.square function takes only 3 parameters, x1,y1 and size of the square, in mikro C the square function takes 4 parameters so i just added the x and y parameters again since it's a square.
the problem is that when i compile the code in mikro c, it gives an error on the Glcd_Init(&PORTB,0,1,2,3,5,4,&PORTD); routine, which is a first, as the other times i have used it in other programs it worked just fine.

this is the ported code by the way

Code:

//header file for mapping the buttons to port pins
#include "button_check.h"
#define   Pressed 0
//*****************************************************************************
//*  Name    : CAPTONG    -                                                   *
//*  Author  : [Captalex and his minions]                                     *
//*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS]              *
//*          : All Rights Reserved                                            *
//*  Date    : 10/june/2011                                                   *
//*  Version : 0.0.1                                                          *
//*  Notes   : a one player pong game , my first try at graphics              *
//*          : microcontroller programming.                                   *
//*          :                                                                *
//*****************************************************************************

/**ALL Constants, Variables and Identifiers **/


//use ints
int   topScreen      = 2;       // set paddle max travel (top display)
int   bottomScreen   = 41;      // set paddle max travel (bottom display)
int   wall_Left      =  1;     // set left wall position for hit detection
int   wall_Bottom    =  60;    // set bottom wall position for hit detection
int   wall_Top       =  1;     // set top wall position for hit detection
int   ballMissPaddle = 130;    // set max value for ball missing paddle

//how do i change Dim to match mikro C format and use Byte and word??? can i just use int instead for Byte ?
       //  ball data variables
int   ballX;        // ball initial x coordinate
int   ballY;        // ball initial y coordinate
int   ballX1;       // hold previous x values into a new varaiable
int   ballY1;      // hold previous y values into a new varaiable
int   ballSize;     // initial size for the ball
int   ballSpeed;     // ball speed

       // ball direction ints ,I set as ints, because mikroc  has no bool variable
int   Ball_Hit_Top;
int   Ball_Direct_Up;
int   Ball_Direct_Left;
int   Ball_Hit_Left;

        // paddle position data
int   paddleX1;          //paddle initial x coordinate
int   paddleY1;          //paddle initial y coordinate
int   paddleX2;          //paddle  final  x coordinate
int   paddleY2;          //paddle  final  x coordinate


//Function prototypes for each of the games functions

/* draws a border for the game */
void init_border()
{
    // draws line (top of screen)
    Glcd_Line(0,0,127,0,1);
    // draws line (left of screen)
    Glcd_Line(0,0,0,63,1);
   // draws line (bottom of screen)
    Glcd_Line(0,63,127,63,1);
} //for init_border();

/*initailizes the game event variables*/
void init_variables()
{
    ballX      = 64 ;           // starting position X for ball
    ballY      = 36 ;           // starting position Y for ball
    ballX1     = ballX+1;         //set old x values into a new varaiable
    ballY1     = ballY+1;         //set old y values into a new varaiable
    ballSize   = 2  ;           // ball size fixed
    ballSpeed  = 30 ;           // ball speed

      // Boder wall flags
    Ball_Hit_Top     = 0;          //  Ball_Hit_Top     = 0;
    Ball_Direct_Up   = 0;          //  Ball_Direct_Up   = 0;
    Ball_Direct_Left = 0;          //  Ball_Direct_Left = 0;
    Ball_Hit_Left    = 0;         //   Ball_Hit_Left    = 0;

    // starting point of paddle X,Y
    paddleX1 = 120 ;         //
    paddleY1 = 15  ;        // starting point of paddle X,Y
    paddleX2 = 121 ;         //
    paddleY2 = 35  ;         //
} //for init_variables();


void ball (int ballX1 , int ballY1, int ballX1, int ballY1)
{   //help here how do i implement the ball function using word in mikro c
     // draw ball on screen X,Y (ball size)
    Glcd_Box(ballX1,ballY1,ballX1,ballY1,1);
} //for ball();

/*the 4 possible ball's directions (left-right-up-down) */
void ballDirect()
{
       if (Ball_Direct_Left == 1)
        { // move the ball left
          ballX--; }
        else
        {  ballX++; //move the ball right
        } //for first if
      if (Ball_Direct_Up == 1)
        { // move the ball direction up
          ballY--;  }
        else
        {  ballY++; //move the ball down
        } //for second if
} //for ballDirect();

/*checks if ball has hit bottom or the top if the screen */
void checkWalls()
{
       if (( ballX == wall_Left ) && (Ball_Hit_Left == 1))
        {   // check wall left
            Ball_Direct_Left = 0;   //Ball_Direct_Left = 0;
            Ball_Hit_Left    = 0;      //Ball_Hit_Left = 0;
        } //for first if
        else if ((ballY == wall_Top) && (Ball_Hit_Top ==1))
        {   // check wall top
            Ball_Direct_Up = 0; //Ball_Direct_Up = 0;
            Ball_Hit_Top   = 0;    //Ball_Hit_Top  = 0;
        } //for second if
      //  else  ((ballY = wall_Bottom) && (Ball_Hit_Top = false))
      //  {  // check wall bottom
      //      Ball_Direct_Up = 1;   //Ball_Direct_Up = 1;
      //      Ball_Hit_Top   = 1;    //Ball_Hit_Top   = 1;
      //  } //for third if
} //for checkWalls();

/* draws the ball on the lcd screen*/
void drawBall()
{
        ball(ballX,ballY,ballX1,ballY1);      // draw new ball on screen
        Glcd_Set_Side(ballX+1);
        Glcd_Set_X(ballX+1);
        //Glcd_Set_Page(ballY+1);    // set pixel in middle of ball
        //delay_ms(ballSpeed);    // delay so we can see the  ball on the  screen, also see the ball's speed
        Glcd_Box(ballX,ballY,ballX1,ballY1,0);
        ball(ballX,ballY,ballX1,ballY1);    // clears ball previous pos (can only be done by deleting pixels)
        Glcd_Box(ballX,ballY,ballX1,ballY1,1);
        ball(ballX,ballY,ballX1,ballY1);      // draw new ball on screen
       // set pixel in middle of ball
        Glcd_Set_Side(ballX+1);
        Glcd_Set_X(ballX+1);
        Glcd_Set_Page(ballY+1);
        delay_ms(10);         // delay so we see ball on screen, also ball speed
        Glcd_Box(ballX,ballY,ballX1,ballY1,0);
        ball(ballX,ballY,ballX1,ballY1);    // clears ball previous pos (can only be done by deleting pixels)
        Glcd_Box(ballX,ballY,ballX1,ballY1,1);
} //for drawBall();


void update_paddle1()
{
            //button 2 is up
        if ((Switch_up == Pressed) && ( paddleY1 >= topScreen))
        { // check button up & check paddle max travel top
            Glcd_Rectangle(paddleX1,paddleY1,paddleX2,paddleY2,0);
            Glcd_Rectangle(paddleX1,paddleY1,paddleX2,paddleY2,1);
            paddleY1 = paddleY1 -1;                               // set paddle to go up on display
            paddleY2 = paddleY2 -1;                              //
            delay_ms(3); // delay to slow down paddle movement
        } //for up if condition
          //button1 is down
       if ((Switch_down == Pressed) && ( paddleY1 <= bottomScreen))
        { // check button down & check paddle max travel bottom
            Glcd_Rectangle(paddleX1,paddleY1,paddleX2,paddleY2,0);  // clear paddle previous data
            Glcd_Rectangle(paddleX1,paddleY1,paddleX2,paddleY2,1);
            paddleY1 = paddleY1 +1;                              // set paddle to go down on display
            paddleY2 = paddleY2 +1;                              //
            delay_ms(3);   // delay to slow down paddle movement
        } //for down if condition
       Glcd_Rectangle(paddleX1,paddleY1,paddleX2,paddleY2,1);   // update our NEW paddle pos data
} //for  update_paddle1();

/*when ball hits paddles select the direction it goes in*/
void checkBallHitPaddle()
{
      // check to see if our ball has hit the paddle
    if (ballX >= paddleX1-2) && (ballX <= paddleX2-2) && (ballY >= paddleY1)  && (ballY <= paddleY2)
      {
        Ball_Direct_Left = 1;           // change ball direction  Ball_Direct_Left = 1;
        Ball_Hit_Left    = 1;              // change ball direction  Ball_Hit_Left = 1;
      }
        else if (ballX = ballMissPaddle)
              { // check to see if ball missed our paddle
        // reset game
        init_variables();   // setup variables , init_variables();
        Glcd_Fill(0);          // Glcd_Fill(0);   clear display before we start main prog
        init_border();      // setup display border , init_border();
              }  //  for first else if }
           // for if
}   //for  checkBallHitPaddle();


void main()
{
ADCON1 = 0x0F;                // set MCU pins as digital and Set AN pins to Digital I/O
Glcd_Init(&PORTB,0,1,2,3,5,4,&PORTD);  // (CONTROL PORT,cs1,cs2,[(d/i)/rs],r/w,rst,en,DATAPORT)
Glcd_Fill(0);                  // clear display before we start main prog
TRISA = 0xFF;                  // set PORTA bits 1-5 Inputs (buttons) ,TRISA = 0xFF; // RA0 input
TRISC = 0;                     // PORTC outputs, for led indicator to show game is on
PORTC.F2 = 0;                 // Turn OFF LED indicator  on port RC2

         /*Welcome message*/
            Glcd_Write_Text("A",8,1,1);
            Glcd_Write_Text("PONG",12,2,1);
            Glcd_Write_Text("GAME",15,3,1);
            Glcd_Write_Text("BY",8,4,1);
            Glcd_Write_Text("CAPTALEX",15,5,1);
            Glcd_Write_Text("ENJOY",15,6,1);

    // Main Game loop
   while (1)
   {
        init_variables();                 // setup game variables
        init_border();                    // setup display border
        ballDirect();      // ball direction
        checkWalls();      // check to see if ball hit any walls
        drawBall();        // draws ball on display
        update_paddle1();  // update paddle on display
        checkBallHitPaddle();  // check to see if ball has hit our paddle
   } // for end of main game while condition

}  // for void main



and the header for Button config
Code:

//header file for mapping the buttons to port pins   in mikro c
#define Switch_up    PORTA.F0     //   button2
#define Switch_right PORTA.F1
#define Switch_down  PORTA.F2     //   button1
#define Switch_left  PORTA.F3
#define Switch_Start PORTA.F4



do help.


Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 1:38 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Im not sure if that ported code will work or not with mikroC? :roll: the GLCD functions in swordfish are more than likely different to that in the GLCD functions in miKroC. When I call the GLCD.Square function in swordfish I know that inside the swordfish square function it also calls the Rectangle function and thats how it draws a Square on the GLCD using swordfish:

this is the function(subroutine) for drawing a square using the swordfish module (or Class known in C language)
Quote:
Public Sub Square(pX, pY, pSize As TXY)
#if GLCD_ASPECT_RATIO <> 100
Rectangle(pX, pY, pX + pSize, pY + pSize * AspectRatio / 100)
#else
Rectangle(pX, pY, pX + pSize, pY + pSize)
#endif
End Sub


You say when compiling the code in mikroC you get an error? What if you compile the code with changing the GLCD_Init after you have declared your PORT settings? not sure if that will make any difference but worth a try?!.

Code:
ADCON1 = 0x0F;                // set MCU pins as digital and Set AN pins to Digital I/O
TRISA = 0xFF;                  // set PORTA bits 1-5 Inputs (buttons) ,TRISA = 0xFF; // RA0 input
TRISC = 0;                     // PORTC outputs, for led indicator to show game is on
PORTC.F2 = 0;                 // Turn OFF LED indicator  on port RC2

Glcd_Init(&PORTB,0,1,2,3,5,4,&PORTD);  // (CONTROL PORT,cs1,cs2,[(d/i)/rs],r/w,rst,en,DATAPORT)
Glcd_Fill(0);                  // clear display before we start main prog


As for using Int instead of Bytes and Words then that should be ok, When I programme I try to use the smallest data type as possible to reduce programme memory.

I didnt know that mikroC doesn't support BOOL, (booleans). the way you've done it looks like it should work.


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 3:49 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
bitfogav wrote:
Im not sure if that ported code will work or not with mikroC? :roll: the GLCD functions in swordfish are more than likely different to that in the GLCD functions in miKroC. When I call the GLCD.Square function in swordfish I know that inside the swordfish square function it also calls the Rectangle function and thats how it draws a Square on the GLCD using swordfish:

this is the function(subroutine) for drawing a square using the swordfish module (or Class known in C language)
Quote:
Public Sub Square(pX, pY, pSize As TXY)
#if GLCD_ASPECT_RATIO <> 100
Rectangle(pX, pY, pX + pSize, pY + pSize * AspectRatio / 100)
#else
Rectangle(pX, pY, pX + pSize, pY + pSize)
#endif
End Sub


You say when compiling the code in mikroC you get an error? What if you compile the code with changing the GLCD_Init after you have declared your PORT settings? not sure if that will make any difference but worth a try?!.

Code:
ADCON1 = 0x0F;                // set MCU pins as digital and Set AN pins to Digital I/O
TRISA = 0xFF;                  // set PORTA bits 1-5 Inputs (buttons) ,TRISA = 0xFF; // RA0 input
TRISC = 0;                     // PORTC outputs, for led indicator to show game is on
PORTC.F2 = 0;                 // Turn OFF LED indicator  on port RC2

Glcd_Init(&PORTB,0,1,2,3,5,4,&PORTD);  // (CONTROL PORT,cs1,cs2,[(d/i)/rs],r/w,rst,en,DATAPORT)
Glcd_Fill(0);                  // clear display before we start main prog


As for using Int instead of Bytes and Words then that should be ok, When I programme I try to use the smallest data type as possible to reduce programme memory.

I didnt know that mikroC doesn't support BOOL, (booleans). the way you've done it looks like it should work.



yes bitfogav, i tried moving the code, but i still get this error
" ';' expected = found"

hey bitfogav could you compilie the original code in swordfish for me using a pic18f4550 device and portA(0,2) for the button inputs.i also used a 4mhz external clock. i have also attached a screenshot of my screen.
thanks again.


Attachments:
File comment: source file, header file and screenshot of error
CAPTONG.rar [114.78 KiB]
Downloaded 72 times
Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 4:09 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Sure, ive changed what youve asked :)

Heres the Hex file of my compiled Pong with the changes:
Attachment:
GLCD Pong.rar [3.64 KiB]
Downloaded 65 times



Has for your error message - I can't see where the error can be :( sorry.


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 8:03 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Ive had another look over your code but still can't see why your getting that error?

TRISA Identifier redefined message means that the same identifier already exists in some unit
in your project? but I cant find it in any other unit and also you've got the ; colons in the correct places.

Attachment:
errormikroC.jpg
errormikroC.jpg [ 36.5 KiB | Viewed 835 times ]


One thing though, you need to take out these two lines from your main loop though, and put them out above your main loop so your program reads them before everything starts, I call these before the main loop to setup the variables and set the border for the display, you dont need to call these again. (well not here anyway).
Quote:
init_variables(); // setup game variables
init_border(); // setup display border


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 9:56 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
bitfogav wrote:
Ive had another look over your code but still can't see why your getting that error?

TRISA Identifier redefined message means that the same identifier already exists in some unit
in your project? but I cant find it in any other unit and also you've got the ; colons in the correct places.

Attachment:
errormikroC.jpg


One thing though, you need to take out these two lines from your main loop though, and put them out above your main loop so your program reads them before everything starts, I call these before the main loop to setup the variables and set the border for the display, you dont need to call these again. (well not here anyway).
Quote:
init_variables(); // setup game variables
init_border(); // setup display border



thanks bitfogav,
ive learnt alot from you man ,
ive taken the init funCtions out of the loop now,

but when i burn the hex to my pic the lcd does nothing, i think the pin assignments you used for your lcd are different from mine
well this are mine pin assignments.
portD- DATA PORT(D0-D7)
PORTB.F0- cs1
PORTB.F1- cs2
PORTB.F2- RS //REGISTER SELECT(DATA/INSTRUCTION)
PORTB.F3- R/W
PORTB.F4- EN
PORTB.F5-RST

i hope this is the cause of the problem :roll:


Top
 Profile E-mail  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Mon Jun 13, 2011 5:21 pm 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Yes I didnt change the GLCD pins, so thats probably why. :)

Im off to work now so I will have another look at it later, maybe build a 18f4550 with my pong code to test it and change the pins of the GLCD.


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Tue Jun 14, 2011 7:20 am 
Offline
Moderator
Moderator
User avatar

Joined: Sun Mar 28, 2010 9:03 pm
Posts: 699
Location: United Kingdom
Hi Captalex,

Ive made up a breadboard with a GLCD using a 18f4550, I have a 4mhz Ext crystal and two buttons connected up to the microchip, Ive connected up the GLCD and the rest of the circuit as you have in your project, changed my code to suit (datalines, etc) and the code runs fine :) Can I just point out that the 18F4550 has an Internal Oscillator 8 MHz.

Heres a picture of it working:
Attachment:
TestingPongon18f4550.jpg
TestingPongon18f4550.jpg [ 19.44 KiB | Viewed 828 times ]


Heres the New Hex file with the changes, And a text file of the changed code.
Attachment:
BitfogavsPongHex.rar [5.78 KiB]
Downloaded 75 times


Top
 Profile  
 
 Post subject: Re: Microcontroller based Graphical lcd game
PostPosted: Tue Jun 14, 2011 9:06 am 
Offline
decided to stick around...
decided to stick around...
User avatar

Joined: Mon Mar 21, 2011 3:00 am
Posts: 28
bitfogav wrote:
Hi Captalex,

Ive made up a breadboard with a GLCD using a 18f4550, I have a 4mhz Ext crystal and two buttons connected up to the microchip, Ive connected up the GLCD and the rest of the circuit as you have in your project, changed my code to suit (datalines, etc) and the code runs fine :) Can I just point out that the 18F4550 has an Internal Oscillator 8 MHz.

Heres a picture of it working:
Attachment:
The attachment TestingPongon18f4550.jpg is no longer available


Heres the New Hex file with the changes, And a text file of the changed code.
Attachment:
The attachment BitfogavsPongHex.rar is no longer available



hey bitfogav, "may more bytes be added to your harddrive", you circuit works completely, the ball bounces off the screen as expected.
but there is one caveat, the circuit works as expected but the orientation of the screen is on the right hand side and the pixels are negative as in they are inverted. i think my lcd screen is (0,0) for the extreme left upper corner and (128,64) for the bottom right corner of the lcd. so i think that is why the game starts on the right side. anyways thank you for effort and code man really appreciate it . your code is a just in time helper. and could you like send the swordfish work project file to me so i could include "made by captalex" in the text hehe. cheers man. :P here's the image on my screen


Attachments:
File comment: the image of the pong game on my lcd screen
block.rar [519.36 KiB]
Downloaded 73 times
Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 10 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme made by Keenen Wheeler