看到满屏的贪吃蛇,我也来开源一个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();elseI2C_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
#endifvoid
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);}}}}
}

实现效果如下图


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

管道鸟cortex-M4(TM4C1294)相关推荐

  1. ST-LINK下载程序出现flash download failed - ‘cortex m4‘

    ST-LINK下载程序出现flash download failed - 'cortex m4' 可能原因:项目测试时使用ST-link下载程序调试,之前都好好的可以下载程序,之后可能做掉电存储等一些 ...

  2. ARM Cortex M4使用浮点运算单元(FPU)

    1.ARM Cortex M4   ARM Cortex-M4处理器是由ARM专门开发的最新嵌入式处理器,在M3的基础上强化了运算能力,新加了浮点.DSP.并行计算等.Cortex-M4处理器的最大亮 ...

  3. Helix MP3 解码器在cortex m4应用

    Helix MP3 解码器在cortex m4应用 Helix MP3 解码器可浮点和定点实现.该算法可运行在任意 32 位定点处理器上,并完全使用 C 语言编码,可选择用优化的汇编指令替换某些代码段 ...

  4. 国内LORA首颗SOC芯片ASR6601ARM Cortex M4

    ASR6601是一种通用的LPWAN无线通信芯片组,集成射频收发器.调制解调器和32位RISC MCU.MCU使用ARM Cortex M4,频率为48 MHz工作频率.射频150MHZ-960MHZ ...

  5. Cortex M4 中断向量表

    前言 重新学习Cortex M4的中断向量表内容.中断向量表是Cortex M4自带的功能,厂家可以根据需要自行定义,所以需要学习该内容,直接看Cortex M4内核相关即可.我这查看的是<Co ...

  6. stm32cubeide烧写程序_stm32mp157 Cortex M4开发篇:stm32CubeIDE开发环境搭建

    写在前面: 本文章为<STM32MP1系列教程之Cortex-M4开发篇>系列中的一篇,全系列总计11篇.笔者使用的开发平台为华清远见FS-MP1A开发板(STM32MP157开发板).针 ...

  7. cortex m4 中文手册_江淮瑞风M4柴油版上市 售13.88-15.48万

    [太平洋汽车网 新车频道]4月18日,江淮瑞风M4柴油版车型正式上市.新车共推出三款配置车型,售价区间为13.88-15.48万元.新车外观与现款车型保持一致,搭载一台2.0T柴油发动机,并满足国六排 ...

  8. cortex m4 中文手册_奥迪RS4 Avant都来了,新一代宝马M4还会远吗?

    在上个月的20号,新款奥迪RS 4 Avant已经上市,售价为81.28万元,相比此前车型的售价有稍微降低了一些.新款奥迪RS 4 Avant的上市也让很多人开始期待另外一款车型,那就是全新的宝马M4 ...

  9. stm32mp1 Cortex M4开发篇12:扩展板震动马达控制

    写在前面: 本文章为<ARM Cortex-M4裸机开发篇>系列中的一篇,,全系列总计14篇.笔者使用的开发平台为华清远见FS-MP1A开发板(STM32MP157开发板),Cortex- ...

最新文章

  1. 【MRCTF—Web】做题+复现记录
  2. 在WPF中进行碰撞检测
  3. 如何在keil下实现单工程多目标的设置(选择性自动编译)
  4. java 注解scheduler_使用spring的@Scheduled注解执行定时任务,启动项目不输出警告
  5. 如何使用单线程处理高并发
  6. NAND FLASH Controler for IMX31
  7. php get请求_《细说PHP》第四版 样章 第23章 自定义PHP接口规范 10
  8. 取文字_玉镯取不出来了怎么办?教你6种最有效的方法
  9. 小猿圈学习Linux之shell脚本中cd命令无效的解决方法
  10. ZendFramework-2.4 源代码 - 整体架构(类图)
  11. keil中L6002U的error原因之一
  12. 海马汽车经销商管理系统技术解析(四)保养管理
  13. 中国Linux杰出人物
  14. 超强可视化图表工具:Smartbi!!
  15. 如何将pdf转换成ppt?
  16. 2023年重庆邮电大学计算机科学与技术(802)初试经验贴
  17. [28期] 坚定信念,抗战二十年
  18. 关于图片的多标签分类(1)
  19. 修理牧场( 哈夫曼算法 ,贪心 )
  20. 前端三剑客 HTML、CSS、JavaScript 入门到上手

热门文章

  1. easyexcel表头单个字体样式注解使用
  2. 基础算法思想之贪心法
  3. python西游之路
  4. Refused to display 'XXX' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
  5. python下载地址到迅雷qq旋风下载
  6. EN50155是什么,轨道交通设备EN50155测试
  7. 设计模式之禅的学习感触
  8. 2017CME中国机床展会刊(参展商名录)
  9. 最全的Matlab工具箱免费分享
  10. linux、FreeBSD网桥转发性能对比