Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <basedef.h>
- #include <Board.h>
- #include <stdio.h>
- #include <fixedsys.h>
- #include <lcd_GE8.h>
- #define BIT_SW1 0x01000000
- #define BIT_SW2 0x02000000
- #define JOY_LEFT 0x80
- #define JOY_DOWN 0x100
- #define JOY_UP 0x200
- #define JOY_RIGHT 0x4000
- #define JOY_CLICK 0x8000
- #define CIRCLES 4
- #define CIRCLE_STEP 5
- #define CIRCLE_X_BEGIN 20
- #define CIRCLE_Y_BEGIN 20
- #define CIRCLE_RADIUS 10
- void Delay (unsigned long a) {while (--a!=0);}
- typedef struct {
- int pos_x;
- int pos_y;
- char flags;
- } circle;
- circle circles[CIRCLES];
- int total_circles = 0;
- int selected_circle = 0;
- void drawCircle(circle toDraw) {
- if(toDraw.flags && CIRCLE_SELECTED) {
- LCDSetCircle(toDraw.pos_x, toDraw.pos_y, CIRCLE_RADIUS, LCD_COLOR_GREEN);
- } else {
- LCDSetCircle(toDraw.pos_x, toDraw.pos_y, CIRCLE_RADIUS, LCD_COLOR_RED);
- }
- }
- int main()
- {
- int circle_x = 20;
- int circle_y = 20;
- int step = 5;
- AT91PS_PIO p_pPioA = AT91C_BASE_PIOA;
- AT91PS_PIO p_pPioB = AT91C_BASE_PIOB;
- AT91PS_PMC p_pPMC = AT91C_BASE_PMC;
- AT91PS_SYS p_pSys = AT91C_BASE_SYS;
- /* Initialize the Atmel AT91SAM7X256 (watchdog, PLL clock, default interrupts, etc.) */
- AT91F_LowLevel_Init();
- //enable the clock of the PIO
- p_pPMC->PMC_PCER = 1 << AT91C_ID_PIOA;
- //enable the clock of the PIO
- p_pPMC->PMC_PCER = 1 << AT91C_ID_PIOB;
- // GPIO init
- p_pPioA->PIO_ODR = 0xffffffff; // All as input
- p_pPioB->PIO_ODR = 0xffffffff; // All as input
- p_pSys->PIOA_PPUDR = 0xffffffff; // Disable Pull-up resistor
- p_pSys->PIOB_PPUDR = 0xffffffff; // Disable Pull-up resistor
- // BUTTON SW1
- p_pPioB->PIO_ODR |= BIT_SW1; //Configure in Input
- p_pPioB->PIO_PER |= BIT_SW1; //Enable PB24
- // BUTTON SW2
- p_pPioB->PIO_ODR |= BIT_SW2; //Configure in Input
- p_pPioB->PIO_PER |= BIT_SW2; //Enable PB25
- //joystick
- p_pPioA->PIO_ODR |= JOY_LEFT; //Configure in Input
- p_pPioA->PIO_PER |= JOY_LEFT;
- p_pPioA->PIO_ODR |= JOY_DOWN; //Configure in Input
- p_pPioA->PIO_PER |= JOY_DOWN;
- p_pPioA->PIO_ODR |= JOY_UP; //Configure in Input
- p_pPioA->PIO_PER |= JOY_UP;
- p_pPioA->PIO_ODR |= JOY_UP; //Configure in Input
- p_pPioA->PIO_PER |= JOY_UP;
- p_pPioA->PIO_ODR |= JOY_RIGHT; //Configure in Input
- p_pPioA->PIO_PER |= JOY_RIGHT;
- p_pPioA->PIO_ODR |= JOY_CLICK; //Configure in Input
- p_pPioA->PIO_PER |= JOY_CLICK;
- /* Init the LCD */
- InitLCD();
- LCD_ClearScreen( LCD_COLOR_WHITE );
- /* enable interrupts */
- AT91F_Finalize_Init();
- /* add your program here ... */
- // LCD_WriteString("Hello world!", &Fixedsys_descriptor, 2, 20, LCD_COLOR_WHITE, LCD_COLOR_RED);
- /* ... and here */
- while ( true )
- {
- LCDSetRect(20, 20, 60, 60, 0, LCD_COLOR_BLACK);
- if(!((p_pPioB->PIO_PDSR) & BIT_SW1) || !((p_pPioA->PIO_PDSR) & JOY_CLICK))
- {
- if(total_circles < CIRCLES) {
- total_circles++;
- circles[total_circles].pos_x = CIRCLE_X_BEGIN + 10*total_circles;
- circles[total_circles].pos_y = CIRCLE_Y_BEGIN;
- }
- drawCircle(circles[total_circles]);
- }
- if(!((p_pPioA->PIO_PDSR) & JOY_RIGHT))
- {
- circles[selected_circle].pos_x += CIRCLE_STEP;
- drawCircle(circles[selected_circle]);
- }
- if(!((p_pPioA->PIO_PDSR) & JOY_LEFT))
- { circles[selected_circle].pos_x -= CIRCLE_STEP;
- drawCircle(circles[selected_circle]);
- }
- if(!((p_pPioA->PIO_PDSR) & JOY_DOWN))
- {
- LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_WHITE);
- circle_y += step;
- LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_RED);
- }
- if(!((p_pPioA->PIO_PDSR) & JOY_UP))
- {
- LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_WHITE);
- circle_y -= step;
- LCDSetCircle(circle_x, circle_y, 10, LCD_COLOR_RED);
- }
- }
- /* Actually, the execution never gets here */
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement