Code:
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>#include<ti/grlib/grlib.h>
#include"LcdDriver/Crystalfontz128x128_ST7735.h"
#include <stdint.h>
#include <stdbool.h>
Graphics_Context g_sContext;
volatile uint32_t radius;
volatile uint32_t timerflag;
volatile uint32_t timerflag2;
volatile uint32_t timerflag3;
volatile uint32_t x;
volatile uint32_t y;
volatile int32_t Vx;
volatile int32_t Vy;
volatile uint32_t window_height;
volatile uint32_t window_width;
volatile uint32_t paddleY;
const int32_t paddle_width= 16;
volatile uint32_t hits;
void draw(int32_t x,int32_t y,int32_t radius)
{
Graphics_fillCircle(&g_sContext,x,y,radius);
}
void erase(int32_t x,int32_t y,int32_t radius)
{
Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_WHITE);
Graphics_fillCircle(&g_sContext,x,y,radius);
Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_RED);
}
void erase_paddle(int32_t x, int32_t y)
{
Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_WHITE);
Graphics_drawLineV(&g_sContext, x, y, y + paddle_width -1);
Graphics_setForegroundColor(&g_sContext, GRAPHICS_COLOR_RED);
}
void draw_paddle(int32_t x, int32_t y)
{
Graphics_drawLineV(&g_sContext, x, y, y + paddle_width -1);
}
int main(void)
{
SysTick_enableModule();
GPIO_setAsInputPin(GPIO_PORT_P5, GPIO_PIN1);
GPIO_setAsInputPin(GPIO_PORT_P3, GPIO_PIN5);
GPIO_clearInterruptFlag(GPIO_PORT_P5, GPIO_PIN1);
GPIO_clearInterruptFlag(GPIO_PORT_P3, GPIO_PIN5);
GPIO_interruptEdgeSelect(GPIO_PORT_P5, GPIO_PIN1,GPIO_HIGH_TO_LOW_TRANSITION);
GPIO_interruptEdgeSelect(GPIO_PORT_P3, GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);
GPIO_enableInterrupt(GPIO_PORT_P5, GPIO_PIN1);
GPIO_enableInterrupt(GPIO_PORT_P3, GPIO_PIN5);
Interrupt_enableInterrupt(INT_PORT5);
Interrupt_enableInterrupt(INT_PORT3);
Interrupt_enableMaster();
Crystalfontz128x128_Init();
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP);
Graphics_initContext(&g_sContext,&g_sCrystalfontz128x128,&g_sCrystalfontz128x128_funcs);
Graphics_setForegroundColor(&g_sContext,GRAPHICS_COLOR_RED);
Graphics_setBackgroundColor(&g_sContext,GRAPHICS_COLOR_WHITE);
GrContextFontSet(&g_sContext,&g_sFontFixed6x8);
Graphics_clearDisplay(&g_sContext);
MAP_WDT_A_holdTimer();
y = 64;
x = 64;
Vx = 1;
Vy =-1;
radius = 3;
window_height = 127;
window_width = 127;
paddleY = 64;
draw_paddle(120,paddleY);
SysTick_setPeriod(90000);
SysTick_enableInterrupt();
while(1)
{
if(x <= 0 || x >= window_width-5)
Vx*= -1;
if(y <= 0 || y >= window_height -5)
Vy*= -1;
if(timerflag==1)
{
draw(x,y,radius);
erase(x,y,radius);
timerflag = 0;
}
if(timerflag2==1)
{
erase_paddle(120,paddleY+paddle_width+1);
draw_paddle(120,paddleY);
timerflag2 = 0;
}
if(timerflag3==1)
{
erase_paddle(120,paddleY-paddle_width+1);
draw_paddle(120,paddleY);
timerflag3 = 0;
}
}
}
void SysTick_Handler(void)
{
timerflag = 1;
if(x+radius <127 || x-radius>0)
{
if(y+radius <127 || y-radius>0)
{
x+=Vx;
y+=Vy;
}
}
if(x+radius==127 || x-radius==0)
{
Vx*= -1;
}
if(y+radius ==127 || y-radius==0)
{
Vy*= -1;
}
}
void PORT5_IRQHandler(void)
{
uint32_t status;
status= GPIO_getEnabledInterruptStatus(GPIO_PORT_P5);
GPIO_clearInterruptFlag(GPIO_PORT_P5, status);
timerflag2=1;
if(status & GPIO_PIN1)
{
timerflag2=1;
paddleY-= paddle_width-1;
}
}
void PORT3_IRQHandler(void)
{
uint32_t status;
status= GPIO_getEnabledInterruptStatus(GPIO_PORT_P3);
GPIO_clearInterruptFlag(GPIO_PORT_P3, status);
if(status & GPIO_PIN5)
{
timerflag3=1;
paddleY+= paddle_width-1;
}
}