/* - weather-progs.c - Olamide Adabonyan / Philip Lechowicz - o_mide@yahoo.com / phillech@aol.com */ /******************************************************* Name: Escape Sequences Purpose: - Move cursor to a specific area on CRT display Inputs: Any character Outputs: none ********************************************************/ void EscapeSequence(char i) { //if character passed is '1', clear screen //if character passed is '2', move cursor to wind direction output area //if character passed is '3', move cursor to wind speed output area //if character passed is '4', move cursor to temperature output area //if any other character is passed, move cursor below weather display outputs if (i == 1) //clear screen { unsigned char clearScreen[4], x, dummy; clearScreen[0] = 0x1b; //esc[2J clearScreen[1] = 0x5b; clearScreen[2] = 0x32; clearScreen[3] = 0x4a; clearScreen[4] = 0x04; x = 0; while(x < 4) { dummy = clearScreen[x]; OutChar(dummy); x++; } } else if (i == 2) //wind direction { unsigned char wDirection[7], x, dummy; wDirection[0] = 0x1b; //esc[3;34H wDirection[1] = 0x5b; wDirection[2] = 0x33; wDirection[3] = 0x3b; wDirection[4] = 0x33; wDirection[5] = 0x34; wDirection[6] = 0x48; wDirection[7] = 0x04; x = 0; while(x < 7) { dummy = wDirection[x]; OutChar(dummy); x++; } } else if (i == 3) //wind speed { unsigned char wSpeed[7], x, dummy; wSpeed[0] = 0x1b; //esc[5;29H wSpeed[1] = 0x5b; wSpeed[2] = 0x35; wSpeed[3] = 0x3b; wSpeed[4] = 0x32; wSpeed[5] = 0x39; wSpeed[6] = 0x48; wSpeed[7] = 0x04; x = 0; while(x < 7) { dummy = wSpeed[x]; OutChar(dummy); x++; } } else if (i == 4) //temperature { unsigned char temp[7], x, dummy; temp[0] = 0x1b; //esc[7;29H temp[1] = 0x5b; temp[2] = 0x37; temp[3] = 0x3b; temp[4] = 0x32; temp[5] = 0x39; temp[6] = 0x48; temp[7] = 0x04; x = 0; while(x < 7) { dummy = temp[x]; OutChar(dummy); x++; } } else //test area on screen (below weather outputs) { unsigned char test[7], x, dummy; test[0] = 0x1b; //esc[15;2H test[1] = 0x5b; test[2] = 0x31; test[3] = 0x35; test[4] = 0x3b; test[5] = 0x32; test[6] = 0x48; test[7] = 0x04; x = 0; while(x < 7) { dummy = test[x]; OutChar(dummy); x++; } } } /******************************************************* Name: DispWeather Purpose: - Display weather readings on CRT Screen Inputs: none Outputs: none ********************************************************/ void DispWeather(void) { int wSpeed, wDirection, temperature, temp; while(1) { asm ("sei"); wSpeed = (Wind_speed * 70) / 255; temp = (Wind_direction * 90); wDirection = (temp / 255) * 4; //NB: Using (Wind_direction*360)/255 will not work // because it will turn out to be more than 65000 // which is the (max # int can hold) temperature = (Temperature * 100) / 255; Wait(&displayFree); EscapeSequence(2); OutUDec(wDirection); OutString(" Degrees "); EscapeSequence(3); OutUDec(wSpeed); OutString(" m/s "); EscapeSequence(4); OutUDec(temperature); OutString(" d Farenheit "); Signal(&displayFree); asm("cli"); } } /******************************************************* Name: OutWindDir Purpose: - Light Up LED corresponding to current wind direction Inputs: none Outputs: none ********************************************************/ void DispWindDir(void) { //myId=RunPt->Id; //debugger while(1) { if (Wind_speed <= 3) //if less than 1 m/s, output no wind { PORTA = 0x80; PORTD = (PORTD & 0xC3); } else if ((Wind_direction >= 0)&&(Wind_direction<16) | (Wind_direction >= 240)&&(Wind_direction<=255)) { PORTA = 0x40; PORTD = (PORTD & 0xC3); } else if ((Wind_direction >= 16)&&(Wind_direction<48)) { PORTA = 0x20; PORTD = (PORTD & 0xC3); } else if ((Wind_direction >= 48)&&(Wind_direction<80)) { PORTA = 0x10; PORTD = (PORTD & 0xC3); } else if ((Wind_direction >= 80)&&(Wind_direction<112)) { PORTA = 0x08; PORTD = (PORTD & 0xC3); } else if ((Wind_direction >= 112)&&(Wind_direction<144)) { PORTA = 0x00; PORTD = (PORTD | 0x20); PORTD = (PORTD & 0xE3); } else if ((Wind_direction >= 144)&&(Wind_direction<176)) { PORTA = 0x00; PORTD = (PORTD | 0x10); PORTD = (PORTD & 0xD3); } else if ((Wind_direction >= 176)&&(Wind_direction<208)) { PORTA = 0x00; PORTD = (PORTD | 0x08); PORTD = (PORTD & 0xCB); } else if ((Wind_direction >= 208)&&(Wind_direction<=240)) { PORTB = 0x00; PORTD = (PORTD | 0x04); PORTD = (PORTD & 0xC7); } } }