Tuesday, January 20, 2009


Even the tetris failed to be exhibited due to the low brightness of the LED's, it was a great experience.It was a week ahead of our department program Insignia, and my class mates and me were searching every where for an idea of project. The lack of time kept us away from start projects from scratch. The team behind the റെതൃസ് decided to gave it a new birth, but this time there was another newbie team ready to take the challenge. Jaslina, Merlin and Abitha were ready to re-implement the idea with a new code and slight change in the circuit ( the changes ie the structure of the new project is described below) .
This time we decided to go with an etched circuit. Regarding the code, Abitha, Jaslina and Merlin could re-write the complete code where the job for me and Vyshakh was just helping them. After the effort of a few days the three colleagues of us could write a new code which was robust than the previous one, where the core ideas remained the same.

The soldering left in the etched board was done by the three itself..( another piece of perfect work from another newbies..)

Although it was for the first time these ത്രീ working with embedded programming there was nothing left in the code to be edited after the code was etched. The code ran in the first burning itself. It was really the greatest experience to see the tetrades falling one by one and changing there position and rotating with the keys...
    The circuit:
  • The tetris board is the same led dot matrix in which the negative legs of the 14 leds in each row are shorted positive legs of the 28 leds in each column are shorted.
  • The 14 column are controlled directly from the micro controller through ports B and C.
  • The 28 rows are controlled by decoded outputs through portA ie one row can be selected at a time.
  • The score is shown in 7segment display whose ic is controlled by 4 inputs ( 3 from port A and 1 from port C)
  • A 8 Mhz crystal is connected to the micro controller because the internal frequency of the mc which 4 Mhz will not be sufficient for the back ground programm of tetris to work.

    Background program:
    • Data structure used
    • The teris board is a single dimension integer array of length 28.
    • The shapes(tetrades) are single dimension array of integers terminated by negative values. Binary equivalent of the positive numbers in the shape array corresponds to the shape and the terminating negative number denote the maximum breadth of the shape.
    • Another variable for shifting the shape is used in the code which is just an integer whose default value is 6 and a left key press will increase the value of the variable and right key press will decrease it by 1.

    • Operation
    • Check for fall- to check whether a shape can fall a row down we have to look whether the 1 of the shape(tetrade) will overlap with any one in the board if all rows of the shape is pushed one row downwards, and if there is no such overlapping the shape can fall a row down.
      This checking is down based on the nature of binary numbers that a+b(addition) and a(+)b (bitwise X-oring ) will be the same if no two 1s are X-ored together. That means if the result of addition and X-or are the same the tetrade can fall.

    1. Algorithm for The Back ground Program
    2. The back-ground program will randomly select shapes from the array of shapes.
    3. The board is displayed such that ith row and value in ith row are selcted for all i<28>
    4. The game is over is the shape left shifted withe a value (say l) cannot be inserted to the board.
    5. The keys are read and the value of 'l' is updated for a left or right key and the shape is changed to the next change in the sequence of the present one, for a key press for rotation. nb: the updation of shape or l will take place only if the shape can exist in the board with the updated index of shape or vale of 'l'.
    6. The shape is made to fall a row down if it can fall down. and the algorithm is repeated from step2. And if the shape cannot fall down the Algorithm is repeated from step1.

Here is the micro controller code

No comments: