int main(void){
	TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	
	DisableInterrupts();
	
	
	Random_Init(1);
	
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();
	
	SysTick_Init();
	// initialize Timer2 after Nokia5110_Init because of
	// error-prone registers operations (old and new registers
	// are not working good together)
	// 80MHz/11,025 cycles, which is about 7256
	Timer2_Init(7256);
	Ports_Init();
	
	InitSprites(NumberOfEnemies);
	RestartGame();
	
	// Countdown, after which all interrupts are enabled!
	// print 3
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 2
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 1
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print GO
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	
	
	EnableInterrupts();
	
  while(1){
		if (Flag == 1) {
			Nokia5110_DisplayBuffer();
			
			Flag = 0;
		}
	}
	
}
示例#2
0
文件: 1602.c 项目: hxl9654/C51_Study
void main()
{
	uint8 idata str1[100],str2[100];
	uint8 i,index=0;
	lcdinit();
	lcdinit();
	for(i=0;i<16;i++)
	{
		str1[i]=' ';
		str2[i]=' ';
		str1[16+sizeof(string1)+i]=' ';
		str2[16+sizeof(string2)+i]=' ';
	}
	for(i=0;i<sizeof(string1);i++)
		{
			str1[16+i]=string1[i];
			str2[16+i]=string2[i];
		}
	i--;
	str1[16+i]=' ';
	str2[16+i]=' ';
	while(1)
	{
	lcdshow(0,0,str1+index,16);
	lcdshow(0,1,str2+index,16);
	Delay100ms();
	index++;
	if(index>=(15+sizeof(string1)))index=0;	
	}
}
int main(void){ unsigned long volatile delay;
  TExaS_Init(SW_PIN_PF4, LED_PIN_PF2);  // activate grader and set system clock to 80 MHz
  // initialization goes here
	
	
  SYSCTL_RCGC2_R |= 0x00000020;     // 1) activate clock for Port F
  delay = SYSCTL_RCGC2_R;           // allow time for clock to start
//  GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F
//  GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
  // only PF0 needs to be unlocked, other bits can't be locked
  GPIO_PORTF_AMSEL_R &= ~0x14;        // 3) disable analog on PF2,4
  GPIO_PORTF_PCTL_R &= ~0x000F0F00;   // 4) PCTL GPIO on PF2,4
  GPIO_PORTF_DIR_R &= ~0x10;          // 5) PF4 in,
	GPIO_PORTF_DIR_R |= 0x04;           // PF2 out
  GPIO_PORTF_AFSEL_R &= ~0x14;        // 6) disable alt funct on PF7-0
  GPIO_PORTF_PUR_R |= 0x10;          // enable pull-up on  PF4
  GPIO_PORTF_DEN_R = 0x14;          // 7) enable digital I/O on PF2,4
  GPIO_PORTF_DATA_R |= 0x04;         // set pf2 on

  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    // body goes 
		Delay100ms(1);
		if(GPIO_PORTF_DATA_R&0x10) GPIO_PORTF_DATA_R |= 0x04;
		if(!(GPIO_PORTF_DATA_R&0x10)) GPIO_PORTF_DATA_R ^= 0x04;
		
  }
}
int main(void){
	DisableInterrupts();
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	Random_Init(1);
  Nokia5110_Init();
	PF1Init();
  //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts
	SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
	ADC0_Init();
	Game_Init();
	SwitchLed_Init();
	Sound_Init();
	Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256
	GameOverFlag = 0;
	EnableInterrupts();
	
  while(1){
		while(Semaphore==0){};
    Semaphore = 0;
		if(GameOverFlag){
			State_GameOver();
		}
		else{
			Draw_GameFrame(); // update the LCD
		}	
		if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over
			Delay100ms(2);//Delay 200ms
			GameOverFlag = Check_GameOver();
			//SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt
			SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
		}
	}
}
int main(void){ unsigned long volatile delay;
  TExaS_Init(SW_PIN_PF4, LED_PIN_PF2);  // activate grader and set system clock to 80 MHz
  // initialization goes here
	SYSCTL_RCGC2_R = SYSCTL_RCGC2_R | SYSCTL_RCGC2_GPIOF; // eja :::: Turn on the clock for PortF.
	delay = SYSCTL_RCGC2_R; // eja :::: give clock time to stablize.
	GPIO_PORTF_AMSEL_R = GPIO_PORTF_AMSEL_R & ~0x14; // eja :::: clear bits 4(switch 1) and 2(blue led) in the AMSEL registor. 
	GPIO_PORTF_PCTL_R = GPIO_PORTF_PCTL_R & ~0x000F0F00; // eja :::: clear pins PF4 and PF2 in the P control registor to configure as GPIO.
	GPIO_PORTF_DIR_R = 0x0E; // eja :::: set bits 4 and 0 and clear bits 3, 2, and 1 in the direction registor.
	GPIO_PORTF_AFSEL_R = 0x0000; // eja :::: clear all bits in the AFSEL registor.
	GPIO_PORTF_DEN_R = 0x1F; // eja :::: enable digital for pins PF4, PF3, PF2, PF1, PF0. 
	GPIO_PORTF_PUR_R = 0x11; //eja :::: enable pullup resistors for PF4, PF3, PF2, PF1, PF0.
	GPIO_PORTF_DATA_R = GPIO_PORTF_DATA_R | 0x04; // eja :::: set bit 2 in the data registor to turn led on.

  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    // body goes here
		Delay100ms(1); //eja :::: waits 100ms.
		in = GPIO_PORTF_DATA_R&0x10; //eja :::: reads value of PF4 into in.
		if (in == 0) { //eja :::: conditional if statement testing if the value of in is 0.
			GPIO_PORTF_DATA_R = GPIO_PORTF_DATA_R ^ 0x04; //eja :::: toggle bit 2(blue led)
		} //eja :::: ending of if statement and test.
		if (in == 1) { //eja :::: conditional if statement testing if the value of in is 1.
			GPIO_PORTF_DATA_R = GPIO_PORTF_DATA_R | 0x04; // eja :::: set bit 2 so as to turn led on.
		} //eja :::: end of if statement and test.
  }
}
int main(void){ 
	unsigned long volatile delay;
	unsigned long In;
  TExaS_Init(SW_PIN_PF4, LED_PIN_PF2);  // activate grader and set system clock to 80 MHz
  // initialization goes here
	PortF_Init();
  EnableInterrupts();           // enable interrupts for the grader
	
	GPIO_PORTF_DATA_R = 0x04;
	
  while(1){
    // body goes here	
		Delay100ms(1);
		In = GPIO_PORTF_DATA_R&0x10;
		if(In == 0x00)
		{
			//Switch is pressed toggel PF2
			GPIO_PORTF_DATA_R = GPIO_PORTF_DATA_R ^ (1 << 2);
		}
		else
		{
			//Switch is not pressed, set PF2 to on
			GPIO_PORTF_DATA_R = 0x04;
		}
  }
}
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Random_Init(1);
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();     // draw buffer

  Delay100ms(50);              // delay 5 sec at 50 MHz


  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  while(1){
  }

}
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Random_Init(1);

  Output_Init();
  ST7735_FillScreen(0x0000);            // set screen to black
  
  ST7735_DrawBitmap(52, 159, PlayerShip0, 18,8); // player ship middle bottom
  ST7735_DrawBitmap(53, 151, Bunker0, 18,5);

  ST7735_DrawBitmap(0, 9, SmallEnemy10pointA, 16,10);
  ST7735_DrawBitmap(20,9, SmallEnemy10pointB, 16,10);
  ST7735_DrawBitmap(40, 9, SmallEnemy20pointA, 16,10);
  ST7735_DrawBitmap(60, 9, SmallEnemy20pointB, 16,10);
  ST7735_DrawBitmap(80, 9, SmallEnemy30pointA, 16,10);
  ST7735_DrawBitmap(100, 9, SmallEnemy30pointB, 16,10);


  Delay100ms(50);              // delay 5 sec at 80 MHz


  ST7735_FillScreen(0x0000);            // set screen to black
  ST7735_SetCursor(1, 1);
  ST7735_OutString("GAME OVER");
  ST7735_SetCursor(1, 2);
  ST7735_OutString("Nice try,");
  ST7735_SetCursor(1, 3);
  ST7735_OutString("Earthling!");
  ST7735_SetCursor(2, 4);
  LCD_OutDec(1234);
  while(1){
  }

}
示例#9
0
main()
{
        char i ;                //宣告字元變數 i
        i=0 ;                   //令 i 等於 0
        for(;;){
            P0=sstbl[i++] ;     //取得資料表 sstbl 第 i 筆資料並輸出至 P0
            if(i >=16)          //若 i 大於等於 10 則
                i=0 ;           //設 i 為 0 重新顯示
            Delay100ms() ;      //呼叫延遲 100 毫秒副程式
        }
}
示例#10
0
main()
{
 int Step ;		//定義Step為整數變數
 char idx_pp=0 ;	//定義idx_pp為字元變數其數值為0
 for(Step=0;Step<(n*2+1);Step++) 
 {//若Step<n*2+1,則繼續執行迴圈
 P0=pp[idx_pp++]; //P0=idx_pp所指之pp的資料,推動步進馬達
 if(idx_pp==8)	//若idx_pp=8,則
    idx_pp=0 ;	//還原資料
 Delay100ms() ;	//呼叫延遲100毫秒
 }
}
示例#11
0
文件: touchpad.c 项目: lll7/SmartTP
unsigned char TPReset() {
    Delay100ms(20);
    Debug("RST:");
    TPSendByte(TP_CMD_RESET); //reset
    STP.TPModule.U8LastData[0] = TPGetByte();
    STP.TPModule.U8LastData[1] = TPGetByte();
    DebugHex1(STP.TPModule.U8LastData[0]);
    Debug(" ");
    DebugHex1R(STP.TPModule.U8LastData[1]);
    if ((STP.TPModule.U8LastData[0] != 0xAA) || (STP.TPModule.U8LastData[1] != 0x00))
        return 0;
    return 1;
}
示例#12
0
int main(void){
  PLL_Init();                   // set system clock to 80 MHz
  Random_Init(1);
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
  Init();
  Draw();
  while(1){
    Move();
    Draw();
    Delay100ms(2);
  }
}
示例#13
0
void main()
{
	UART_T1_Init();
	P3M0 = 0x00; P3M1 = 0x00;
	Timer2Init();
	Interrput_Init();
	DoorNotCloseFlag = P33;
	P34 = ~P33;
	WDT_CONTR = 0x37;
	while(1)
	{
		WDT_CONTR |= 0x10;
		Delay100ms();
		UART_Driver();
	}
}
示例#14
0
main()
{
    char i ;                //宣告字元變數 i (代表要顯示之數值)
    i=0 ;                   //令 i 等於 0
    for(i=0; i<100; i++) {

        P1=0xff ;          //關閉七段顯示器
        P0=sstbl[i/10];    //將顯示值經轉換計算後顯示於第三顆
        P1=0xFD;           //掃描第三顆七段顯示器

        P1=0xff ;          //關閉七段顯示器
        P0=sstbl[i%10];    //將顯示值經轉換計算後顯示於第四顆
        P1=0xFE;           //掃描第四顆七段顯示器
        Delay100ms() ;     //呼叫延遲 100 毫秒副程式
    }
}
int main(void)
{ 
	TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  								// activate grader and set system clock to 80 MHz
  PortE_Init();
	
  EnableInterrupts();           												// enable interrupts for the grader
  while(1)
	{
     Delay100ms(1);
     In = GPIO_PORTE_DATA_R&0x01;   										// read PE0 into In
     if (In == 0x01) 
         GPIO_PORTE_DATA_R = GPIO_PORTE_DATA_R ^ 0x02;	// toggle the LED
     else 
         GPIO_PORTE_DATA_R |= 0x02;         						// the LED ON (make PE1 =1). 
  }
}
示例#16
0
void LCD_init()
{
    // wait for Power on reset
    Delay100ms();

    //Hold RS in a low state
    PORTEbits.RE0 = 0;

    //Function Set in 8-bit mode
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x30; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Function Set in 8-bit mode
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x30; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Function Set in 8-bit mode
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x30; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //4-bit Initialization
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x20; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Function Set, specify display size and font
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x20; PORTEbits.RE1 = 0;
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x80; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Display ON
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x00; PORTEbits.RE1 = 0;
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0xF0; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Clear Display
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x00; PORTEbits.RE1 = 0;
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x10; PORTEbits.RE1 = 0;
    __delay_ms(10);
    
    //Entry Mode Set
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x00; PORTEbits.RE1 = 0;
    PORTEbits.RE1 = 1; PORTD = (PORTD & 0b00001111) | 0x60; PORTEbits.RE1 = 0;
    __delay_ms(10);

    //Set DDRAM Address
    place_lcd_cursor(0,0);
}
int main(void){ int AnyLife = 1; int i;
  TExaS_Init(NoLCD_NoScope);  // set system clock to 80 MHz
  // you cannot use both the Scope and the virtual Nokia (both need UART0)
  Random_Init(1);
  Nokia5110_Init();
  EnableInterrupts(); // virtual Nokia uses UART0 interrupts
  
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();   // draw buffer

  Delay100ms(50);              // delay 5 sec at 80 MHz

  Init();
  Timer2_Init(80000000/30);  // 30 Hz
  while(AnyLife){
    while(Semaphore == 0){};
    Semaphore = 0; // runs at 30 Hz
    AnyLife = 0;
    for(i=0; i<4 ; i++){
      AnyLife |= Enemy[i].life;
    }
    Draw();
  }
  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  Nokia5110_SetCursor(0, 0); // renders screen
  while(1){
  }

}
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10 k ohm pull down resistor
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or 
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
// 1) Make PE1 an output and make PE0 an input.
// 2) The system starts with the LED on (make PE1 =1).
// 3) Wait about 100 ms
// 4) If the switch is pressed (PE0 is 1), then toggle the LED once, else turn the LED on.
// 5) Steps 3 and 4 are repeated over and over.
int main(void){ 
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
  TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  // activate grader and set system clock to 80 MHz
  PortE_Init();
  EnableInterrupts();           // enable interrupts for the grader
  while(1){
		Delay100ms(time_delay);
		button = GPIO_PORTE_DATA_R&0x01;   		  // read PE0 into the switch
		if(button == 1){
			GPIO_PORTE_DATA_R ^=0x02;					// Toggle PE1
		}else{
			GPIO_PORTE_DATA_R |=0x02;					// Set PE1
		}
  }
  
}
示例#19
0
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10 k ohm pull down resistor
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or 
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
int main(void){ 
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
  TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  // activate grader and set system clock to 80 MHz
  PortE_Init();
	
  EnableInterrupts();           // enable interrupts for the grader
  while(1){
     Delay100ms(1);
     In = GPIO_PORTE_DATA_R&0x01;   // read PE0 into In
     if (In == 0x01) {
         GPIO_PORTE_DATA_R = GPIO_PORTE_DATA_R ^ 0x02; // toggle the LED
     } else {
         GPIO_PORTE_DATA_R |= 0x02;         // the LED ON (make PE1 =1). 
     }

  }
  
}
int main(void){ 
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
  TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  // activate grader and set system clock to 80 MHz
  InitPorts();
	
	
  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    Delay100ms(1);
		
		in = GPIO_PORTE_DATA_R & 0x01; // in 0 if not pressed, 1 if pressed
		
		if (in && 0x01) { // switch is pressed
			GPIO_PORTE_DATA_R ^= 0x02; // toggle LED			
		} else {
			LED_On();
		}
  }  
}
// PE0, PB0, or PA2 connected to positive logic momentary switch using 10k ohm pull down resistor
// PE1, PB1, or PA3 connected to positive logic LED through 470 ohm current limiting resistor
// To avoid damaging your hardware, ensure that your circuits match the schematic
// shown in Lab8_artist.sch (PCB Artist schematic file) or 
// Lab8_artist.pdf (compatible with many various readers like Adobe Acrobat).
int main(void){ 
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
  TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  // activate grader and set system clock to 80 MHz
  PortE_Init();
	
  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    // body goes here
		//for(i=0;i<2666667;i++); // Delay for about 100 ms 100 ms * 80 MHZ/3
		Delay100ms(1);
		In = GPIO_PORTE_DATA_R&0x01; // read PE0 into Sw1
		if (In == 0x01) {
			GPIO_PORTE_DATA_R = GPIO_PORTE_DATA_R ^ 0x02;
		} 
		else {
			GPIO_PORTE_DATA_R |= 0x02;
		}
  }
  
}
示例#22
0
 void Timer2A_Handler(void){ 
	ST enemy;
  TIMER2_ICR_R = 0x00000001;   // acknowledge timer2A timeout
  q++;
	 d=(Random())%4;
	 k=(Random())%4;
	 s=(d+k)%4;
	 if(q<10){
	 enemy.x=Enemy[s].x;
	 enemy.y=Enemy[s].y;
	 enemy.life=1;
		 enemy.b=0;
	 enemy.image[0]=Black;
	 enemy.image[1]=Dead;
	 }
	 else 
	 {
	 enemy.x=Enemy[s].x;
	 enemy.y=Enemy[s].y;
	 enemy.life=1;
	 enemy.image[0]=bomp;
	 enemy.image[1]=bomp;
	 enemy.b=1;
	 q=0;
	 }
	 for(i=0;i<30;i++)
	 {
		 if(vector[i].fl==0)
		 {
			 vector[i]=enemy;
			 vector[i].fl=1;
			 vector[i].life=1;
			 o++;
		 break;
		 }
	 }
	 Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(LFish.x, LFish.y, LFish.image[0], 0);
	
    for(p=0;p<30;p++){
			if(vector[p].fl==1 && vector[p].life==1){
	 if(vector[p].x >0){
      vector[p].x -= 10;
      if(((((LFish.y-16)<vector[p].y) && (vector[p].y<=(LFish.y)))||((vector[p].y-16)<LFish.y && (vector[p].y-16)<LFish.y))&& (vector[p].x<=17) && (vector[p].b==0 ))
			{				
				Score+=10;
				vector[p].life=0;
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[1], 0);
				o--;
			}
			else if((((LFish.y-16)<vector[p].y)&& (vector[p].y<=(LFish.y+4))) &&(vector[p].x<=17) && vector[p].b==1){
	 Nokia5110_ClearBuffer();
		Nokia5110_DisplayBuffer(); 
			 Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
			Nokia5110_SetCursor(1, 4);
			Nokia5110_OutString("Score: ");
		 Nokia5110_SetCursor(6, 4);
  Nokia5110_OutUDec(Score);
		 Delay100ms(50);   
exit(0);			
	 }
			else
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0);
			
		}
		else if (vector[p].x==0){
			vector[p].fl=0;
			vector[p].life=0;
	    o--;
		}
	}
		if(p>=o)break;
		}
 Nokia5110_DisplayBuffer();
}
示例#23
0
int main(void)
{
	int data;
	int index=0;
	char buffer[100];
	Config32MHzClock();

	CLK.PSCTRL = 0x00; // no division on peripheral clock

	UsartInit();
	
	UsartWriteString("\r\n\r\nBOOT: Starting...\r\n");

	//Analog Mux
	PORTF.DIR = 0b11111111; //Output

	PORTF.OUTCLR = PIN6_bm;
	PORTF.OUTCLR = PIN4_bm | PIN7_bm;
	PORTF.OUTSET = PIN5_bm;

	PORTF.OUTCLR = PIN0_bm | PIN1_bm | PIN2_bm | PIN3_bm;
	//PORTF.OUTSET = PIN1_bm;

	PORTF.OUTCLR = PIN6_bm;
	PORTF.OUTSET = PIN4_bm;
	PORTF.OUTCLR = PIN5_bm;
	PORTF.OUTSET = PIN7_bm; //WR

	UsartWriteString("BOOT: Analog Mux configured...\r\n");

	//ADC
	PORTQ.DIR = 0b1111; //Output
	PORTQ.OUTCLR = PIN1_bm | PIN3_bm; //PWRDWN pins

	PORTQ.OUTSET = PIN0_bm | PIN2_bm; //ENCODE pins

	//Reading Values
	PORTD.DIR = 0b00000000; //Input
	PORTE.DIR = 0b00000000; //Input

	UsartWriteString("BOOT: ADC configured...\r\n");

	//TFT LCD
	TFT_init();

	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	Delay100ms(10);
	
	TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL);
	/*
	TSLCDFillRect(0,TS_SIZE_X-1,0,70,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDSetFontColor(TS_COL_BLUE);
	TSLCDPrintStr(2,6,"Testing ELT240320TP with AVR",TS_MODE_NORMAL);
	TSLCDFillRect(20,80,90,130,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillRect(30,90,100,140,TS_COL_YELLOW,TS_MODE_NORMAL);
	TSLCDFillRect(20,80,160,200,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillRect(30,90,170,210,TS_COL_RED,TS_MODE_NORMAL);
	TSLCDFillRect(195,205,71,TS_SIZE_Y-1,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,60,TS_COL_WHITE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,50,TS_COL_BLUE,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,40,TS_COL_BLACK,TS_MODE_NORMAL);
	TSLCDFillCirc(200,155,30,TS_COL_RED,TS_MODE_NORMAL);
	*/
	
	UsartWriteString("BOOT: TFT LCD configured...\r\n");

	//Timing Lines

	//INT0: breakoutbar6 / A0 / frame
	//INT1: slicebin0 / A1 / pixel
	PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT0LVL_gm ) | PORT_INT0LVL_LO_gc; 
	PORTA.INTCTRL = (PORTA.INTCTRL & ~PORT_INT1LVL_gm ) | PORT_INT1LVL_LO_gc;

	//Detect rising edge only
	PORTA.PIN0CTRL |= 0x01;
	PORTA.PIN0CTRL &= ~0x06;
	PORTA.PIN1CTRL |= 0x01;
	PORTA.PIN1CTRL &= ~0x06;

    PORTA.INT0MASK = PIN0_bm;
	PORTA.INT1MASK = PIN1_bm;
	
	UsartWriteString("BOOT: Interrupts configured...\r\n");
	
	//EBI/SDRAM
	ebi_setup_port(12, 0, 0, EBI_PORT_3PORT | EBI_PORT_SDRAM);
	/*
	 * Configure the EBI chip select for an 8 MB SDRAM located at
	 * \ref BOARD_EBI_SDRAM_BASE.
	 */
	ebi_cs_set_mode(&cs_config, EBI_CS_MODE_SDRAM_gc);
	ebi_cs_set_address_size(&cs_config, EBI_CS_ASPACE_8MB_gc);
	ebi_cs_set_base_address(&cs_config, BOARD_EBI_SDRAM_BASE);

	/* Configure the EBI chip select to be in SDRAM mode. */
	ebi_sdram_set_mode(&cs_config, EBI_CS_SDMODE_NORMAL_gc);

	/* Setup the number of SDRAM rows and columns. */
	ebi_sdram_set_row_bits(&sdram_config, 12);
	ebi_sdram_set_col_bits(&sdram_config, 10);

	/* Further, setup the SDRAM timing. */
	ebi_sdram_set_cas_latency(&sdram_config, 3);
	ebi_sdram_set_mode_delay(&sdram_config, EBI_MRDLY_2CLK_gc);
	ebi_sdram_set_row_cycle_delay(&sdram_config, EBI_ROWCYCDLY_7CLK_gc);
	ebi_sdram_set_row_to_precharge_delay(&sdram_config, EBI_RPDLY_7CLK_gc);
	ebi_sdram_set_write_recovery_delay(&sdram_config, EBI_WRDLY_1CLK_gc);
	ebi_sdram_set_self_refresh_to_active_delay(&sdram_config,
			EBI_ESRDLY_7CLK_gc);
	ebi_sdram_set_row_to_col_delay(&sdram_config, EBI_ROWCOLDLY_7CLK_gc);
	ebi_sdram_set_refresh_period(&sdram_config, BOARD_EBI_SDRAM_REFRESH);
	ebi_sdram_set_initialization_delay(&sdram_config,
			BOARD_EBI_SDRAM_INITDLY);

	/* Write SDRAM configuration into the EBI registers. */
	ebi_sdram_write_config(&sdram_config);
	/* Write the chip select configuration into the EBI registers. */
	ebi_cs_write_config(EBI_SDRAM_CS, &cs_config);

	ebi_enable_cs(EBI_SDRAM_CS, &cs_config);
	
	UsartWriteString("BOOT: SDRAM configured...\r\n");
	
	do {
		// Wait for SDRAM to initialize.
	} while (!ebi_sdram_is_ready());
	
	UsartWriteString("BOOT: SDRAM ready...\r\n");
	
	status_code_t retval = ebi_test_data_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE);
	if (retval == STATUS_OK) {
		UsartWriteString("BOOT: SDRAM data bus test completed...\r\n");
	} else {
		UsartWriteString("BOOT: WARNING: SDRAM data bus test failed...\r\n");
	}
	
	retval = ebi_test_addr_bus((hugemem_ptr_t)BOARD_EBI_SDRAM_BASE,BOARD_EBI_SDRAM_SIZE);
	if (retval == STATUS_OK) {
		UsartWriteString("BOOT: SDRAM address bus test completed...\r\n");
	} else {
		UsartWriteString("BOOT: WARNING: SDRAM address bus test failed...\r\n");
	}

	//_delay_ms(1);
	
	//SD Card testing
	UsartWriteString("BOOT: SD Card testing...\r\n");
	//_delay_ms(1);
	
	FRESULT f_err_code;
	static FATFS FATFS_Obj;

	UsartWriteString("BOOT: SD Card: initializing disk...\r\n");
	disk_initialize(0);

	UsartWriteString("BOOT: SD Card: mounting disk...\r\n");
	f_err_code = f_mount(0, &FATFS_Obj);

	if (f_err_code == FR_OK) {
	
		FIL fil_obj;
		int test_number = 5;

		UsartWriteString("BOOT: SD Card: opening file...\r\n");
		f_open(&fil_obj, "asplfc.txt", FA_WRITE);
		UsartWriteString("BOOT: SD Card: writing file...\r\n");
		int out = f_printf(&fil_obj, "moo %d", test_number);
		UsartWriteString("BOOT: SD Card: closing file...\r\n");
		f_close(&fil_obj);

	} else {
		UsartWriteLine("BOOT: WARNING: No SD card found...");
	}

	//PORTQ.OUTCLR = PIN2_bm | PIN4_bm;

	UsartWriteString("\n\rASP LFC firmware -- v0.1\r\n");
	UsartWriteString("> ");
	while(1)
	{
		data=UsartReadChar(); // read char
		// check for carriage return and try to match/execute command
		if((data == '\r')||(index==sizeof(buffer)))
		{
			//PORTF.OUT ^= (1<<0);      // switch LED
			buffer[index]=0;          // null terminate
			index=0;                  // reset buffer index
			UsartWriteString("\n\r"); // echo newline
			ParseCommand(buffer);     // attempt to parse command
			  UsartWriteString("> ");
		}
		else if(data==8)              // backspace character
		{
			if(index>0)
				index--;                  // backup one character
			UsartWriteChar(data);
		}
		else
		{
			buffer[index++]=data;
			UsartWriteChar(data);
		};

		//	UsartWriteChar(data); // write char
		//	_delay_ms(100);
		//	PORTF.OUT ^= (1<<0); // toggle LED

	};
};