u8
car2_position[20]={45,18,63,80,22,30,45,17,25,30,40,50,60,70,50,32,58,77,17,65};//17~83 int main(void) {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
unsigned char
direction,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) {
update_speed(speed); 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) {
update_speed(speed); 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 == 3)
{
update_speed(speed); 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 == 4) {
update_speed(speed); 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(direction == 1) //控制车的方向向左,把车的位置向左移动1 {
update_to_LCD(x,y,block,2,12); //先把原位置的图案清空 y=y-2;
if(y<=16) y=17; }
if(direction == 2) //控制车的方向向右,把车的位置向右移动1 {
update_to_LCD(x,y,block,2,12); //先把原位置的图案清空 y=y+2;
if(y>=84) y=83; }
update_to_LCD(x,y,car,2,12);//把当前车的位置更新上去