管道鸟cortex-M4(TM4C1294)

看到满屏的贪吃蛇,我也来开源一个Ti开发板(TM4C1294)的游戏
将简化版的管道鸟,根据自己玩的经历,在cortexm4开发板上重新撸了一边,
设计思路:
设计思路:将小鸟固定在一条竖线上规定其只能上下移动并记录下其最高和最低的坐标,管道从屏幕右边开始出现依次移动到屏幕左边消失,用户通过按键控制小鸟上下移动,小鸟也有一个自然下降的速度,用户要控制小鸟在前进过程中不碰到管道的边和屏幕的边界。
主要的方法是:
画管道按横坐标宽60个像素将屏幕分成4等分,第一块产生随机高度的管道,第二,三,四块在管道运动到相应的块结束时接着上一块的结尾显示;
画小鸟选取15x15像素的一块区域,以中心点计算出鸟上各个点的坐标,在画鸟时只需知道其中一个点就可以画出鸟。
画的鸟如下图:

移动鸟,先将前一步鸟所在的位置的图像消除,再根据中心点的位置变化计算出其他点的位置画出新的鸟位置。
鸟中心坐标改变是靠按键中断来实现;
重新开始是在屏幕上确定一块区域当触摸那块区域后从新开始。
源代码

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_epi.h"
#include "inc/hw_ints.h"
#include "driverlib/epi.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/pin_map.h"
#include "driverlib/systick.h"
#include "driverlib/interrupt.h"
#include "driverlib/ssi.h"
#include "driverlib/fpu.h"
#include "utils/uartstdio.h"
#include "TFTinit/TFT_400x240_OTM4001A_16bit.h"
//#include "TFTinit/picture.h"
#include "TOUCHinit/TOUCH_TSC2046.h"
#include "EPIinit/EPIinit.h"
#include "IQmath/IQmathLib.h"
//---
//-----mi
#define _NOP() _nop()

//*********************************************************************
//*********************************************************************
#define I2C0_MASTER_BASE 0x40020000
#define I2C0_SLAVE_BASE 0x40020000

//*********************************************************************
// 地址、寄存器等定义部分
//*********************************************************************
//*********************************************************************
//
// 设定slave(从)模块的地址。这是一个7-bit的地址加上RS位,具体形式如下:
//                      [A6:A5:A4:A3:A2:A1:A0:RS]
// RS位是一个指示位,如果RS=0,则说明是主发送数据,从接收数据;RS=1说明是主接收数据,从发送数据
//
//*********************************************************************
//U21控制4个米字管和特殊管脚的亮灭
#define I2C0_ADDR_TUBE_SEL        0x30  //00110000
//U22控制米字管7~14管脚对应的码段
#define I2C0_ADDR_TUBE_SEG_LOW    0x32  //00110010
//U23控制米字管15~18管脚对应的码段
#define I2C0_ADDR_TUBE_SEG_HIGH  0x34   //00110100
//U24控制LED光柱

//PCA9557内部寄存器,也称子地址
#define PCA9557_REG_INPUT    0x00
#define PCA9557_REG_OUTPUT   0x01
#define PCA9557_REG_PolInver 0x02
#define PCA9557_REG_CONFIG   0x03

//*************************************************************************************
 #define NUM 0
//IIC 接受数据临时缓冲区
unsigned char I2C_RECV_DATA[] =
                {
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00,
                    0x00
                };

/*******************************************
        拉高 SDA 信号
********************************************/
void I2C_Set_sda_high( void )
{
    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_3,GPIO_PIN_3);  //拉高PB3
    _NOP();
    _NOP();
    return;
}

/*******************************************
        拉低SDA 信号
********************************************/
void I2C_Set_sda_low ( void )
{
    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_3,0X00000000);  //拉低PB3
    _NOP();
    _NOP();
    return;
}

/*******************************************
        拉高SCL 信号
********************************************/
void I2C_Set_scl_high( void )
{
    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_2,GPIO_PIN_2);  //拉高PB2
    _NOP();
    _NOP();
    return;
}

/*******************************************
        拉低SCL 信号/
********************************************/
void I2C_Set_scl_low ( void )
{
    GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_2,0X00000000);  //拉低PB2
    _NOP();
    _NOP();
    return;
}

/*******************************************
        IIC 信号结束信号函数
********************************************/
void I2C_STOP(void)
{
    int i;
    I2C_Set_sda_low();
    for(i = NUM;i > 0;i--);
    I2C_Set_scl_low();
    for(i = NUM;i > 0;i--);
    I2C_Set_scl_high();
    for(i = NUM;i > 0;i--);
    I2C_Set_sda_high();
    for(i = NUM+1;i > 0;i--);
    return;
}

/*******************************************
        IIC 信号初始化
********************************************/
void I2C_Initial( void )
{
    I2C_Set_scl_low();
    I2C_STOP();
    return;
}

/*******************************************
        IIC 信号起始信号函数
********************************************/
void I2C_START(void)
{
    int i;

    I2C_Set_sda_high();
    for(i = NUM;i > 0;i--);
    I2C_Set_scl_high();
    for(i = NUM;i > 0;i--);
    I2C_Set_sda_low();
    for(i = NUM;i > 0;i--);
    I2C_Set_scl_low();
    return;
}

/*******************************************
        IIC 获取应答函数
********************************************/
int  I2C_GetACK(void)
{
    int j;
    _NOP();
    _NOP();
    I2C_Set_scl_low();
    for(j = NUM;j> 0;j--);
    I2C_Set_scl_high();
    for(j = NUM;j> 0;j--);
    I2C_Set_sda_low();
    for(j = NUM;j > 0;j--);
    I2C_Set_scl_low();
    return 1;
}

/*******************************************
        IIC 设置应答函数
********************************************/
void I2C_SetNAk(void)
{
    I2C_Set_scl_low();
    I2C_Set_sda_high();
    I2C_Set_scl_high();
    I2C_Set_scl_low();
    return;
}

/*******************************************
        IIC 发送字节函数
        参数  1:要发送字节值
        return :无返回
********************************************/
void I2C_TxByte(unsigned char nValue)
{
    int i;
    int j;
    for(i = 0;i < 8;i++)
    {
        if(nValue & 0x80)
            I2C_Set_sda_high();
        else
            I2C_Set_sda_low();
        for(j = NUM;j > 0;j--);
        I2C_Set_scl_high();
        nValue <<= 1;
        for(j = NUM;j > 0;j--);
        I2C_Set_scl_low();
    }

    return;
}

/*******************************************
        IIC 接收字节函数
        参数      无
        return :无返回
********************************************/
unsigned char  I2C_RxByte(void)
{
    GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_3);//配置PB3为输入口
    unsigned char nTemp=0 ;
    int i;

    I2C_Set_sda_high();

   _NOP();
    _NOP();
    _NOP();
    _NOP();
     for(i = 0;i < 8;i++)
    {
        I2C_Set_scl_high(); //模拟SCL信号
        if(GPIOPinRead(GPIO_PORTB_BASE,GPIO_PIN_3) == 0x18) //依次判断PB3(SDA)输入
        {
            nTemp |= (0x01 << (7-i));  //8位SDA数据哪一位为高就置1
        }
        I2C_Set_scl_low();
        //Delay5us();
    }

    return nTemp;

}

/*******************************************
        IIC 发送数组函数
    参数      1 num : 发送字节数
        2 device_addr : iic目标地址
        3 *data :发送数组地址
    return :无返回
********************************************/
void i2c_write(int num, unsigned char device_addr,unsigned char *data)
{
    int i = 0;
    int count = num;
    unsigned char *send_data = data;
    unsigned char write_addr = device_addr;

    I2C_Set_scl_high();
    for(i = NUM;i > 0;i--);
    I2C_Set_sda_high();
    for(i = NUM;i > 0;i--);

    for(i = 0;i < count;i++)
    {
      I2C_START();           //模拟I2C写数据的时序
      I2C_TxByte(write_addr);
      I2C_GetACK();
      I2C_TxByte(send_data[i]);
      I2C_GetACK();
      i++;
      I2C_TxByte(send_data[i]);
      I2C_GetACK();
      I2C_STOP();
    }

}

/*******************************************
        IIC 读取数组函数
    参数      1 num : 发送字节数
        2 device_addr : iic目标地址
        3 *data :接收数组地址
    return :无返回
********************************************/
void i2c_read(int num, unsigned char device_addr,unsigned char *data)
{
  int i = 0;
  int count = num;
  unsigned char *send_data = data;
  unsigned char read_addr = device_addr;

  I2C_Set_scl_high();
  for(i = NUM;i > 0;i--);
  I2C_Set_sda_high();
  for(i = NUM;i > 0;i--);

  for(i = 0; i < count;i++)
  {
    I2C_START();               //模拟I2C读数据
    I2C_TxByte((read_addr - 1));
    I2C_GetACK();
    I2C_TxByte(send_data[2*i]);
    I2C_GetACK();

    I2C_START();
    I2C_TxByte(read_addr);
    I2C_GetACK();

    I2C_RECV_DATA[i] = I2C_RxByte();
    data[2*i+1]=I2C_RECV_DATA[i];
    I2C_SetNAk();
    I2C_STOP();
  }

}

//*********************************************************************/

//*********************************************************************/
//******配置I2C0模块的IO引脚,**********************************************/
void I2C0GPIOBEnable(void)
{   // Enable GPIO portB containing the I2C pins (PB2&PB3)
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3);

}

//******配置PCA9557芯片中连接米字管的各引脚为输出***********************************/
void I2C0DeviceInit(void)
{
    unsigned char dataBuf[2] = {PCA9557_REG_CONFIG, 0x00};
    i2c_write(2,I2C0_ADDR_TUBE_SEL,dataBuf);
    i2c_write(2,I2C0_ADDR_TUBE_SEG_LOW,dataBuf);
    i2c_write(2,I2C0_ADDR_TUBE_SEG_HIGH,dataBuf);

}

/*******设置米字管的管选信号**************************************************/
void I2C0TubeSelSet(char data)
{   //选择1、2、3、4、5哪个米字管亮
    unsigned char dataBuf[2] = {PCA9557_REG_OUTPUT, data};
    i2c_write(2,I2C0_ADDR_TUBE_SEL,dataBuf);
}
/*******点亮米字管的相应码段**************************************************/
void I2C0TubeLowSet(char data)
{  //点亮7-14管脚对应的码段
    unsigned char dataBuf[2] = {PCA9557_REG_OUTPUT, data};
    i2c_write(2,I2C0_ADDR_TUBE_SEG_LOW,dataBuf);
}
void I2C0TubeHighSet(char data)
{  //点亮15-18管脚对应的码段
    unsigned char dataBuf[2] = {PCA9557_REG_OUTPUT, data};
    i2c_write(2,I2C0_ADDR_TUBE_SEG_HIGH,dataBuf);
}

//********预设码段值,方便查找************************************************
static const char tubeCodeTable[10][2]=
        { //  SegmLow, SegHigh
            {   0x10,   0x3E    },      //          0
            {   0x00,   0x18    },      //          1
            {   0x70,   0x2C    },      //          2
            {   0x70,   0x26    },      //          3
            {   0x60,   0x32    },      //          4
            {   0x70,   0x16    },      //          5
            {   0x70,   0x1E    },      //          6
            {   0x00,   0x26    },      //          7
            {   0x70,   0x3E    },      //          8
            {   0x70,   0x36    },      //          9
//            { 0x60,   0x3E    },      //          a
        };

/**************************************************************************/
unsigned char a[2];
void setnumber(int value)
{

    switch(value){
    case 0:{ a[0]=tubeCodeTable[0][0];a[1]=tubeCodeTable[0][1];break;}
    case 1:{ a[0]=tubeCodeTable[1][0];a[1]=tubeCodeTable[1][1];break;}
    case 2:{ a[0]=tubeCodeTable[2][0];a[1]=tubeCodeTable[2][1];break;}
    case 3:{ a[0]=tubeCodeTable[3][0];a[1]=tubeCodeTable[3][1];break;}
    case 4:{ a[0]=tubeCodeTable[4][0];a[1]=tubeCodeTable[4][1];break;}
    case 5:{ a[0]=tubeCodeTable[5][0];a[1]=tubeCodeTable[5][1];break;}
    case 6:{ a[0]=tubeCodeTable[6][0];a[1]=tubeCodeTable[6][1];break;}
    case 7:{ a[0]=tubeCodeTable[7][0];a[1]=tubeCodeTable[7][1];break;}
    case 8:{ a[0]=tubeCodeTable[8][0];a[1]=tubeCodeTable[8][1];break;}
    case 9:{ a[0]=tubeCodeTable[9][0];a[1]=tubeCodeTable[9][1];break;}
             }
}
void I2C0Tubeset()
{
    I2C0TubeLowSet(a[0]);
    I2C0TubeHighSet(a[1]);

}
void showvalue(int value)
{
    setnumber(value);
    I2C0Tubeset();
}
//--
void GPIOIntInitial(void)
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);//
    GPIOPinTypeGPIOInput(GPIO_PORTD_BASE,GPIO_PIN_0);
   GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_0,GPIO_LOW_LEVEL);
    GPIOIntEnable(GPIO_PORTD_BASE,GPIO_INT_PIN_0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPION);//
    GPIOPinTypeGPIOInput(GPIO_PORTN_BASE,GPIO_PIN_2);
    GPIOIntTypeSet(GPIO_PORTN_BASE,GPIO_PIN_2,GPIO_LOW_LEVEL);
    GPIOIntEnable(GPIO_PORTN_BASE,GPIO_INT_PIN_2);
}
// System clock rate in Hz.
//
//*****************************************************************************
//----------------------wave
static volatile unsigned long g_ulTickCount;
#define SERIES_LENGTH 240
typedef struct _Series
{
    uint32_t xAxis;
    int32_t data;
}tSeries;

tSeries g_cSeries[241];
int x,y,i;
#define TICKS_PER_SECOND 40
#define FSECONDS_PER_TICK (1.0F / (float)TICKS_PER_SECOND)
#ifndef M_PI
#define M_PI                    3.14159265358979323846F
#endif

void
SysTickIntHandler(void)
{
    //
    // Update our tick counter.
    //
    g_ulTickCount++;
    if(g_ulTickCount>=320)
        g_ulTickCount = 0;

}

//-------------------------------------------------
uint32_t g_ui32SysClock;

extern uint32_t GetData[11];
void qingniao(int x,int y);
void huaniao(int x,int y);
uint32_t TouchXData[11];
uint32_t TouchYData[11];
uint32_t TouchZData[11];   //Z is for pressure measurement
void delay()
{
    int ui32Loop0;
    for(ui32Loop0=0;ui32Loop0<1000000;ui32Loop0++)  //delay
    {;}
}
void delay2()
{
    int ui32Loop0;
    for(ui32Loop0=0;ui32Loop0<500000;ui32Loop0++)  //delay
    {;}
}

