The idea to my mechanically scanned game system came from Bob Blick’s mechanically scanned clock, so I thought that I also had to implement a clock on my virtual game system.
The clock can simulate both a digital and an analog clock. Due to that the resolution of the clock is only 24×16 pixels, it is hard to show the time in both cases. In the case of the digital clock, scrolling the time over the screen solves the low-resolution problem. In the case of analog clock, the low resolution makes the clock really ugly. It is hard to make a good looking analog clock with such low resolution, but as this project is just for fun I think it is quite nice anyway. Originally my plan was to make a cuckoo clock, but there was not enough program memory left, if the I2C routines would be converted into assembler it would fit, but I don’t have time to do that in the close future.
Most of the code is written in C and compiled with Hi-tech PIC-C. It is the best c-compiler available for the PIC, but it comes with a primitive DOS IDE. However, it is possible to integrate the compiler with MPLAB and then you’ll have an extremely powerful easy-to-use development environment. It is this combination that I’ve used developing the virtual clock, and it is what I recommend you to use when developing stuff for PIC. It is amazing to see how tight code it produces.
It is quite easy to write the clock in C. I choose to use an external clock chip with an I2C interface to keep track of the time. The compiler comes with I2C routines, which makes the chip really easy to use. Quite easy anyway, I actually had problems with it first. The datasheet gave me the impression that the address counter was reset at the beginning of a new transfer so that it could be possible to read the time without specifying the address, but it wasn’t so. The address counter is not reset, so the address needs to be loaded at the beginning of each time-reading session. When I did this everything worked just fine. Showing the numbers on the screen is also quite easy thanks to the printchar command that can be sent to the graphics card.
The time menu shows the time using the same technique as the digital clock, but it updates the time from joystick moves instead of from the time-chip, and it writes back the time to the chip when the user is done. Not very complicated, the only thing that can be a little confusing is that the time is stored as BCD in the chip.
The analog clock uses a table to get the coordinates for the circle. It uses the line-drawing function in the graphics card to show hours and minutes. Seconds and markers uses the draw pixel function.
How to use the clock
The first screen is the digital clock. The time is scrolled over and over aigain. If you move the joystick down, you get into set-time mode, moving the joystick to the left, gets the clock into analog mode. Moving the joystick up or do anything one stuff with it doesn’t do anything it is just stupid =)
In time-set mode, the part of the time being set has a line under it, and you can choose part by moving joystick left and right. Time is adjusted by moving the joystick up and down, when done, store time by pressing fire.
In analog mode, the time is shown analog. If you move the joystick right, the mode is changed to digital clock mode.
For more detail: Virtual Tetris
We recommend EasyEDA for electronic circuit design.
From Schematic Drawing to PCB Production, Just Need One Tool
Cheap PCB Prototype: 10 pcs 2 layers only $10, quick delivery, 100% E-test
Current Project / Post can also be found using:
- game on pic16f84
- simon game on pic16f84