//***************Get_Cadence****************** //Displays the time you have been riding in hours, minutes, seconds, miliseconds //Input: the hour, minute, second and milisecond to display on the LCD //Output: none void Get_Cadence(unsigned short *buffer, unsigned long time) { char i; unsigned short rotations = 0; unsigned char SaveCCR; asm tpa asm staa SaveCCR asm sei // make atomic // The for loop has the 10 for(i=0; i<12; i++) { rotations = rotations + *buffer; buffer++; } //rotations now has the number of rotations that have been made if(time < 60) { rotations = ((600/time)*rotations)/10; } LCD_OutChar(NUM_TO_CHAR + (rotations/100)); LCD_OutChar(NUM_TO_CHAR + ((rotations/10)%10)); LCD_OutChar(NUM_TO_CHAR + (rotations%10)); asm ldaa SaveCCR asm tap // end critical section asm cli }
int main(void){ int useless =0; int a,b,c; DisableInterrupts(); PLL_Init(); // 50 MHz I think? LCD_Open(); ADC_InitSWTriggerSeq3(3); SysTick_Init(); SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOG; // activate port G useless = 1; useless =0; GPIO_PORTG_DIR_R |= 0x04; // make PG2 out (built-in LED) GPIO_PORTG_AFSEL_R &= ~0x04; // disable alt func on PG2 GPIO_PORTG_DEN_R |= 0x04; // enable digital I/O on PG2 PG2 = 0; // turn off LED UART_Init(); ADC_Init(); LCD_Clear(); EnableInterrupts(); while(1) { if((FIFO_Get() !=1) && getmail==0x2) { int i; int sendme; flag =0; //FIFO_Get(); LCD_GoTo(0); for(i = 0; i <5; i++) { FIFO_Get(); sendme = getmail; LCD_OutChar( sendme); } LCD_GoTo(20); LCD_OutChar(99); LCD_OutChar(109); FIFO_Get(); FIFO_Get(); // these two gets just take the blank space and the Stop 0x03 off the FIFO } } }
//***************Get_Countdown****************** //Displays the time you have been riding in hours, minutes, seconds, miliseconds //Input: the hour, minute, second and milisecond to display on the LCD //Output: none void Get_Countdown(short hour, short minute, short second, short msecond) { /* unsigned char SaveCCR; asm tpa asm staa SaveCCR asm sei // make atomic */ LCD_OutChar(NUM_TO_CHAR+(hour/10)); LCD_OutChar(NUM_TO_CHAR+(hour%10)); LCD_OutChar(0x3A); // ASCII Colon : LCD_OutChar(NUM_TO_CHAR+(minute/10)); LCD_OutChar(NUM_TO_CHAR+(minute%10)); LCD_OutChar(0x3A); // ASCII Colon : LCD_OutChar(NUM_TO_CHAR+(second/10)); LCD_OutChar(NUM_TO_CHAR+(second%10)); //LCD_OutChar(0x3A); // ASCII Colon : //LCD_OutChar(NUM_TO_CHAR+(msecond/10)); //LCD_OutChar(NUM_TO_CHAR+(msecond%10)); /* asm ldaa SaveCCR asm tap // end critical section asm cli */ }
//--------------------------LCD_OutUHex---------------------------- // Output a 32-bit number in unsigned hexadecimal format // Input: 32-bit number to be transferred // Output: none // Variable format 1 to 8 digits with no space before or after void LCD_OutUHex(uint32_t number){ // This function uses recursion to convert the number of // unspecified length as an ASCII string if(number >= 0x10){ LCD_OutUHex(number/0x10); LCD_OutUHex(number%0x10); } else{ if(number < 0xA){ LCD_OutChar(number+'0'); } else{ LCD_OutChar((number-0x0A)+'A'); } } }
//***************Get_Weight****************** //Displays the users weight in lbs //Input: the weight that the user is inputting //Output: none void Get_Weight(unsigned short weight) { unsigned char SaveCCR; asm tpa asm staa SaveCCR asm sei // make atomic LCD_GoTo(0,0); LCD_OutString(" lbs"); LCD_GoTo(0,0); LCD_OutChar(NUM_TO_CHAR + (weight/100)); LCD_OutChar(NUM_TO_CHAR + ((weight/10)%10)); LCD_OutChar(NUM_TO_CHAR + (weight%10)); asm ldaa SaveCCR asm tap // end critical section asm cli }
//-----------------------LCD_OutUDec----------------------- // Output a 32-bit number in unsigned decimal format // Input: 32-bit number to be transferred // Output: none // Variable format 1-10 digits with no space before or after void LCD_OutUDec(uint32_t n){ // This function uses recursion to convert decimal number // of unspecified length as an ASCII string if(n >= 10){ LCD_OutUDec(n/10); n = n%10; } LCD_OutChar(n+'0'); /* n is between 0 and 9 */ }
//***************Get_Distance****************** //Calculates the distance traveled based on wheel rotations and displays info on LCD //Input: Number of wheel rotations //Output: none void Get_Distance(unsigned long rotations, unsigned char units) { unsigned long distance; /* unsigned char SaveCCR; asm tpa asm staa SaveCCR asm sei // make atomic */ if(units == KM) distance = (rotations*WHEEL_CIRCUM_KM); //distance currently in milimeters else distance = (rotations*WHEEL_CIRCUM_MI); distance = distance/1000; Fixed_ulDecOut2(distance); LCD_OutChar(0x6B); LCD_OutChar(0x6D); /* asm ldaa SaveCCR asm tap // end critical section asm cli */ }
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; } }
//------------LCD_OutString------------ // Output String (NULL termination) // Input: pointer to a NULL-terminated string to be transferred // Output: none void LCD_OutString(char *pt){ while(*pt){ LCD_OutChar(*pt); pt++; } }
//---------------------Get_Stopwatch--------------------- // outputs the current time to the LCD display // Input: none // Output: none void Get_Stopwatch(short hour, short minute, short second, short msecond) { // unsigned char SaveCCR; // asm tpa // asm staa SaveCCR // asm sei // make atomic LCD_OutChar(NUM_TO_CHAR+(hour/10)); LCD_OutChar(NUM_TO_CHAR+(hour%10)); LCD_OutChar(0x3A); // ASCII Colon : LCD_OutChar(NUM_TO_CHAR+(minute/10)); LCD_OutChar(NUM_TO_CHAR+(minute%10)); LCD_OutChar(0x3A); // ASCII Colon : LCD_OutChar(NUM_TO_CHAR+(second/10)); LCD_OutChar(NUM_TO_CHAR+(second%10)); LCD_OutChar(0x3A); // ASCII Colon : LCD_OutChar(NUM_TO_CHAR+(msecond/10)); LCD_OutChar(NUM_TO_CHAR+(msecond%10)); // asm ldaa SaveCCR // asm tap // end critical section // asm cli }
//***************Get_AvgSpeed****************** //Displays the average speed over the whole trip //Input: the total time spent on the trip (in seconds), and the total rotations done over the whole trip //Output: none void Get_AvgSpeed(unsigned long time, unsigned long rotations, unsigned char units) { unsigned long distTraveled; unsigned char SaveCCR; asm tpa asm staa SaveCCR asm sei // make atomic if(units == KM) distTraveled = rotations*WHEEL_CIRCUM_KM; //distanceTraveled currently in mm else distTraveled = rotations*WHEEL_CIRCUM_MI; //distanceTraveled currently in miles/1E6 distTraveled = distTraveled/1000; //distanceTravleed now in meters distTraveled = ((distTraveled*3600)/(time)); //distanceTravled now in meters/hr if(distTraveled<9999) { LCD_OutChar(NUM_TO_CHAR+(distTraveled/1000)); LCD_OutString("."); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10)); } else if(distTraveled<99999) { LCD_OutChar(NUM_TO_CHAR+(distTraveled/10000)); LCD_OutChar(NUM_TO_CHAR+((distTraveled)%10)); LCD_OutString("."); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10)); } else if(distTraveled<999999) { LCD_OutChar(NUM_TO_CHAR+(distTraveled/100000)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10)); LCD_OutString("."); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10)); } else if(distTraveled<9999999) { LCD_OutChar(NUM_TO_CHAR+(distTraveled/1000000)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10)); LCD_OutString("."); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10)); } else if(distTraveled<99999999) { LCD_OutChar(NUM_TO_CHAR+(distTraveled/10000000)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10000)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/1000)%10)); LCD_OutString("."); LCD_OutChar(NUM_TO_CHAR+((distTraveled/100)%10)); LCD_OutChar(NUM_TO_CHAR+((distTraveled/10)%10)); } LCD_OutString(" km/hr"); asm ldaa SaveCCR asm tap // end critical section asm cli }