//*****************************************************************************
//
// Configure the UART and its pins.  This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, g_ui32SysClock);
}
//---------------------------------------
///
///中断加速上升
//-----
void
GPIOD(void)
{
    UARTprintf("y=");
    unsigned long Status;
    Status=GPIOIntStatus(GPIO_PORTD_BASE,true);
    if(Status==GPIO_INT_PIN_0)
    {
       qingniao(x,y);
        y=y-10;
        huaniao(x,y);
        delay2();
    }
    GPIOIntClear(GPIO_PORTD_BASE,Status);
}
//---------------------------------------
//---------------------------------------
///
///中断向下移动
//-----
void
GPION(void)
{
    unsigned long Status;
    UARTprintf("y=%d,data=%d\n",y,g_cSeries[x].data);
    Status=GPIOIntStatus(GPIO_PORTN_BASE,true);
    if(Status==GPIO_INT_PIN_2)
    {
        qingniao(x,y);
        y=y+10;
        huaniao(x,y);
        delay2();

    }
        GPIOIntClear(GPIO_PORTD_BASE,Status);
}
//----------画出小鸟
//----------
void huaniao(int x,int y)
{
     TFTLCD_DrawPoint(x-7,y+1,BLUE);
     TFTLCD_DrawPoint(x-7,y+3,BLUE);
     TFTLCD_DrawPoint(x-6,y-2,BLUE);
     TFTLCD_DrawPoint(x-6,y-1,BLUE);
     TFTLCD_DrawPoint(x-6,y,BLUE);
     TFTLCD_DrawPoint(x-6,y+2,BLUE);
     TFTLCD_DrawPoint(x-6,y+4,BLUE);
     TFTLCD_DrawPoint(x-6,y+5,BLUE);
     TFTLCD_DrawPoint(x-5,y-5,BLUE);
     TFTLCD_DrawPoint(x-5,y-4,BLUE);
     TFTLCD_DrawPoint(x-5,y-3,BLUE);
     TFTLCD_DrawPoint(x-5,y-2,BLUE);
     TFTLCD_DrawPoint(x-5,y+5,BLUE);
     TFTLCD_DrawPoint(x-5,y+6,BLUE);
     TFTLCD_DrawPoint(x-4,y-6,BLUE);
     TFTLCD_DrawPoint(x-4,y+6,BLUE);
     TFTLCD_DrawPoint(x-4,y+7,BLUE);
     TFTLCD_DrawPoint(x-3,y-5,BLUE);
     TFTLCD_DrawPoint(x-3,y,BLUE);
     TFTLCD_DrawPoint(x-3,y+1,BLUE);
     TFTLCD_DrawPoint(x-3,y+7,BLUE);
     TFTLCD_DrawPoint(x-2,y-5,BLUE);
     TFTLCD_DrawPoint(x-2,y-5,BLUE);
     TFTLCD_DrawPoint(x-2,y-4,BLUE);
     TFTLCD_DrawPoint(x-2,y-1,BLUE);
     TFTLCD_DrawPoint(x-2,y+2,BLUE);
     TFTLCD_DrawPoint(x-2,y+7,BLUE);
     TFTLCD_DrawPoint(x-1,y-6,BLUE);
     TFTLCD_DrawPoint(x-1,y-1,BLUE);
     TFTLCD_DrawPoint(x-1,y,BLUE);
     TFTLCD_DrawPoint(x-1,y+1,BLUE);
     TFTLCD_DrawPoint(x-1,y+2,BLUE);
     TFTLCD_DrawPoint(x-1,y+7,BLUE);
     TFTLCD_DrawPoint(x,y-5,BLUE);
     TFTLCD_DrawPoint(x,y-1,BLUE);
     TFTLCD_DrawPoint(x,y+2,BLUE);
     TFTLCD_DrawPoint(x,y+7,BLUE);
     TFTLCD_DrawPoint(x+1,y-4,BLUE);
     TFTLCD_DrawPoint(x+1,y-3,BLUE);
     TFTLCD_DrawPoint(x+1,y,BLUE);
     TFTLCD_DrawPoint(x+1,y+1,BLUE);
     TFTLCD_DrawPoint(x+1,y+6,BLUE);
     TFTLCD_DrawPoint(x+2,y-2,BLUE);
     TFTLCD_DrawPoint(x+2,y-1,BLUE);
     TFTLCD_DrawPoint(x+2,y+5,BLUE);
     TFTLCD_DrawPoint(x+3,y-1,BLUE);
     TFTLCD_DrawPoint(x+3,y,BLUE);
     TFTLCD_DrawPoint(x+3,y+1,BLUE);
     TFTLCD_DrawPoint(x+3,y+2,BLUE);
     TFTLCD_DrawPoint(x+3,y+3,BLUE);
     TFTLCD_DrawPoint(x+3,y+4,BLUE);
     TFTLCD_DrawPoint(x+4,y,BLUE);
     TFTLCD_DrawPoint(x+4,y+4,BLUE);
     TFTLCD_DrawPoint(x+5,y+1,BLUE);
     TFTLCD_DrawPoint(x+5,y+3,BLUE);
     TFTLCD_DrawPoint(x+6,y+2,BLUE);
}
//------------------------
//-----------------------消除小鸟
void qingniao(int x,int y)
{
     TFTLCD_DrawPoint(x-7,y+1,BLACK);
     TFTLCD_DrawPoint(x-7,y+3,BLACK);
     TFTLCD_DrawPoint(x-6,y-2,BLACK);
     TFTLCD_DrawPoint(x-6,y-1,BLACK);
     TFTLCD_DrawPoint(x-6,y,BLACK);
     TFTLCD_DrawPoint(x-6,y+2,BLACK);
     TFTLCD_DrawPoint(x-6,y+4,BLACK);
     TFTLCD_DrawPoint(x-6,y+5,BLACK);
     TFTLCD_DrawPoint(x-5,y-5,BLACK);
     TFTLCD_DrawPoint(x-5,y-4,BLACK);
     TFTLCD_DrawPoint(x-5,y-3,BLACK);
     TFTLCD_DrawPoint(x-5,y-2,BLACK);
     TFTLCD_DrawPoint(x-5,y+5,BLACK);
     TFTLCD_DrawPoint(x-5,y+6,BLACK);
     TFTLCD_DrawPoint(x-4,y-6,BLACK);
     TFTLCD_DrawPoint(x-4,y+6,BLACK);
     TFTLCD_DrawPoint(x-4,y+7,BLACK);
     TFTLCD_DrawPoint(x-3,y-5,BLACK);
     TFTLCD_DrawPoint(x-3,y,BLACK);
     TFTLCD_DrawPoint(x-3,y+1,BLACK);
     TFTLCD_DrawPoint(x-3,y+7,BLACK);
     TFTLCD_DrawPoint(x-2,y-5,BLACK);
     TFTLCD_DrawPoint(x-2,y-5,BLACK);
     TFTLCD_DrawPoint(x-2,y-4,BLACK);
     TFTLCD_DrawPoint(x-2,y-1,BLACK);
     TFTLCD_DrawPoint(x-2,y+2,BLACK);
     TFTLCD_DrawPoint(x-2,y+7,BLACK);
     TFTLCD_DrawPoint(x-1,y-6,BLACK);
     TFTLCD_DrawPoint(x-1,y-1,BLACK);
     TFTLCD_DrawPoint(x-1,y,BLACK);
     TFTLCD_DrawPoint(x-1,y+1,BLACK);
     TFTLCD_DrawPoint(x-1,y+2,BLACK);
     TFTLCD_DrawPoint(x-1,y+7,BLACK);
     TFTLCD_DrawPoint(x,y-5,BLACK);
     TFTLCD_DrawPoint(x,y-1,BLACK);
     TFTLCD_DrawPoint(x,y+2,BLACK);
     TFTLCD_DrawPoint(x,y+7,BLACK);
     TFTLCD_DrawPoint(x+1,y-4,BLACK);
     TFTLCD_DrawPoint(x+1,y-3,BLACK);
     TFTLCD_DrawPoint(x+1,y,BLACK);
     TFTLCD_DrawPoint(x+1,y+1,BLACK);
     TFTLCD_DrawPoint(x+1,y+6,BLACK);
     TFTLCD_DrawPoint(x+2,y-2,BLACK);
     TFTLCD_DrawPoint(x+2,y-1,BLACK);
     TFTLCD_DrawPoint(x+2,y+5,BLACK);
     TFTLCD_DrawPoint(x+3,y-1,BLACK);
     TFTLCD_DrawPoint(x+3,y,BLACK);
     TFTLCD_DrawPoint(x+3,y+1,BLACK);
     TFTLCD_DrawPoint(x+3,y+2,BLACK);
     TFTLCD_DrawPoint(x+3,y+3,BLACK);
     TFTLCD_DrawPoint(x+3,y+4,BLACK);
     TFTLCD_DrawPoint(x+4,y,BLACK);
     TFTLCD_DrawPoint(x+4,y+4,BLACK);
     TFTLCD_DrawPoint(x+5,y+1,BLACK);
     TFTLCD_DrawPoint(x+5,y+3,BLACK);
     TFTLCD_DrawPoint(x+6,y+2,BLACK);
}

