/* - weather.c - Olamide Adabonyan / Philip Lechowicz - o_mide@yahoo.com / phillech@aol.com */ #include "hc11.h" #include "vector.h" #include "weather-sci.h" #include "weather-progs.h" #define stacksize 150 #define switchtime 40000 #define readtime 50000 int Wind_speed, Wind_direction, Temperature; char count; int displayFree; //==========[.c file includes]========================= #include "weather-spin.c" //semaphore file #include "weather-threads.c" //thread structure file #include "weather-sci.c" //SCI file #include "weather-progs.c" //programs file //===================================================== /******************************************************* Name: ThreadSwitcher Purpose: - Switch threads in a round-robin manner Inputs: none Outputs: none ********************************************************/ #pragma interrupt_handler ThreadSwitcher() void ThreadSwitcher() { //OutString("switch..."); //debugger INTR_OFF(); //disable interrupts asm(" ldx _RunPt\n" " sts 2,x"); RunPt = RunPt->Next; asm(" ldx _RunPt\n" " lds 2,x"); TOC1 = TCNT + switchtime; //Reschedule Thread Swithcher(e.g. will run for 10ms if switchtime is 20000) TFLG1 = 0x80; INTR_ON(); //enable interrupts } /******************************************************* Name: AtoD Purpose: - To read in Voltages of weather signals and store them in global variables. Inputs: none Outputs: none ********************************************************/ #pragma interrupt_handler AtoD() void AtoD(void) { INTR_OFF(); //disable interrupts count = count + 1; if (count == 4) { Wind_speed = ADR1; Wind_direction = ADR2; Temperature = ADR3; count = 0; } TOC2 = TCNT + readtime; TFLG1 = 0x40; INTR_ON(); //enable interrupts } /******************************************************* Name: Main Purpose: - Initialize weather station - Hand control over to Thread Switcher ISR Inputs: none Outputs: none ********************************************************/ main() { unsigned char i, dummy; int temp; INTR_OFF(); //disable interrupts //init vars Wind_speed=0; Wind_direction=0; Temperature=0; count = 0; EscapeSequence(1); OutString(".:[ WEATHER STATION ]:.\n\r"); OutString("=======================\n\r\n\r"); //I/O config... OutString("Initializing I/O...\n\r"); SCCR1=0; SCCR2=0x0c; //enable SCI setbaud(BAUD9600); //set baud rate to 9600 PORTA = 0; DDRD = 0x3C; PACTL = 0x88; //OC1, OC2 config... OutString("Initializing OCn Interrupts...\n\r"); TOC1vector = &ThreadSwitcher; TOC2vector = &AtoD; TMSK1 = 0xC0; TFLG1 = 0xC0; TOC1 = TCNT + (65000); TOC2 = TCNT + 40000; //A/D Initialization... OutString("Initializing A/D...\n\r"); OPTION = (OPTION | 0xC0); //Power up A/D, set csel for (i=0; i<200; i++) //Delay 100 us dummy = i; ADCTL = 0x30; //set scan =1, mult=1, and cd=0, cc=0 //Thread & Semaphore config... OutString("Initializing Threads & Semaphore...\n\r"); displayFree = 1; RunPt=&sys[0]; //Specify first thread to run asm(" ldx _RunPt\n" " lds 2,x\n"); OutString("\n\r::[System Initialization Complete]::\n\r\n\r"); for(temp=0; temp<60000; temp++) //delay (so above initialization messages can be seen) temp++; for(temp=0; temp<60000; temp++) //delay (so above initialization messages can be seen) temp++; EscapeSequence(1); //clears screen //Display weather station readings OutString("WELCOME TO WEATHER STATION...\n\r\n\r"); OutString("The Current Wind Direction is: \n\r\n\r"); OutString("The Current Wind Speed is: \n\r\n\r"); OutString("The Current Temperature is: "); INTR_ON(); //enable interrupts asm("rti"); }