基于MSP430的LCD1284赛车小游戏开发Word文件下载.docx
《基于MSP430的LCD1284赛车小游戏开发Word文件下载.docx》由会员分享,可在线阅读,更多相关《基于MSP430的LCD1284赛车小游戏开发Word文件下载.docx(58页珍藏版)》请在冰点文库上搜索。
由该模块构成的液晶显示方案与同类型的图形点阵液晶显示模块相比,不论硬件电路结构或显示程序都要简洁得多,且该模块的价格也略低于相同点阵的图形液晶模块。
通讯方式:
串行、并口可选,内置DC-DC转换电路,无需外加负压,低电压低功耗。
无需片选信号,简化软件设计。
4、制作流程和作品内容
1.初步讨论和确立作品内容
小组成员组成队伍,并进行小组讨论,交流想法,确立作品的内容和目标。
进行初步的计划和分工。
2.学习相关知识并采购元器件
根据计划收集并学习相关资料(主要涉及单片机MSP430软件编程和功能使用,以及显示器LCD12864使用的相关说明等)并进行学习,采购单片机MSP、显示器LCD12864、电源、导线、电路板等元器件。
3.绘制详细电路图并制作成电路板
运用AltiumDesigner14绘制详细的电路图,并打印、腐蚀电路板,再与MSP430、LCD12864等元器件进行组装焊接,制成半成品。
4.进行软件编程
根据所设立的赛车小游戏的要求,与工作原理,进行相关的软件编程,并载入MSP430进行调试。
(主要程序、函数会在下文中进行罗列和说明)
5.制成成品并调试修改
对作品进行相关调试修改,完成作品。
5、主要程序、函数说明与功能简介
Main.c
intmain(void){
WDTCTL=WDTPW|WDTHOLD;
//Stopwatchdogtimer
unsignedchardirection,speed,temp,temp_car2=0;
Sys_Clk_Init();
//时钟初始化,现在为20MHz
Init_LCD();
Init_key();
update_to_LCD(x,y,car,2,12);
show_others();
LCD_Draw_Pic(LCD);
while
(1)
{
if(temp_car2==19)
{
temp_car2=0;
}//car2回归初始位置
if(car2_x>
64)
temp_car2++;
car2_y=car2_position[temp_car2],
car2_x=1;
}//新的一辆车的位置
direction=test_direction();
speed=test_speed();
if(speed==0)
update_speed(speed);
}
if(speed==1)
for(temp=speed;
temp>
0;
temp--)
{
update_fraps_some(1,16);
update_fraps_some(95,110);
update_to_LCD(car2_x,car2_y,block,2,12);
car2_x++;
show_car2(car2_x,car2_y);
}
}
if(speed==2)
if(speed==3)
if(speed==4)
if(direction==1)//控制车的方向向左,把车的位置向左移动1
update_to_LCD(x,y,block,2,12);
//先把原位置的图案清空
y=y-2;
if(y<
=16)y=17;
if(direction==2)//控制车的方向向右,把车的位置向右移动1
y=y+2;
if(y>
=84)y=83;
//把当前车的位置更新上去
judge_score();
//判断与更新得分
delay_ms(50);
return0;
}
6、结果展示
1.开始游戏
2.游戏画面
7、附件(程序)
(全部程序)
#include<
msp430.h>
#include"
NN12864.h"
UCS.h"
global.h"
Games.h"
key.h"
unsignedcharx=49,y=50,car2_x=1,car2_y=40;
unsignedintscore=0;
u8car2_position[20]={45,18,63,80,22,30,45,17,25,30,40,50,60,70,50,32,58,77,17,65};
//17~83
voidjudge_score(void)
{
if((car2_x==35))
if((car2_y<
=y)&
&
(car2_y+12>
=y))
score++;
update_score(score);
Game.c
u8LCD[8][128];
u8car[2][12]={0X00,0X1E,0X0C,0X0C,0XFF,0XFF,0XFF,0XFF,0X0C,0X0C,0X1E,0X00,
0XF8,0X30,0X30,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X30,0X30,0XF8};
u8block[2][12]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
u8black[4][18]={0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xFF,
0xFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xFF,
0XFF,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0XFF};
u8street[16]={0x00,0x00,0x10,0x38,0x3C,0X7E,0XFF,0X18,0X18,0X18,0X18,0X18,0XDB,0X00,0XFF,0XFF};
u8black_speed[16]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
u8white_speed[16]={0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,};
u8street_right[16]={0XFF,0XFF,0X00,0XDB,0X18,0X18,0X18,0X18,0X18,0XFF,0X7E,0x3C,0x38,0x10,0x00,0x00,};
u8num[10][6]={
{0x00,0x3E,0x51,0x49,0x45,0x3E},//0
{0x00,0x00,0x42,0x7F,0x40,0x00},//1
{0x00,0x42,0x61,0x51,0x49,0x46},//2
{0x00,0x21,0x41,0x45,0x4B,0x31},//3
{0x00,0x18,0x14,0x12,0x7F,0x10},//4
{0x00,0x27,0x45,0x45,0x45,0x39},//5
{0x00,0x3C,0x4A,0x49,0x49,0x30},//6
{0x00,0x01,0x71,0x09,0x05,0x03},//7
{0x00,0x36,0x49,0x49,0x49,0x36},//8
{0x00,0x06,0x49,0x49,0x29,0x1E},//9
};
u8coin[8]={0x18,0x3c,0x7e,0xff,0xff,0x7e,0x3c,0x18};
//更新新的一帧,是把矩阵数组更新下,像素点整体下移动一格
voidupdate_fraps(void)
u8temp[128];
u8temp_bit;
uchari,j;
for(i=0;
i<
128;
i++)
temp[i]=LCD[7][i]&
0x80;
//最后一行像素需要保存下
if((LCD[6][i]&
0x80)==0x80)temp_bit=0x01;
elsetemp_bit=0x00;
LCD[7][i]=(LCD[7][i]<
<
1)|temp_bit;
for(j=6;
j>
j--)
if((LCD[j-1][i]&
LCD[j][i]=(LCD[j][i]<
if(temp[i]==0x80)temp_bit=0x01;
LCD[0][i]=(LCD[0][i]<
//把液晶y1~y2内的元素循环下移一格(在LCD矩阵中)
//
voidupdate_fraps_some(u8y1,u8y2)
y1=y1-1;
//y2-=y2;
for(i=y1;
y2;
//把分数显示到LCD矩阵上
voidupdate_score(unsignedintscore)
unsignedinta,b,c;
//百位,十位,各位
c=score%10;
score=score/10;
b=score%10;
a=score%10;
update_to_LCD(1,111,num[a],1,6);
update_to_LCD(1,117,num[b],1,6);
update_to_LCD(1,123,num[c],1,6);
//把速度条显示到LCD矩阵上
voidupdate_speed(u8speed)
update_to_LCD(33,112,white_speed,1,16);
update_to_LCD(41,112,white_speed,1,16);
update_to_LCD(49,112,white_speed,1,16);
update_to_LCD(57,112,white_speed,1,16);
elseif(speed==1)
update_to_LCD(57,112,black_speed,1,16);
elseif(speed==2)
update_to_LCD(33,112,white_speed,1,16);
update_to_LCD(41,112,white_speed,1,16);
update_to_LCD(49,112,black_speed,1,16);
update_to_LCD(57,112,black_speed,1,16);
elseif(speed==3)
update_to_LCD(41,112,black_speed,1,16);
elseif(speed==4)
update_to_LCD(33,112,black_speed,1,16);
//将街道等物件显示完全
voidshow_others(void)
update_to_LCD(1,1,street,1,16);
//确定左边街道的显示
update_to_LCD(9,1,street,1,16);
update_to_LCD(17,1,street,1,16);
update_to_LCD(25,1,street,1,16);
update_to_LCD(33,1,street,1,16);
update_to_LCD(41,1,street,1,16);
update_to_LCD(49,1,street,1,16);
update_to_LCD(57,1,street,1,16);
update_to_LCD(1,95,street_right,1,16);
//确定右边街道的