void main()
{

    x=120;
    y=240;
    i=0;
    uint16_t ui32Loop = 0,pp= 0;
    int start=0;
    int end=0;
    int fenshu[4]=0;
    int high=0;
    int zaici=0;
    int t1,t2,t3,t4;
    int p1=180,p2=120,p3=60;
    int b1=0,b2=0,b3=0;
    int c=0;
    //-----------------------------------
    uint16_t ulItemCount=0,FinishCalculateFlag=0,ulLastTickCount=0;
    float fElapsedTime;
    _iq24 fRadians,fSine;
    FPUEnable();
    FPULazyStackingEnable();
    //
    // Run from the PLL at 120 MHz.
    //
    g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
            SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
            SYSCTL_CFG_VCO_480), 120000000);
    GPIOIntInitial();
    IntPrioritySet(INT_GPION, 0x20);
    IntPrioritySet(INT_GPIOD, 0x80);
    I2C0GPIOBEnable();//配置I2C0模块的IO引脚
    I2C0DeviceInit();//配置PCA9557芯片中连接米字管的各引脚为输出
    IntMasterEnable();
    SysTickPeriodSet(g_ui32SysClock / TICKS_PER_SECOND);
    IntMasterEnable();
    SysTickEnable();
    ConfigureUART();
    EPIGPIOinit();
    TOUCH_TSC2046init(g_ui32SysClock);

    GPIOIntEnable(GPIO_PORTB_BASE,GPIO_INT_PIN_0);
    GPIOIntTypeSet(GPIO_PORTB_BASE,GPIO_PIN_0,GPIO_FALLING_EDGE);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);
    UARTprintf("TFTLCD touch screen test\n");
    UARTprintf("EPI Type: host-bus 16-bit interface\n");
    UARTprintf("SSI Type: SSI0 8bit\n");

    TFT_400x240_OTM4001Ainit(g_ui32SysClock);

    SSIDataPut(SSI0_BASE,0xd0);
    IntEnable(INT_GPION);
    IntEnable(INT_GPIOD);
    while(1)
    {

        //ulLastTickCount = g_ulTickCount;

        if(ulItemCount == SERIES_LENGTH)
        {
            FinishCalculateFlag = 1;
        }

        //
        // Otherwise, the series data buffer is less than full so just
        // increment the count of data points.
        //
        else
        {

            g_cSeries[ulItemCount].xAxis = ++ulItemCount;
            g_cSeries[239].data=100;

        }
        //
        // Compute the elapsed time in decimal seconds, in floating point
        // format.
        //
        fElapsedTime = (float)g_ulTickCount * FSECONDS_PER_TICK;
        // Convert the time to radians.
        //
        //      fRadians = fElapsedTime * (float)M_PI;
        fRadians = _IQ24(fElapsedTime * (float)M_PI);     //_IQ24 converts a floating-point constant or variable into an IQ number.

        //
        // Adjust the period of the wave.  This will give us a wave period
        // of 4 seconds, or 0.25 Hz.  This number was chosen arbitrarily to
        // provide a nice looking wave on the display.
        //
        //        fRadians /= 2.0F;
        fRadians = _IQdiv2(fRadians);        //_IQdiv2 divides fRadians by two.
        //        fRadians = _IQdiv4(fRadians);        //Divides fRadians by four.
        //
        // Compute the sine.  Multiply by 0.5 to reduce the amplitude.
        //
        fSine = _IQ24sin(fRadians);         //Computes the sine of the input value.

        if(!FinishCalculateFlag)
        {

        }
        else
        {
/*/----------------------------------
 *
 *
 * 开始画管道
 *
 ----------------------------------------*/
            for(ui32Loop=240;ui32Loop>0;ui32Loop--)
            {
                int k;
                for(k=0;k<80000;k++)
                {

                }
                if(ui32Loop==210)
                {
                    c++;
                    c=c%2;
                }
                int num;
////-------------180到240的管道
                if(g_cSeries[ui32Loop].data>20)
                {
                    g_cSeries[ui32Loop-1].data = g_cSeries[ui32Loop].data;
                    TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,g_cSeries[ui32Loop-1].data,GREEN);
                    TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,g_cSeries[ui32Loop-1].data+50,GREEN);//设置管子中间夹缝是50个像素

                    num=g_cSeries[ui32Loop-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,num,GREEN);
                    }
                    num=g_cSeries[ui32Loop-1].data+50;
                    for(;num<480;num++)
                    {
                        TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,num,GREEN);
                    }
            }
            else
            {
                num=g_cSeries[ui32Loop-1].data;
                for(;num>0;num--)
                {
                    TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,num,BLACK);
                }
                num=g_cSeries[ui32Loop-1].data+50;
                for(;num<480;num++)
                {
                    TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,num,BLACK);
                }
                    TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,g_cSeries[ui32Loop-1].data,0);
                TFTLCD_DrawPoint(g_cSeries[ui32Loop-1].xAxis,g_cSeries[ui32Loop-1].data+50,0);
                g_cSeries[ui32Loop-1].data = g_cSeries[ui32Loop].data;

            }
