interrupt 8 void OC0handler(void) { TFLG1 |= 0x01; TC0 = TC0 + 37525; // Set next interrupt (5Hz) 37525 PTP ^= 0x80; // Heartbeat ADCMail = ADC_In(2); //ADCStatus = 0x80; sci1_OutChar(ADC_In(2)); Counter++; }
void DAS(void) { int index; static int i = 0; unsigned short input; static unsigned long LastTime; // time at previous ADC sample unsigned long thisTime; // time at current ADC sample long jitter; // time between measured and expected if(NumSamples < RUNLENGTH){ // finite time run // GPIO_B0 ^= 0x01; input = ADC_In(1); thisTime = OS_Time(); // current time, 20 ns DASoutput = Filter(input); FilterWork++; // calculation finished if(FilterWork>1){ // ignore timing of first interrupt jitter = ((OS_TimeDifference(thisTime,LastTime)-PERIOD)*CLOCK_PERIOD)/1000; // in usec if(jitter > MaxJitter){ MaxJitter = jitter; } if(jitter < MinJitter){ MinJitter = jitter; } // jitter should be 0 index = jitter+JITTERSIZE/2; // us units if(index<0)index = 0; if(index>=JitterSize)index = JITTERSIZE-1; JitterHistogram[index]++; } LastTime = thisTime; } }
SYSTICK HANDLER void SysTick_Handler() { GPIO_PORTG_DATA_R ^= 0x4; sample = ADC_In(); GPIO_PORTG_DATA_R ^= 0x4; sample = Convert(sample); thousands = sample%1000; hundreds = (sample%100)-(thousands*10); tens = (sample%10) - ( (hundreds*10) + (thousands*100) ); ones = ( sample - (tens*10 + hundreds*100 + thousands*1000 ) ); UART_OutChar(0x2); // STx UART_OutChar((thousands)+0x30); // first number ASCII UART_OutChar(0x2E); // dot ASCII UART_OutChar( (hundreds) + 0x30); // second number ASCII UART_OutChar( tens +0x30); // third UART_OutChar(ones +0x30); // last number ASCII UART_OutChar(0x0D); // CR, whatever that is UART_OutChar(0x3); // ETx samplecount++; GPIO_PORTG_DATA_R ^= 0x4; }
void Timer0B_Handler(void){ TIMER0_ICR_R = TIMER_ICR_TATOCINT; // acknowledge timer0A timeout GPIO_PORTG_DATA_R |= 0x40; // turn on LED ADCvalue = ADC_In(); ADCStatus = 1; GPIO_PORTG_DATA_R &= ~0x40; // turn off LED }
int main1(void){ // single step this program and look at Data TExaS_Init(); // Bus clock is 80 MHz ADC_Init(); // turn on ADC, set channel to 1 while(1){ Data = ADC_In(); // sample 12-bit channel 1 } }
void DAS(void){ unsigned long input; unsigned static long LastTime; // time at previous ADC sample unsigned long thisTime; // time at current ADC sample long jitter; // time between measured and expected, in us if(NumSamples < RUNLENGTH){ // finite time run PE0 ^= 0x01; input = ADC_In(); // channel set when calling ADC_Init PE0 ^= 0x01; thisTime = OS_Time(); // current time, 12.5 ns DASoutput = Filter(input); FilterWork++; // calculation finished if(FilterWork>1){ // ignore timing of first interrupt unsigned long diff = OS_TimeDifference(LastTime,thisTime); if(diff>PERIOD){ jitter = (diff-PERIOD+4)/8; // in 0.1 usec }else{ jitter = (PERIOD-diff+4)/8; // in 0.1 usec } if(jitter > MaxJitter){ MaxJitter = jitter; // in usec } // jitter should be 0 if(jitter >= JitterSize){ jitter = JITTERSIZE-1; } JitterHistogram[jitter]++; } LastTime = thisTime; PE0 ^= 0x01; } }
void DAS(void){ unsigned short input; if(NumSamples < RUNLENGTH){ // finite time run input = ADC_In(1); DASoutput = Filter(input); FilterWork++; // calculation finished } }
void SysTick_Handler(){ PF2 ^= 0x04; // Heartbeat PF2 ^= 0x04; // Heartbeat ADCMail = ADC_In(); // sample 12-bit channel 1 ADCStatus = 1; PF2 ^= 0x04; // Heartbeat NVIC_ST_RELOAD_R = 2000000-1; // number of counts to wait NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears }
int main(void) { // unsigned long x, a, b, c, d; // char cool[5]; //int i = 0; SysTick_Init(); ADC_Init(1); PORTG_Init(1); PORTD_Init(); PORTA_Init(); PORTF_Init(); PORTB_Init(); PORTE_Init(1); PORTH_Init(); LCD_Init(); Touch_Init(); Camera_Init(); /* while(1) { x = ADC_In(); a = x/1000; x -= a * 1000; b = x/100; x -= b * 100; c = x/10; x -= c * 10; d = x; cool[0] = (char)(a + 48); cool[1] = (char)(b + 48); cool[2] = (char)(c + 48); cool[3] = (char)(d + 48); cool[4] = 0; TFT_Fill(purple); TFT_Text(&cool[0], 50, 50, 16, black, purple); } */ while(1) { GPIO_PORTG_DATA_R ^= 0x04; if(ADC_In() != 1023) { TFT_Fill(yellow); } else { TFT_Fill(purple); } } //TFT_H_Line(50,150,50,black); // return 1; }
void SysTick_Handler(void){ // sample ADC ADCMail = ADC_In(); // set flag arrowReady = 1; }
void DAS(void){ unsigned short input; if(NumSamples < RUNLENGTH){ // finite time run input = ADC_In(1); DASoutput = Filter(input); FilterWork++; // calculation finished } MaxJitter = GetPeriodicTask(0)->maxJitter; MinJitter = GetPeriodicTask(0)->minJitter; }
void SysTick_Handler(void){ GPIO_PORTF_DATA_R ^= 0x04; // Toggle Heartbeat GPIO_PORTF_DATA_R ^= 0x04; // Toggle Heartbeat Data = ADC_In(); ADCMail = Data; ADCStatus = 1; GPIO_PORTF_DATA_R ^= 0x04; // Toggle Heartbeat }
void SysTick_Handler(void){ PF2 ^= 0x04; PF2 ^= 0x04; ADCTemp=ADC_In(); if(fabs((ADCTemp-ADCMail))>20){ ADCMail = ADCTemp; ADCStatus= 1; } PF2 ^=0x04; return; }
int ADC_Collect(unsigned int channelNum, unsigned int period,unsigned short buffer[], unsigned int numberOfSamples){ int sampleCounter = 0; ADC_Open(channelNum); TIMER0_CTL_R = 0x00000000; // disable timer0A during setup TIMER0_TAILR_R = period-1; // start value for trigger TIMER0_CTL_R |= 0x00000001; // enable timer0A 16-b, periodic, no interrupts //ask if this is correct setup. what about timer value? roll over while(sampleCounter < numberOfSamples) { buffer[sampleCounter++] = ADC_In(); } return 0; }
void SysTick_Handler(void){ ADCData = ADC_In(); if((GPIO_PORTE_DATA_R)&&0x8){ newMissile++;} //New Missile if PE3 for(i=0;i<20;i++){ if ( (enemy[i].s==1)&&(enemy[i].wait > 1) ){ //if wait not done and enemy exists enemy[i].wait--; //decrement wait time } } if(newMissile>3){newMissile=0;} Semaphore = 1; //semaphore set signifying updated data }
int main2(void){ TExaS_Init(); // Bus clock is 80 MHz ADC_Init(); // turn on ADC, set channel to 1 PortF_Init(); ST7735_InitR(INITR_REDTAB); while(1){ // use scope to measure execution time for ADC_In and LCD_OutDec PF2 = 0x04; // Profile ADC Data = ADC_In(); // sample 12-bit channel 1 PF2 = 0x00; // end of ADC Profile ST7735_SetCursor(0,0); PF1 = 0x02; // Profile LCD LCD_OutDec(Data); ST7735_OutString(" "); // these spaces are used to coverup characters from last output PF1 = 0; // end of LCD Profile } }
void SysTick_Handler(){ PF2 ^= 0x04; // 1. Toggle heartbeat uint32_t data = ADC_In(); // 2. Sample ADC (12-bit channel 1) PF2 ^= 0x04; // 3. Toggle heartbeat data=Convert(data); // 4. Convert to distance and create the 8-byte message uint8_t message[]= {0x02,0,0x2E,0,0,0,0x0D,0x03}; message[1] = (data/1000)%10 + 0x30; message[3] = (data/100)%10 + 0x30; message[4] = (data/10)%10 + 0x30; message[5] = data%10 + 0x30; for(int i=0; i<8; i++){ // 5. Send the 8-byte message to the other computer (calls UART1_OutChar 8 times) UART1_OutChar(message[i]); } TxCounter++; // 6. increment TxCounter (for debugging) PF2 ^= 0x04; // 7. Toggle heartbeat NVIC_ST_RELOAD_R = 2000000-1; // 8. Return from interrupt NVIC_ST_CURRENT_R = 0; // Reset SysTick timer for .25ms }
int main3(void){ TExaS_Init(); // Bus clock is 80 MHz PortF_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); while(1){ PF2 ^= 0x04; // Heartbeat Data = ADC_In(); // sample 12-bit channel 1 PF3 = 0x08; // Profile Convert Position = Convert(Data); PF3 = 0; // end of Convert Profile PF1 = 0x02; // Profile LCD ST7735_SetCursor(0,0); LCD_OutDec(Data); ST7735_OutString(" "); ST7735_SetCursor(6,0); LCD_OutFix(Position); PF1 = 0; // end of LCD Profile } }
void SysTick_Handler(void){ // every 25 ms uint8_t ADC_Temp[8]; uint8_t i; //Toggle Heartbeat Twice PF3 ^= 0xFF; PF3 ^= 0xFF; //Sample the ADC ADCMail = ADC_In(); //Set Flag ADCStatus = fresh; PF3 ^= 0xFF; //Send Measurement to UART_OutChar ADCMail = Convert(ADCMail); ADC_Temp[0] = 0x02; ADC_Temp[1] = (ADCMail/1000); ADCMail -= 1000*ADC_Temp[1]; ADC_Temp[1] += 0x30; ADC_Temp[2] = 0x2E; ADC_Temp[3] = ADCMail/100; ADCMail -= 100*ADC_Temp[3]; ADC_Temp[3] += 0x30; ADC_Temp[4] = ADCMail/10; ADCMail -= 10*ADC_Temp[4]; ADC_Temp[4] += 0x30; ADC_Temp[5] = ADCMail; ADC_Temp[5] += 0x30; ADC_Temp[6] = 0x0D; ADC_Temp[7] = 0x03; for(i=0; i<8; i++){ UART_OutChar(ADC_Temp[i]); } //Increment Counter TxCounter++; //Toggle LED PF3 ^= 0xFF; }
//////////////////////////////////////////////////////////////////////////***START OF PROGRAM***////////////////////////////////////////////////////////////////////////////////////////////// int main(void){ //Initialization PLL_Init(); // Set the clocking to run at 80MHz from the PLL. LCD_Init(); // Initialize LCD LCD_Goto(10,0); LCD_SetTextColor(255,255,0); // yellow= red+green, no blue printf("Lab 10"); LCD_DrawLine(10,16,310,16,BURNTORANGE); ADC_Initialize(); Timer2_Init(7256); Timer2A_Stop(); SysTick_Init(); ///////////////////////////////////////////////////////////////////////////Set Up Waves/////////////////////////////////////////////////////////////////////////////////////////////// while(1){ //set up for the wave 1 (11 means wave needs to be setup, 10 means wave is set up) if (wave==11) { wavesize=5; enemycount=0; LCD_SetCursor(140,120); LCD_SetTextColor(255,0,0); LCD_PrintString("WAVE ONE"); LCD_SetTextColor(0,0,0); LCD_PrintString("WAVE ONE"); enemy[0].x=50; enemy[1].x=90; enemy[2].x=130; enemy[3].x=170; enemy[4].x=210; for (k=0;k<5;k++) { enemy[k].y=40; enemy[k].s=1; enemy[k].e=0; enemy[k].c=0; enemy[k].b=0; wave=10; } } //set up for wave 2 (22 means wave needs to be setup, 20 means wave is set up) //e: so we don't print eraser more than once //s: so we know the state of the sprite //c; so we don't count the death of a sprite more than once if (wave==21) { wavesize=15; enemycount=0; LCD_SetCursor(140,120); LCD_SetTextColor(255,0,0); LCD_PrintString("WAVE TWO"); LCD_SetTextColor(0,0,0); LCD_PrintString("WAVE TWO"); enemy[0].x=50; enemy[1].x=90; enemy[2].x=130; enemy[3].x=170; enemy[4].x=210; for (k=0;k<5;k++) { enemy[k].y=40; enemy[k].s=1; enemy[k].e=0; enemy[k].c=0; enemy[k].b=0; } for (k=5;k<10;k++) { enemy[k].s=4; //set newer coming enemies to 4, so they don't get counted as dead when they don't arrive yet (count happens after printing) enemy[k].e=0; enemy[k].y=40; enemy[k].x=50; enemy[k].c=0; enemy[k].b=0; } for (k=10;k<15;k++) { enemy[k].s=4; enemy[k].s=4; //set newer coming enemies to 4, so they don't get counted as dead when they don't arrive yet (count happens after printing) enemy[k].e=0; enemy[k].y=64; enemy[k].x=296; enemy[k].c=0; enemy[k].b=0; } wave=20; } //set up for wave 3 //set up for wave 3 if(wave==31) { wavesize=1; enemycount=0; LCD_SetCursor(140,30); LCD_SetTextColor(255,0,0); LCD_PrintString("Time For Ziping"); for(k=0;k<10;k++) {enemy[k].x=0;enemy[k].y=0;enemy[k].s=0;;enemy[k].e=0;} enemy[0].s=1; enemy[0].x=100; enemy[0].y=40; enemy[0].b=0; enemy[0].e=0; wave=30; } ////////////////////////////////////////////////////////////////////////////Update and Print User Ship///////////////////////////////////////////////////////////////////////////////////////// if(Semaphore){ //wait for SysTick Semaphore = 0; //"acknowledge" SysTick ADCData = ADC_In(); Position=(ADCData*.4053751277)+157.0113976; //position 0-2000 xShip = ((Position)*.14)+20; //x pixel coordinate of center of ship (.14 = 280/2000) LCD_DrawBMP(UshipErase,xShipTrail,200); //erase previous image LCD_DrawBMP(userShip,xShip,200); xShipTrail = xShip; ////////////////////////////////////////////////////////////////////////////////////Update Enemies///////////////////////////////////////////////////////////////////////////////////////////// //enemy ship update coordinates for wave 1 (s=1 means alive, s=0 means just dead, s=2 means the moment of death) if (wave==10) { for (k=0;k<5;k++){ if (enemy[k].s == 1) { enemy[k].y = enemy[k].y +1; trainWreckL = xShip-enemy[k].x; //enemy within left boundary of ship trainWreckR = enemy[k].x - xShip; //enemy within right boundary of ship if( (enemy[k].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[k].s = 2; DEATH(); userDeath++; } if (enemy[k].y>=210) {enemy[k].s=0;} } } } //enemy ship update coordinates for wave 2 //enemy ship update coordinates for wave 2 else if (wave==20) { for (k=0;k<5;k++) { if(enemy[k].s==1) { //updates only if object is alive (s==1) if (countx<=92 && wave2==0) { enemy[k].x = enemy[k].x +1; } countx++; if (countx >92 && wave2==0) {wave2=1; countx=0;} if (wave2==1) { for (j=0;j<5;j++) { enemy[j].y=enemy[j].y+1; } wave2=2; countx=0; county++; } if (countx <=92 && wave2==2) { enemy[k].x= enemy[k].x-1; } countx++; if (countx >= 92 && wave2==2 ) {wave2=3; countx=0;} if (wave2==3) { for (j=0;j<5;j++) { enemy[j].y=enemy[j].y+1; } wave2=0; county++; } trainWreckL = xShip-enemy[j].x; //enemy within left boundary of ship trainWreckR = enemy[j].x - xShip; //enemy within right boundary of ship if( (enemy[j].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[j].s = 2; DEATH(); userDeath++; } if (enemy[k].y>=210) {enemy[k].s=0;} } } //fleet 2 if (county==24 || enemycount==10) {enemy[5].s=1; wave3=1;} //activate the bigger ships once there is room vertically, e.i. check if y coordinate has been met if (countx2==24) {enemy[6].s=1;} if (countx2==48 ) {enemy[7].s=1;} if (countx2==72) {enemy[8].s=1;} if (countx2==96) {enemy[9].s=1;} //if (enemy[5].x>=196) {wave2big=1;} //once the enemies get to the edge of the screen, set a flag (wave big) to one if (countx2>=146) {wave2big=1;} for (k=5;k<10;k++) { if(wave3==1 && k==5) {countx2++;} if(enemy[k].s==1 && wave2big==0) { //update coordinates for new ships for wave 2 only if they become active (due to above code) and if max x coordinate hasn't been set enemy[k].x=enemy[k].x+1; } if(enemy[k].y>=210) {enemy[k].s=0;} //enemy dead if off the screen vertically, we don't care if horizontally if(enemy[k].s==1 && wave2big==1) { if(k==5 || k==6) {enemy[k].x=enemy[k].x-1; enemy[k].y=enemy[k].y+1;} if(k==8 || k==9) {enemy[k].x=enemy[k].x+1; enemy[k].y=enemy[k].y+1;} if(k==7 && enemy[k].y<=100) {enemy[k].y=enemy[k].y+1;} } } //fleet 3 if (county==48 || enemycount==10) {enemy[10].s=1; wave4=1;} //activate the bigger ships once there is room vertically, e.i. check if y coordinate has been met if (countx3==24) {enemy[11].s=1;} if (countx3==48 ) {enemy[12].s=1;} if (countx3==72) {enemy[13].s=1;} if (countx3==96) {enemy[14].s=1;} if (countx3>=146) {wave3big=1;} for (k=10;k<15;k++) { if(wave4==1 && k==10) {countx3++;} if(enemy[k].s==1 && wave3big==0) { //update coordinates for new ships for wave 2 only if they become active (due to above code) and if max x coordinate hasn't been set enemy[k].x=enemy[k].x-1; } if(enemy[k].y>=210) {enemy[k].s=0;} //enemy dead if off the screen vertically, we don't care if horizontally if(enemy[k].s==1 && wave3big==1) { if(k==10) {if(enemy[k].y<120 && enemy[k].x==50) {enemy[k].y=enemy[k].y+1;} if(enemy[k].y==120 && enemy[k].x<130) {enemy[k].x=enemy[k].x+1;} if(enemy[k].y>64 && enemy[k].x==130) {enemy[k].y=enemy[k].y-1;} if(enemy[k].y==64 && enemy[k].x>50) {enemy[k].x=enemy[k].x-1;}} if(k==14) {if(enemy[k].y<120 && enemy[k].x==246) {enemy[k].y=enemy[k].y+1;} if(enemy[k].y==120 && enemy[k].x>166) {enemy[k].x=enemy[k].x-1;} if(enemy[k].y>64 && enemy[k].x==166) {enemy[k].y=enemy[k].y-1;} if(enemy[k].y==64 && enemy[k].x<246) {enemy[k].x=enemy[k].x+1;}} if(k==11 || k==13 || k==12) {enemy[k].y=enemy[k].y+1;} } } } ///////////////////////////////////////////////////////////////////////Update User missiles//////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(missile[i].s){ missile[i].y = missile[i].y - 2; //if missile is active, move up the screen if(missile[i].y < 18 ){ missile[i].s = 0; //if the missile has moved off the screen, deactivate it LCD_DrawBMP(UmissileErase,missile[i].x,missile[i].y); //cover up with black } //////////////////////////////////////////////////////////////////Test for Enemy-Missile Collisions (small aliens)/////////////////////////////////////////////////////////////////////////////////////// for(k=0;k<wavesize;k++){ //(missile:11x15, enemy: 24x24) crashTestY = ((enemy[k].y + 24) - missile[i].y); //difference in y-coordinates crashTestXR = (missile[i].x - enemy[k].x); //distance of missile from right border of alien crashTestXL = (enemy[k].x - missile[i].x); //distance of missile from left border of alien if ( ( (crashTestY <5) && (crashTestY > 0) ) && ( ( (crashTestXR < 24) && (crashTestXR > 0 ) ) || ( (crashTestXL < 11)&&(crashTestXL > 0) ) ) ){ enemy[k].s = 2; } } } } /////////////////////////////////////////////////////////////////////Test for Enemy-User Collisions/////////////////////////////////////////////////////////////////////////////////////////////////// /* for(k=0;k<5;k++){ trainWreckL = xShip-enemy[k].x; //enemy within left boundary of ship trainWreckR = enemy[k].x - xShip; //enemy within right boundary of ship if( (enemy[k].y >= 176) && (((trainWreckL <24)&&(trainWreckL >0) )||((trainWreckR < 30)&&(trainWreckR > 0))) ){ enemy[k].s = 2; DEATH(); userDeath++; } */ //////////////////////////////////////////////////////////////////////////Activate New Missile///////////////////////////////////////////////////////////////////////////////////////////// if(newMissile==3){ while(missile[notActiveSlot].s == 1){ //find a non-active missile in the array if(notActiveSlot == 99){notActiveSlot = 0;} //wrap around if at end of array notActiveSlot++; //check next slot } missile[notActiveSlot].x = xShip + 10; //missile(11x15) aligned to center of ship missile[notActiveSlot].y = 185; //missile firing out 200 - 15 missile[notActiveSlot].s = 1; //activate Timer2A_Start(); //arm sound newMissile=0; //reset button count tester++; } ///////////////////////////////////////////////////////Update Enemy Missiles///////////////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(emissile[i].s==1){ emissile[i].y = emissile[i].y + 2; if(emissile[i].y > 210){ emissile[i].s = 0; LCD_DrawBMP(UmissileErase,emissile[i].x,emissile[i].y); } } } ///////////////////////////////////////////////////////////////////////Test for User Missile Collisions//////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if((emissile[i].s ==1)&&(emissile[i].y >= 185)&& ((((emissile[i].x - xShip)<30)&&((emissile[i].x - xShip)>0))|| (((xShip- emissile[i].x)<11)&&((xShip-emissile[i].x)>0)))){ emissile[i].s = 0; DEATH(); userDeath++; } } ////////////////////////////////////////////////////////////////////////New Enemy Missiles//////////////////////////////////////////////////////////////////////////////////////////////////// //activate new enemy missiles for(k=0;k<wavesize;k++){ if((enemy[k].s)&&(enemy[k].wait == 1)){ //alive and finished (.wait == 1 means countdown done) while(emissile[notActiveSlotE].s == 1){ //find a non-active enemy missile slot in array if(notActiveSlotE == 99){notActiveSlotE = 0;} //wrap around if at end of array else notActiveSlotE++; //check next slot } emissile[notActiveSlotE].x = enemy[k].x + (enemy[k].w / 2); //center horizontal positioning of missile on enemy emissile[notActiveSlotE].y = enemy[k].y + enemy[k].h; //get correct vertical positioning for missile emissile[notActiveSlotE].s = 1; //activate missile enemy[k].wait = 0; //signifying missile fired, reaady for new wait time } } //loading enemies that just fired with new wait times for(k=0;k<wavesize;k++){ if((enemy[k].s)&&(enemy[k].wait == 0)){ //alive and not currently waiting to fire (.wait == 0 means need new time) j = (Random()%60); //get random number from 0-30 if(j < 20){j=20;} //minimum # 20 (3 shots per second max firing) enemy[k].wait = j; } } /////////////////////////////////////////////////////////////////////enemy missile printing////////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(emissile[i].s == 1){ LCD_DrawBMP(enemyMissile,emissile[i].x,emissile[i].y);}} /*else if ((emissile[i].s == 0)&&(emissile[i].b==0)){ LCD_DrawBMP(UmissileErase,emissile[i].x,emissile[i].y);} emissile[i].b = 1; }*/ //////////////////////////////////////////////////////////////////////////////missile printing/////////////////////////////////////////////////////////////////////////////////////////// for(i=0;i<100;i++){ if(missile[i].s){ LCD_DrawBMP(userMissile,missile[i].x,missile[i].y); //print if missile is active } } ///////////////////////////////////////////////////////////////////////////enemy ship printing/////////////////////////////////////////////////////////////////////////////////////// /////////////ship printing for wave 1 if(wave==10) { for (k=0;k<5;k++) { if (enemy[k].s ==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 &&enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1, enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e ==0) { LCD_DrawBMP(ExplosionBlack, enemy[k].x,(enemy[k].y)); enemy[k].e=1;} } for (k=0;k<5;k++) { if(enemy[k].s==0 && enemy[k].c==0) {enemycount++; enemy[k].c=1;} //count enemies if s=0 and c=0 } if (enemycount==5) {wave=21;} //new wave is all five enemies are "dead" } /////////////Ship printing for wave 2 if(wave==20) { for (k=0;k<5;k++) { if (enemy[k].s ==1) { LCD_DrawBMP(AlienEnemySmall, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x,(enemy[k].y)); enemy[k].e=1;} } for(k=5;k<10;k++) { if(enemy[k].s==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x, enemy[k].y); enemy[k].e=1;}} for (k=0;k<10;k++) { if(enemy[k].s==0 && enemy[k].c==0) {enemycount++; enemy[k].c=1;} //count enemy if s=0 and c=0 } if (enemycount==20) {wave=31;} //new wave if all ten enemies are "dead" for(k=10;k<15;k++) { if(enemy[k].s==1) { LCD_DrawBMP(AlienEnemyBig, enemy[k].x,enemy[k].y); } if (enemy[k].s ==2 && enemy[k].b ==0) { LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); LCD_DrawBMP(Explosion1, enemy[k].x,(enemy[k].y)); LCD_DrawBMP (Explosion1,enemy[k].x, enemy[k].y); enemy[k].s=0; enemy[k].b=1; } if (enemy[k].s ==0 && enemy[k].e==0) { //once explosion eraser is printed, set the s to zero and e to one LCD_DrawBMP(ExplosionBlack, enemy[k].x, enemy[k].y); enemy[k].e=1;}} } } //close semaphore } //close while loop } //close main
void Interpreter(void) // just a prototype, link to your interpreter { uint32_t stringSize; uint32_t adcVoltage; uint8_t deviceChosen; uint8_t taskAddedBefore = 0; uint8_t commandChosen = -1; char message[MESSAGELENGTH] = ""; OutCRLF(); UART_OutString("Input Command: "); while(1){ OutCRLF(); //UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time"); OutCRLF(); commandChosen = UART_InChar(); switch(commandChosen) { case '0': OutCRLF(); UART_OutString("ADC Voltage = "); //ADC_Open(4); adcVoltage = (ADC_In() *3300) / 4095; //convert to mV UART_OutUDec(adcVoltage); OutCRLF(); break; case '1': OutCRLF(); UART_OutString("Enter LCD device 0 or 1: "); deviceChosen = UART_InUDec(); OutCRLF(); UART_OutString("Enter message: "); UART_InString(message, MESSAGELENGTH); OutCRLF(); stringSize = strlen(message); if(stringSize > 20) { OutCRLF(); UART_OutString("String too long..."); OutCRLF(); } LCD_test(deviceChosen, message); //prints to lcd OutCRLF(); break; case '2': if(!taskAddedBefore){ OS_AddPeriodicThread(dummy, 5, 1); taskAddedBefore = 1; } OutCRLF(); UART_OutUDec(OS_ReadPeriodicTime()); OutCRLF(); break; case '3': UART_OutString("NumSamples: "); UART_OutUDec(NumSamples); OutCRLF(); break; case '4': UART_OutString("Jitter: "); UART_OutUDec(MaxJitter); OutCRLF(); break; case '5': UART_OutString("DataLost: "); UART_OutUDec(DataLost); OutCRLF(); break; case '6': UART_OutString("FilterWork: "); UART_OutUDec(FilterWork); OutCRLF(); break; case '7': UART_OutString("NumCreated: "); UART_OutUDec(NumCreated); OutCRLF(); break; case '8': for(int i = 0; i<64; i++) { UART_OutUDec(x[i]); OutCRLF(); } break; default: UART_OutString("Incorrect command!"); break; } //adcSample = ADC_In(); //ST7735_SetCursor(0,0); //ST7735_OutUDec(adcSample); } }
// *************** Sensor_ReadADC *************** int Sensor_ReadADC( PORT_T *port ) { return ADC_In ( (ADC_Channel)port->adc0_chan ); }
void Temperature(void){ unsigned short ADCReceived, ADCReceived2, Res1IntShort,Res2IntShort; float Res1Float,Res2Float,Temp1Float,Temp2Float,ADCReceived1Float,ADCReceived2Float,Rref=2500; char LCDOutput[14]; unsigned short LCDTemp1[3],LCDTemp2[3]; unsigned char dummychar; ADCReceived=(ADC_In(0x87));//ADCReceived=(ADC_In(0x07)>>6); // Read Analog value from AN7 ADCReceived2=(ADC_In(0x86));//ADCReceived2=(ADC_In(0x06)>>6);// Read Analog value from AN6 ADCReceived2Float=(float) ADCReceived2; ADCReceived1Float=(float) ADCReceived; Res2Float= (ADCReceived2Float/1023/7.47*Rref); Res1Float= (ADCReceived1Float/1023/7.47*Rref); Res2IntShort=(unsigned short) Res2Float; Res1IntShort=(unsigned short) Res1Float; Temp2Float= (Res2Float-100)/0.385; Temp1Float= (Res1Float-100)/0.385; Temp2IntShort=(unsigned char) Temp2Float; Temp1IntShort=(unsigned char) Temp1Float; Temp1Global=Temp1IntShort; Temp2Global=Temp2IntShort; //SCI_OutString("Raw 1 :");SCI_OutUDec(ADCReceived);SCI_OutString(" Res1 :");SCI_OutUDec(Res1IntShort);SCI_OutString(" Temp1:");SCI_OutUDec(Temp1IntShort);SCI_OutString(" || Raw 2:");SCI_OutUDec(ADCReceived2);SCI_OutString(" Res : ");SCI_OutUDec(Res2IntShort);SCI_OutString(" Temp : ");SCI_OutUDec(Temp2IntShort);OutCRLF(); LCDTemp2[0]= (Temp2IntShort/100);Temp2IntShort=Temp2IntShort-LCDTemp2[0]*100; LCDTemp2[1]= (Temp2IntShort/10);Temp2IntShort=Temp2IntShort-LCDTemp2[1]*10; LCDTemp2[2]= Temp2IntShort; LCDTemp1[0]= (Temp1IntShort/100);Temp1IntShort=Temp1IntShort-LCDTemp1[0]*100; LCDTemp1[1]= (Temp1IntShort/10);Temp1IntShort=Temp1IntShort-LCDTemp1[1]*10; LCDTemp1[2]= Temp1IntShort; // Update the temperature values on the LCD LCDCommand(0x80+0x07);//Goto first temperature address LCD_OutChar((LCDTemp1[0]+'0')); LCD_OutChar((LCDTemp1[1]+'0')); LCD_OutChar((LCDTemp1[2]+'0')); LCDCommand(0x80+0x47); //Goto second temperature address LCD_OutChar((LCDTemp2[0]+'0')); LCD_OutChar((LCDTemp2[1]+'0')); LCD_OutChar((LCDTemp2[2]+'0')); //Goto Idle Location LCDCommand(0x80+0x4F); //Change the character at this location so that we know the Micro is working if(globalidle==1){ LCD_OutChar(0xb0); globalidle=2; } else{ LCD_OutChar(0x7c); globalidle=1; } }