对于贪吃蛇这款游戏我们并不陌生,虽然它只是一个小游戏,但却不失为一个经典。
今天我们也来写一个贪吃蛇游戏,用单片机实现,用纯C语言写的网上一大堆,写得也很好。额,参考了几个比较经典的,于是说干就干,动手自己写一个。好了,废话不多说,开始吧!!!
由于代码比较多,在这里就不贴代码了,在"无聊游戏"功能模块可查看源代码,这里主要是说一说思路:
既然是用单片机实现的,首先得有单片机,然后设计电路,编程,下载,完了........开玩笑的。
首先我们来看看电路图:
单片机最小系统
16 x 16 LED点阵
因为只有8 x 8 LED点阵,
所以需要扩展成16 x 16,
如下图:
16 x 16 LED点阵原理图如下:
一共16的管脚,怎么办呢?这也太多了吧。
在学习数字电路的时候我们知道有一种芯片
叫译码器(如:3-8线译码器),在这里
我们也需要类似的芯片----74HC595,
看下图:
我们来看看有关这块芯片的资料:
MM54HC595/MM74HC595 8-Bit Shift Registers with Output Latches
General Description This high speed shift register utilizes advanced silicon-gate CMOS technology. This device possesses the high noise immunity and low power consumption of standard CMOS integrated circuits, as well as the ability to drive 15 LS-TTL loads. This device contains an 8-bit serial-in, parallel-out shift register that feeds an 8-bit D-type storage register. The storage register has 8 TRI-STATEÉ outputs. Separate clocks are provided for both the shift register and the storage register. The shift register has a direct-overriding clear, serial input, and serial output (standard) pins for cascading. Both the shift register and storage register use positive-edge triggered clocks. If both clocks are connected together, the shift register state will always be one clock pulse ahead of the storage register. The 54HC/74HC logic family is speed, function, and pin-out compatible with the standard 54LS/74LS logic family. All inputs are protected from damage due to static discharge by internal diode clamps to VCC and ground.
Features:
●Low quiescent current: 80 mA maximum (74HC Series)
● Low input current: 1 mA maximum
● 8-bit serial-in, parallel-out shift register with storage
● Wide operating voltage range: 2V–6V
● Cascadable
● Shift register has direct clear
● Guaranteed shift frequency: DC to 30 MHz
老实说,英文不好是真的烦,看个资料花了我大部分时间。
不过好在我们有了大致的了解。
现在来用这块芯片去驱动那16 x 16LED点阵
嗯,万事俱备,只欠编程。
为了减少篇幅,请到"无聊游戏"功能模块查看源代码。