/*----------------------------------------
 *
 *
 * 120到180管道
 * -------------------------------------
 */
            if(ui32Loop==181)
            {
                t1=rand()%300+50;
                ui32Loop=ui32Loop+60;
                b1=1;
                t2=g_cSeries[185].data;
                g_cSeries[p1].data=t2;
                start++;
                fenshu[0]=((start/2)-1)%10;
                fenshu[1]=(((start/2)-1)%100-fenshu[0])/10;
                fenshu[2]=(((start/2)-1)%1000-fenshu[1]-fenshu[0])/100;
                fenshu[3]=((start/2)-1)/1000;

                showvalue(fenshu[0]);
                I2C0TubeSelSet(~0x08);
                SysCtlDelay(20000);
            }
            if(c==1)
            {
                g_cSeries[240].data=t1;

            }
            else
            {
                g_cSeries[240].data=1;
            }
            if(b1==1)
            {
                if(g_cSeries[p1].data>20)
                {
                    g_cSeries[p1-1].data = g_cSeries[p1].data;
                    TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,g_cSeries[p1-1].data,GREEN);
                    TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,g_cSeries[p1-1].data+50,GREEN);
                    num=g_cSeries[p1-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,num,GREEN);
                    }
                    num=g_cSeries[p1-1].data+50;
                    for(;num<480;num++)
                   {
                    TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,num,GREEN);
                    }
                }
                else
                {
                    num=g_cSeries[p1-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,num,BLACK);
                    }
                    num=g_cSeries[p1-1].data+50;
                    for(;num<480;num++)
                   {
                        TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,num,BLACK);

                   }
                    TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,g_cSeries[p1-1].data,0);
                    TFTLCD_DrawPoint(g_cSeries[p1-1].xAxis,g_cSeries[p1-1].data+50,0);
                    g_cSeries[p1-1].data = g_cSeries[p1].data;

                }
                p1--;
            }

/*----------------------
 *
 *
 *
 * 60到120管道
 * ------------------------------
 */
            if(p1==120)
            {
                t2=g_cSeries[125].data;
                b2=1;
                g_cSeries[p2].data=t2;
                p1=p1+60;
            }
            if(b2==1)
            {
                if(g_cSeries[p2].data>20)
                {

                    g_cSeries[p2-1].data = g_cSeries[p2].data;
                    TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,g_cSeries[p2-1].data,GREEN);
                    TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,g_cSeries[p2-1].data+50,GREEN);
                    num=g_cSeries[p2-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,num,GREEN);
                    }
                    num=g_cSeries[p2-1].data+50;
                    for(;num<480;num++)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,num,GREEN);
                    }

                }
                else
                {
                    num=g_cSeries[p2-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,num,BLACK);
                    }
                    num=g_cSeries[p2-1].data+50;
                    for(;num<480;num++)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,num,BLACK);
                    }

                    TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,g_cSeries[p2-1].data,0);
                    TFTLCD_DrawPoint(g_cSeries[p2-1].xAxis,g_cSeries[p2-1].data+50,0);
                    g_cSeries[p2-1].data = g_cSeries[p2].data;

                }
                p2--;
            }
/*---------------------------
 *
 *
 * 0到60管道
 * ---------------------------
 */
            if(p2==60)
            {
                t3=g_cSeries[115].data;
                b3=1;
                g_cSeries[p3].data=t3;
                p2=p2+60;
            }
            if(b3==1)
            {
                if(g_cSeries[p3].data>20)
                {

                    g_cSeries[p3-1].data = g_cSeries[p3].data;
                    TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,g_cSeries[p3-1].data,GREEN);
                    TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,g_cSeries[p3-1].data+50,GREEN);
                    num=g_cSeries[p3-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,num,GREEN);
                    }
                    num=g_cSeries[p3-1].data+50;
                    for(;num<480;num++)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,num,GREEN);
                    }
                }
                else
                {
                    num=g_cSeries[p3-1].data;
                    for(;num>0;num--)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,num,BLACK);
                    }
                    num=g_cSeries[p3-1].data+50;
                    for(;num<480;num++)
                    {
                        TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,num,BLACK);
                    }
                    TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,g_cSeries[p3-1].data,0);
                    TFTLCD_DrawPoint(g_cSeries[p3-1].xAxis,g_cSeries[p3-1].data+50,0);
                    g_cSeries[p3-1].data = g_cSeries[p3].data;

                }
                p3--;
            }
            if(p3==0)
            {
                p3=60;
            }

            // We need to update sine value per Systick period.

            huaniao(x,y);
/*--------------------------
 *
 *
 *
 * 画出小鸟并让小鸟向下掉落
 * ----------------------
 *
 */

            i=i+1;
            if(i>3)
            {
                qingniao(x,y);

                y=y+7;
                i=0;

            }
            //UARTprintf("y=%d,data=%d\n",y,g_cSeries[x].data);

            /*`````````````````````````````
             *
             *
             *
             *死亡预设当小鸟碰到管道或在碰到屏幕边界
             *
             * `````````````````````````````````
             */
            if((y<g_cSeries[x].data)||(y>g_cSeries[x].data+40)&&(g_cSeries[x].data>20))
            {

                UARTprintf("gameover");
                end=1;

            }
            if(y<0||y>481)
            {
                UARTprintf("gameover");
                end=1;
            }
            /*-----------------------------
             *
             *
             * 出现gameover
             *
             * -----------------------------
             */
            if(end==1)
            {
                TFTLCD_CLEAR(BLACK);
                TFTLCD_ShowString(60,180,"game over",WHITE,BLACK);
                TFTLCD_ShowString(60,200,"ahahahahahhaha",WHITE,BLACK);
                TFTLCD_DrawHorizontalLine(60,180,240,WHITE);
                TFTLCD_DrawHorizontalLine(60,180,320,WHITE);
                TFTLCD_DrawVerticalLine(240,320,60,WHITE);
                TFTLCD_DrawVerticalLine(240,320,180,WHITE);
                TFTLCD_ShowString(80,260,"return",WHITE,BLACK);
                int lemon=0;
                /*-------------------------
                 *
                 *
                 * 判断是否触摸到gameover
                 *
                 *
                 * ------------------------
                 */
                while(end==1)
                {
                    if((TouchXData[10]<=240)&&(TouchYData[10]<=400))
                    {
                        if(TouchXData[10]<=180&&TouchXData[10]>=60&&TouchYData[10]>240&&TouchYData[10]<320)
                            end=0;
                    }

                    for(lemon=0;lemon<=9;lemon++)
                    {
                        SSIDataPut(SSI0_BASE,0x90);
                        SysCtlDelay(3);
                        SSIDataGet(SSI0_BASE,&TouchXData[lemon]);
                        SysCtlDelay(3);
                        SSIDataPut(SSI0_BASE,0xd0);
                        SysCtlDelay(3);
                        SSIDataGet(SSI0_BASE,&TouchYData[lemon]);
                        SysCtlDelay(3);
                    }
                    TouchXData[10] = (TouchXData[0]+TouchXData[1]+TouchXData[2]+TouchXData[3]+TouchXData[4]+TouchXData[5]+TouchXData[6]+TouchXData[7]+TouchXData[8]+TouchXData[9])/10;
                    TouchYData[10] = (TouchYData[0]+TouchYData[1]+TouchYData[2]+TouchYData[3]+TouchYData[4]+TouchYData[5]+TouchYData[6]+TouchYData[7]+TouchYData[8]+TouchYData[9])/10;

                    TOUCH_PointAdjust(&TouchXData[10], &TouchYData[10]);
                }
                if (start>high)
                    high=start;
                start=0;
                /*------------------------
                 * 复位出现开始
                 *
                 *
                 *
                 * ------------------------
                 */
                I2C0TubeLowSet(0x00);
                I2C0TubeHighSet(0x00);
                I2C0TubeSelSet(~0x08);
                int u;
                TFTLCD_CLEAR(BLACK);
                for( u=0;u<240;u++)
                {
                    g_cSeries[u].data=0;
                }
                for(u=0;u<11;u++)
                {
                    TouchXData[u]=0;
                    TouchYData[u]=0;
                }
                x=120;
                y=240;
                //showvalue(high);
                //I2C0TubeSelSet(~0x08);
                }
            }

        }
    }
}

实现效果如下图


希望看到的能在基础上进行改进

时间: 2024-10-30 15:35:20

管道鸟cortex-M4(TM4C1294)的相关文章

低功耗M2M市场广阔 芯片设计如何降耗

当前有关物联网的话题备受市场青睐.根据预测,到2020年左右世界上将有超过1000亿台设备实现联网.值得关注的是,这些设备中超过一半将对功耗问题十分敏感.因此,具有低功耗.高性能的,尤其是集成了无线通信功能的MCU解决方案将会受到重视.它在简化设计之余,可以让更多下游设计人员将联网设备推向市场. 物联网关注平均功耗 随着人与物.物与物连接的增多,未来将是千亿连接的时代,加之国际标准组织对技术标准制定工作的积极推动,低功耗M2M业务的市场前景十分广阔.对此,Silicon Labs 32位微控制器

智能家居引爆MCU需求 多样化市场应用或成推力

新一代年轻消费族群对于生活品质的需求逐渐提高,不仅小米要发展智能家居,中兴通讯也于上月22日正式于北京揭晓智慧家庭的新战略,研调机构预测全球智能家居设备和服务市场到了2018年,市场规模将达到680亿美元,可见"智能家居"将成为市场主流,而智能家居的崛起将引爆MCU(微控制器)的需求量迅速攀升,大陆以GigaDevice为首的MCU半导体厂商有望迎来庞大商机. 智能家居所需要的IC芯片与物联网主流芯片基本上是一致的,物联网的数据处理.加工.传输都离不开MCU,在物联网(IoT)发展趋势

VR/AR 时代就在眼前 (二)(作者:方如)

    VR/AR系统包括:头显.交互工具.内容制作工具.操作系统.渲染引擎和VR应用等,行业覆盖了硬件.系统.平台.开发工具.应用以及消费内容等诸多方面,还未完全成熟的产业,产业链还比较单薄, 内容提供方比较少.     不过,虽然VR/AR还处于发展初期,但从行业增速.用户关注.资本热度来看潜能巨大.2015年12月4日,百度视频宣布进军虚拟现实,计划在全国10多个大中型城市的100多家购物中心.影城举办大规模的VR线下免费体验活动.旨在通过线上内容聚合与线下体验活动的结合的方式全面实现虚拟

微软手环试用评测:硬件强大下的体验阴影

坚果网-全球酷玩试用社区 为你第一时间发现好玩的酷玩产品,并第一时间试用上(微信公众号:JguoJguo)今年以来,穿戴市场一片火热,各大科技巨头相继推出可穿戴产品和数字健康平台.前不久,作为PC巨头的微软也踏入了可穿戴产品市场,发布了自有品牌的健身跟踪器Microsoft Band,而经过千山万水,笔者也终于拿到了这款巨擎之作.基本参数产品尺寸:19×8.7mm产品重量:60g产品材质:热可塑橡胶处理器型号:ARM Cortex M4 MCU内存容量:64MB电池容量:2×100 mAh可充电

微软最新手环试用感受:技术强大体验渣

坚果网-全球酷玩试用社区 为你第一时间发现好玩的酷玩产品,并第一时间试用上(微信公众号:JguoJguo) 今年以来,穿戴市场一片火热,各大科技巨头相继推出可穿戴产品和数字健康平台.前不久,作为PC巨头的微软也踏入了可穿戴产品市场,发布了自有品牌的健身跟踪器--Microsoft Band,而经过千山万水,笔者也终于拿到了这款巨擎之作. 基本参数 产品尺寸:19×8.7mm 产品重量:60g 产品材质:热可塑橡胶 处理器型号:ARM Cortex M4 MCU 内存容量:64MB 电池容量:2×

源码-c#像素鸟代码问题,碰撞检测

问题描述 c#像素鸟代码问题,碰撞检测 项目源码链接:http://pan.baidu.com/s/1dEpefAx 密码:wi87 小鸟与管道的碰撞检测问题 1.小鸟与下管道GDDown碰撞有反应,但与GDUp管道碰撞没有反应 2.小鸟与地面picturebox1.Height接触时,提示发生碰撞确实在上管道以上的位置,与地面接触却没有提示 解决方案 http://www.narkii.com/club/thread-266478-1.html

80后技术宅发明“玩鸟机器人”破解虐心游戏

风靡一时的虐心小游戏<Flappy Bird>,以玩法简单.难度超高著称,不过,最近这款让全世界玩家几欲怒摔手机的游戏,被两位中国技术宅设计的"玩鸟机器人"搞定,疯狂突破百分.记者联系上两位80后小伙伴师雪坤和刘阳了解到,就 是因为游戏玩不下去才"小试牛刀"玩破解,而研发机器人是两人的兴趣点和事业未来.简易的"玩鸟机器人"正在闯关机器人让游戏高手望尘莫及flappy bird是不少玩家热衷的休闲游戏,超级玛丽游戏中的绿色通道.眼神 有

国内爆出的Android WebView安全漏洞会导致大量应用成为黑客管道

摘要: 创新工场旗下的上网快鸟向 36氪 透露,近期国内爆出的Android WebView安全漏洞会导致大量应用成为黑客管道.漏洞危及超过90%的安卓手机,当用户通过存在漏洞的APP打开挂马网页后,可被 创新工场旗下的上网快鸟向36氪透露,近期国内爆出的Android WebView安全漏洞会导致大量应用成为黑客管道.漏洞危及超过90%的安卓手机,当用户通过存在漏洞的APP打开挂马网页后,可被大规模利用,包括远程操控手机窃取隐私.扣费等. 根据上网快鸟联合创始人姜向前的介绍,该漏洞的原理是在A

Android WebView安全漏洞会导致大量应用成为黑客管道

摘要: 创新工场旗下的上网快鸟向 36氪 透露,近期国内爆出的Android WebView安全漏洞会导致大量应用成为黑客管道.漏洞危及超过90%的安卓手机,当用户通过存在漏洞的APP打开挂马网页后,可被 创新工场旗下的上网快鸟向36氪透露,近期国内爆出的Android WebView安全漏洞会导致大量应用成为黑客管道.漏洞危及超过90%的安卓手机,当用户通过存在漏洞的APP打开挂马网页后,可被大规模利用,包括远程操控手机窃取隐私.扣费等. 根据上网快鸟联合创始人姜向前的介绍,该漏洞的原理是在A