// This program holds all of the functions used in the total program #include #include "EESD.h" /* * This is a starting point of a library * of functions that are useful. THese * fuctions drive the LCD dispaly. * * It is recommended that you create a * similar set of fucntions that work with * HyperTerminal * */ /* * Setup LCD display * */ void LCD_init(void) { trisd = trisd & 0x0f; //Top 4 pins configured for output trise = trise & 0xf8; //Bottom 3 pins configured for output adcon1 |= 0x0f; // port E digital mode delay_ms(40); LCD_icmd( 0x30 ) ; /* 8 Bit mode */ delay_ms(5); // DH - min delay here of 4.1 ms LCD_icmd( 0x30 ) ; /* 8 Bit mode */ LCD_icmd( 0x30 ) ; /* 8 Bit mode */ LCD_icmd( 0x20 ) ; /* 4-BIT Mode */ LCD_cmd( 0x28 ); /* Function Set: 4-bit,2-line,5X7 */ LCD_cmd( 0x0C ); /* Display on, Cursor off */ LCD_cmd( 0x06 ); /* Entry mode: INC addr, NO SHIFT display */ LCD_cmd( 0x01 ); /* Clear Display */ delay_ms( 20 ); } /******************************************************* * LCD_cmd - Write ASCII character to LCD peripheral * * configured as a 4 bit interface * *******************************************************/ void LCD_char(char data) { char dsave; dsave = latd; LCD_DATA = (data & 0xF0) | (LCD_DATA & 0x0F); /* Write HI nibble word to LCD */ write_data; LCD_DATA = ((data << 4) & 0xF0) | (LCD_DATA & 0x0F); /* Write LO nibble word to LCD */ write_data; delay_ms(1); latd = dsave; } /***************************************************** * LCD_icmd - Write control word to LCD peripheral * *****************************************************/ void LCD_icmd(char data) { char dsave; dsave = portd; LCD_DATA = data | (LCD_DATA & 0x0F) ; write_cmd; delay_ms(1); portd = dsave; return; } /*************************************************** * LCD_cmd - Write control word to LCD peripheral * * configured as a 4 bit interface * **************************************************/ void LCD_cmd(char data) { char dsave; dsave = portd; LCD_DATA = (data & 0xF0) | (LCD_DATA & 0x0F); /* Write HI nibble word to LCD */ write_cmd; LCD_DATA = ((data << 4) & 0xF0) | (LCD_DATA & 0x0F); /* Write LO nibble word to LCD */ write_cmd; if (data < 0x03) delay_ms(20); else delay_ms(1); portd = dsave; return; } /* set the cursor position */ void LCD_setpos(char line, char pos) { LCD_cmd(0x80 + line * 0x40 + pos); return; } /********************** * routine to clear display screen * */ void LCD_clear(void) { LCD_cmd( 0x01 ); /* Clear Display */ delay_ms(20); return; } /******************************** * Display char in HEX - format * ********************************/ void LCD_hex(char data) { char n; n = ((data >> 4) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = (data & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); return; } /******************************** * Display unsigned short in HEX - format * ********************************/ void LCD_hex(unsigned short data) { char n; n = ((data >> 12) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = ((data >> 8) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = ((data >> 4) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = (data & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); return; } /******************************** * Display short in HEX - format * ********************************/ void LCD_hex(short data) { char n; n = ((data >> 12) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = ((data >> 8) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = ((data >> 4) & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); n = (data & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); return; } /******************************** * Display low nibble in HEX - format * ********************************/ void LCD_nib(char data) { char n; n = (data & 0x0F) + 0x30; if (n > 0x39) n = n+7; LCD_char(n); return; } /******************************** * Display byte in binary - format * ********************************/ void LCD_bin(char data) { char n; char temp; temp =0x80; for( n=1; n<=8; ++n) { if(temp & data) LCD_char(0x31); else LCD_char(0x30); temp = temp >> 1; } return; } /******************************** * Display unsigned short in binary - format * ********************************/ void LCD_bin(unsigned short data) { char n; unsigned short temp; temp =0x8000; for( n=1; n<=16; ++n) { if(temp & data) LCD_char(0x31); else LCD_char(0x30); temp = temp >> 1; } } void LCD_dec(short dat) { unsigned short val; // ascii results unsigned short temp; unsigned short div; unsigned short data; char i; char digit; data = dat; // make it unsigned div = 10000; for(i=0; i <= 4; ++i) // get all 5 digits { val = data/div; // get most signif. digit LCD_char(val + '0'); // print digit data -= val * div; // what we’ve printed div=div/10; // adjust divisor } return; } void LCD_dec(unsigned short dat) { unsigned short val; // ascii results unsigned short temp; unsigned short div; unsigned short data; char i; char digit; data = dat; // make it unsigned div = 10000; for(i=0; i <= 4; ++i) // get all 5 digits { val = data/div; // get most signif. digit LCD_char(val + '0'); // print digit data -= val * div; // what we’ve printed div=div/10; // adjust divisor } return; } /********************************** * Display byte as decimal number * **********************************/ void LCD_dec(char data) { LCD_char(((data /100) & 255) + 0x30); data = data % 100; LCD_char( ((data / 10) & 255) + 0x30 ); LCD_char( ((data % 10) & 255) + 0x30 ); return; } /* * display char as a signed int * */ void LCD_int(char data) { char val; // ascii results char temp; char div; char i; bool dozero; dozero = false; div = 100; if(data == 0) // always print 0 { LCD_char('0'); return; } /* * adjust for sign * */ if(data & 10000000b) { LCD_char('-'); data = ~data + 1; } for(i=0; i <= 2; ++i) // get all 3 digits { val = data/div; // get most signif. digit if(val != 0 || dozero) { LCD_char(val + '0'); // print digit dozero = true; } temp = val * div; // subtract off data = data - temp; // what we’ve printed div=div/10; // adjust divisor } } /* * display unsigned short as a signed int * */ void LCD_int(short dat) { short val; // ascii results short temp; short div; char i; unsigned short data; bool dozero; dozero = false; data = dat; if(dat == 0) // always print 0 { LCD_char('0'); return; } div = 10000; /* * adjust for sign * */ if(dat < 0) { LCD_char('-'); data = ~data + 1; } for(i=0; i <= 4; ++i) // get all 3 digits { val = data/div; // get most signif. digit if(val != 0 || dozero) { LCD_char(val + '0'); // print digit dozero = true; } data -= val*div; // subtract off what we’ve printed div=div/10; // adjust divisor } } void LCD_rxint(short dat) { short val; // ascii results short temp; short div; char i; unsigned short data; bool dozero; dozero = false; data = dat; if(dat == 0) // always print 0 { LCD_char('0'); return; } div = 10000; /* * adjust for sign * */ if(dat < 0) { LCD_char('-'); data = ~data + 1; } for(i=0; i <= 4; ++i) // get all 3 digits { val = data/div; // get most signif. digit if(val != 0 || dozero) { LCD_char(val + '0'); // print digit dozero = true; } data -= val*div; // subtract off what we’ve printed div=div/10; // adjust divisor } } void LCD_printf( const char* text ) { char i = 0; while( text[i] != 0 ) LCD_char( text[i++] ); return; } void Serial_init(void) { trisc.6=1; trisc.7=1; trisc.0=0; latc.0=0; delay_ms(50); latc.0=1; trise.2=0; porte.2=1; txsta = 0x24; rcsta = 0x90; baudcon.3=0; baudcon.0=0; spbrgh=0x00; spbrg=51; } void putc(char dat) { while(!txsta.1) {} txreg = dat; return; } void putc(int dat) { while(!txsta.1) {} txreg = dat; return; } char getc(void) { while(!pir1.5) {} char dat; dat = rcreg; LCD_char(dat); //putc(dat); return dat; } void Send_Zigbee(const char* text) { char i = 0; while(text[i] != 0) { putc(text[i]); LCD_char(text[i]); i++; } return; } void Send_Zigbee(int data) { putc(data); LCD_int(data); return; } void Zigbee_init(void) { delay_s(1); Send_Zigbee("+++"); delay_s(1); delay_ms(300); Send_Zigbee("ATID1313\r"); Send_Zigbee("ATCH13\r"); //Send_Zigbee("ATAC\r"); //delay_s(1); //Send_Zigbee("ATID\r"); //Send_Zigbee("ATCH\r"); Send_Zigbee("ATCN\r"); } void Zigbee_read(void) { delay_s(1); Send_Zigbee("+++"); delay_s(1); delay_ms(300); Send_Zigbee("ATID\r"); Send_Zigbee("ATCH\r"); Send_Zigbee("ATCN\r"); } void Zigbee_restore(void) { delay_s(1); Send_Zigbee("+++"); delay_s(1); delay_ms(300); Send_Zigbee("ATRE\r"); Send_Zigbee("ATWR\r"); delay_s(2); Send_Zigbee("ATID\r"); Send_Zigbee("ATCN\r"); } void Print_Hyperterm (unsigned short dat) { unsigned short val; // ascii results unsigned short temp; unsigned short div; unsigned short data; char i; char digit; data = dat; // make it unsigned div = 10000; for(i=0; i <= 4; ++i) // get all 5 digits { val = data/div; // get most signif. digit putc(val + '0'); // print digit data -= val * div; // what we’ve printed div=div/10; // adjust divisor } return; } short binary_decimal (void) { short a = 1; short b = 0; char data; short i = 0; short decimal; while (a) { data=getc(); if(data!=13 & i < 6) { decimal = data - 48; } b = b * 10; b = b + decimal; if(data==13 || i ==5) { Print_Hyperterm(b); a = 0; } i++; } return b; } //volatile bit sspflag@PIR1.3; //SPI sending 16 bits void LED (unsigned short val) { volatile bit sspflag@PIR1.3 = 0; latd.3 = 0; //Assigns CS at pin C2 to 0. delay_us(2); sspbuf = val>>8; //Shifts 8 bits of value into sspbuf while(!sspflag){} //Waits for the flag. sspflag = 0; //Resets Flag sspbuf = val; //Puts the remaining bits into sspbuf while(!sspflag){} //Waits for the flag. sspflag = 0; //Resets Flag latd.3 = 1; //Brings CS up to 1. delay_us(2); return; } void SEVEN (unsigned short val) { volatile bit sspflag@PIR1.3 = 0; latd.4 = 0; //Assigns CS at pin C1 to 0. delay_us(2); sspbuf = val>>8; //Shifts 8 bits of value into sspbuf while(!sspflag){} //Waits for the flag. sspflag = 0; //Resets Flag sspbuf = val; //Puts the remaining bits into sspbuf while(!sspflag){} //Waits for the flag. sspflag = 0; //Resets Flag latd.4 = 1; //Brings CS up to 1. delay_us(2); return; } //Maxim initialization void LED_maxim_init(void) { LED(0x0C01); //Moves to normal operation. LED(0x0B05); //Display digit 0 1 2 3 4 5 only. LED(0x0900); //No Decode LED(0x0A0F); //Light Intensity LED(0x0F00); //Display-test register normal operation. return; } void SEVEN_maxim_init(void) { SEVEN(0x0C01); //Moves to normal operation. SEVEN(0x0B03); //Display digit 0 1 2 3 only. SEVEN(0x0900); //No Decode SEVEN(0x0A0F); //Light Intensity SEVEN(0x0F00); //Display-test register normal operation. return; } void B_code(void) { LED(0x09FF); //Code B decode for digits 7-0. return; } void No_decode(void) { LED(0x0900); //No decode for digits 7-0 return; } // Hole 1 //Turns on SEG A (No decode) void display_sega1(void) { LED(0x0140); return; } //Turns on SEG B (No decode) void display_segb1(void) { LED(0x0120); return; } //Turns on SEG C (No decode) void display_segc1(void) { LED(0x0110); return; } //Turns on SEG D (No decode) void display_segd1(void) { LED(0x0108); return; } //Turns on SEG E (No decode) void display_sege1(void) { LED(0x0104); return; } //Turns on SEG F (No decode) void display_segf1(void) { LED(0x0102); return; } //Turns on SEG G (No decode) void display_segg1(void) { LED(0x0101); return; } //Turns on SEG DP (No decode) void display_segdp1(void) { LED(0x0180); return; } void display_sega1_off(void) { LED(0x013F); return; } void display_segbg1_off(void) { LED(0x015E); return; } void display_segcf1_off(void) { LED(0x016D); return; } void display_segde1_off(void) { LED(0x0173); return; } //Turns on all LEDs (No decode) void all_on1(void) { LED(0x01FF); return; } //Turns off all LEDs except ones in hole void all_off1(void) { LED(0x0100); return; } //Blink Code: top to bottom of Maxim chip void blink(void) { //No_decode(); LCD_init(); LCD_printf("Blink Both"); delay_s(1); LCD_clear(); display_segd1(); display_segd2(); delay_ms(100); display_segdp1(); display_segdp2(); delay_ms(100); display_sege1(); display_sege2(); delay_ms(100); display_segc1(); display_segc2(); delay_ms(100); display_segg1(); display_segg2(); delay_ms(100); display_segb1(); display_segb2(); delay_ms(100); display_segf1(); display_segf2(); delay_ms(100); display_sega1(); display_sega2(); delay_ms(100); display_segd1(); display_segd2(); delay_ms(100); display_segdp1(); display_segdp2(); delay_ms(100); display_sege1(); display_sege2(); delay_ms(100); display_segc1(); display_segc2(); delay_ms(100); display_segg1(); display_segg2(); delay_ms(100); display_segb1(); display_segb2(); delay_ms(100); display_segf1(); display_segf2(); delay_ms(100); display_sega1(); display_sega2(); delay_ms(100); all_off1(); all_off2(); return; } void bounce_blink(void) { display_sega1_off(); display_sega2_off(); display_sega3_off(); display_sega4_off(); display_sega5_off(); display_sega6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segde1_off(); display_segde2_off(); display_segde3_off(); display_segde4_off(); display_segde5_off(); display_segde6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); display_sega1_off(); display_sega2_off(); display_sega3_off(); display_sega4_off(); display_sega5_off(); display_sega6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segde1_off(); display_segde2_off(); display_segde3_off(); display_segde4_off(); display_segde5_off(); display_segde6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); display_sega1_off(); display_sega2_off(); display_sega3_off(); display_sega4_off(); display_sega5_off(); display_sega6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segde1_off(); display_segde2_off(); display_segde3_off(); display_segde4_off(); display_segde5_off(); display_segde6_off(); delay_ms(100); display_segcf1_off(); display_segcf2_off(); display_segcf3_off(); display_segcf4_off(); display_segcf5_off(); display_segcf6_off(); delay_ms(100); display_segbg1_off(); display_segbg2_off(); display_segbg3_off(); display_segbg4_off(); display_segbg5_off(); display_segbg6_off(); delay_ms(100); all_off1(); all_off2(); all_off3(); all_off4(); all_off5(); all_off6(); return; } void blink1(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd1(); delay_ms(100); display_segdp1(); delay_ms(100); display_sege1(); delay_ms(100); display_segc1(); delay_ms(100); display_segg1(); delay_ms(100); display_segb1(); delay_ms(100); display_segf1(); delay_ms(100); display_sega1(); delay_ms(100); display_segd1(); delay_ms(100); display_segdp1(); delay_ms(100); display_sege1(); delay_ms(100); display_segc1(); delay_ms(100); display_segg1(); delay_ms(100); display_segb1(); delay_ms(100); display_segf1(); delay_ms(100); display_sega1(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off1(); return; } // Hole 2 LED functions //Turns on SEG A (No decode) void display_sega2(void) { LED(0x0240); return; } //Turns on SEG B (No decode) void display_segb2(void) { LED(0x0220); return; } //Turns on SEG C (No decode) void display_segc2(void) { LED(0x0210); return; } //Turns on SEG D (No decode) void display_segd2(void) { LED(0x0208); return; } //Turns on SEG E (No decode) void display_sege2(void) { LED(0x0204); return; } //Turns on SEG F (No decode) void display_segf2(void) { LED(0x0202); return; } //Turns on SEG G (No decode) void display_segg2(void) { LED(0x0201); return; } //Turns on SEG DP (No decode) void display_segdp2(void) { LED(0x0280); return; } void display_sega2_off(void) { LED(0x023F); return; } void display_segbg2_off(void) { LED(0x025E); return; } void display_segcf2_off(void) { LED(0x026D); return; } void display_segde2_off(void) { LED(0x0273); return; } //Turns on all LEDs (No decode) void all_on2(void) { LED(0x02FF); return; } //Turns off all LEDs except ones in hole void all_off2(void) { LED(0x0200); return; } void blink2(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd2(); delay_ms(100); display_segdp2(); delay_ms(100); display_sege2(); delay_ms(100); display_segc2(); delay_ms(100); display_segg2(); delay_ms(100); display_segb2(); delay_ms(100); display_segf2(); delay_ms(100); display_sega2(); delay_ms(100); display_segd2(); delay_ms(100); display_segdp2(); delay_ms(100); display_sege2(); delay_ms(100); display_segc2(); delay_ms(100); display_segg2(); delay_ms(100); display_segb2(); delay_ms(100); display_segf2(); delay_ms(100); display_sega2(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off2(); return; } // Hole 3 LED functions //Turns on SEG A (No decode) void display_sega3(void) { LED(0x0340); return; } //Turns on SEG B (No decode) void display_segb3(void) { LED(0x0320); return; } //Turns on SEG C (No decode) void display_segc3(void) { LED(0x0310); return; } //Turns on SEG D (No decode) void display_segd3(void) { LED(0x0308); return; } //Turns on SEG E (No decode) void display_sege3(void) { LED(0x0304); return; } //Turns on SEG F (No decode) void display_segf3(void) { LED(0x0302); return; } //Turns on SEG G (No decode) void display_segg3(void) { LED(0x0301); return; } //Turns on SEG DP (No decode) void display_segdp3(void) { LED(0x0380); return; } void display_sega3_off(void) { LED(0x033F); return; } void display_segbg3_off(void) { LED(0x035E); return; } void display_segcf3_off(void) { LED(0x036D); return; } void display_segde3_off(void) { LED(0x0373); return; } //Turns on all LEDs (No decode) void all_on3(void) { LED(0x03FF); return; } //Turns off all LEDs except ones in hole void all_off3(void) { LED(0x0300); return; } void blink3(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd3(); delay_ms(100); display_segdp3(); delay_ms(100); display_sege3(); delay_ms(100); display_segc3(); delay_ms(100); display_segg3(); delay_ms(100); display_segb3(); delay_ms(100); display_segf3(); delay_ms(100); display_sega3(); delay_ms(100); display_segd3(); delay_ms(100); display_segdp3(); delay_ms(100); display_sege3(); delay_ms(100); display_segc3(); delay_ms(100); display_segg3(); delay_ms(100); display_segb3(); delay_ms(100); display_segf3(); delay_ms(100); display_sega3(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off3(); return; } // Hole 4 LED functions //Turns on SEG A (No decode) void display_sega4(void) { LED(0x0440); return; } //Turns on SEG B (No decode) void display_segb4(void) { LED(0x0420); return; } //Turns on SEG C (No decode) void display_segc4(void) { LED(0x0410); return; } //Turns on SEG D (No decode) void display_segd4(void) { LED(0x0408); return; } //Turns on SEG E (No decode) void display_sege4(void) { LED(0x0404); return; } //Turns on SEG F (No decode) void display_segf4(void) { LED(0x0402); return; } //Turns on SEG G (No decode) void display_segg4(void) { LED(0x0401); return; } //Turns on SEG DP (No decode) void display_segdp4(void) { LED(0x0480); return; } void display_sega4_off(void) { LED(0x043F); return; } void display_segbg4_off(void) { LED(0x045E); return; } void display_segcf4_off(void) { LED(0x046D); return; } void display_segde4_off(void) { LED(0x0473); return; } //Turns on all LEDs (No decode) void all_on4(void) { LED(0x04FF); return; } //Turns off all LEDs except ones in hole void all_off4(void) { LED(0x0400); return; } void blink4(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd4(); delay_ms(100); display_segdp4(); delay_ms(100); display_sege4(); delay_ms(100); display_segc4(); delay_ms(100); display_segg4(); delay_ms(100); display_segb4(); delay_ms(100); display_segf4(); delay_ms(100); display_sega4(); delay_ms(100); display_segd4(); delay_ms(100); display_segdp4(); delay_ms(100); display_sege4(); delay_ms(100); display_segc4(); delay_ms(100); display_segg4(); delay_ms(100); display_segb4(); delay_ms(100); display_segf4(); delay_ms(100); display_sega4(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off4(); return; } // Hole 5 LED functions //Turns on SEG A (No decode) void display_sega5(void) { LED(0x0540); return; } //Turns on SEG B (No decode) void display_segb5(void) { LED(0x0520); return; } //Turns on SEG C (No decode) void display_segc5(void) { LED(0x0510); return; } //Turns on SEG D (No decode) void display_segd5(void) { LED(0x0508); return; } //Turns on SEG E (No decode) void display_sege5(void) { LED(0x0504); return; } //Turns on SEG F (No decode) void display_segf5(void) { LED(0x0502); return; } //Turns on SEG G (No decode) void display_segg5(void) { LED(0x0501); return; } //Turns on SEG DP (No decode) void display_segdp5(void) { LED(0x0580); return; } void display_sega5_off(void) { LED(0x053F); return; } void display_segbg5_off(void) { LED(0x055E); return; } void display_segcf5_off(void) { LED(0x056D); return; } void display_segde5_off(void) { LED(0x0573); return; } //Turns on all LEDs (No decode) void all_on5(void) { LED(0x05FF); return; } //Turns off all LEDs except ones in hole void all_off5(void) { LED(0x0500); return; } void blink5(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd5(); delay_ms(100); display_segdp5(); delay_ms(100); display_sege5(); delay_ms(100); display_segc5(); delay_ms(100); display_segg5(); delay_ms(100); display_segb5(); delay_ms(100); display_segf5(); delay_ms(100); display_sega5(); delay_ms(100); display_segd5(); delay_ms(100); display_segdp5(); delay_ms(100); display_sege5(); delay_ms(100); display_segc5(); delay_ms(100); display_segg5(); delay_ms(100); display_segb5(); delay_ms(100); display_segf5(); delay_ms(100); display_sega5(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off5(); return; } // Hole 6 LED functions //Turns on SEG A (No decode) void display_sega6(void) { LED(0x0640); return; } //Turns on SEG B (No decode) void display_segb6(void) { LED(0x0620); return; } //Turns on SEG C (No decode) void display_segc6(void) { LED(0x0610); return; } //Turns on SEG D (No decode) void display_segd6(void) { LED(0x0608); return; } //Turns on SEG E (No decode) void display_sege6(void) { LED(0x0604); return; } //Turns on SEG F (No decode) void display_segf6(void) { LED(0x0602); return; } //Turns on SEG G (No decode) void display_segg6(void) { LED(0x0601); return; } //Turns on SEG DP (No decode) void display_segdp6(void) { LED(0x0680); return; } void display_sega6_off(void) { LED(0x063F); return; } void display_segbg6_off(void) { LED(0x065E); return; } void display_segcf6_off(void) { LED(0x066D); return; } void display_segde6_off(void) { LED(0x0673); return; } //Turns on all LEDs (No decode) void all_on6(void) { LED(0x06FF); return; } //Turns off all LEDs except ones in hole void all_off6(void) { LED(0x0600); return; } void blink6(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd6(); delay_ms(100); display_segdp6(); delay_ms(100); display_sege6(); delay_ms(100); display_segc6(); delay_ms(100); display_segg6(); delay_ms(100); display_segb6(); delay_ms(100); display_segf6(); delay_ms(100); display_sega6(); delay_ms(100); display_segd6(); delay_ms(100); display_segdp6(); delay_ms(100); display_sege6(); delay_ms(100); display_segc6(); delay_ms(100); display_segg6(); delay_ms(100); display_segb6(); delay_ms(100); display_segf6(); delay_ms(100); display_sega6(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_off6(); return; } // 7 Segment Score Display Code For Team 1 //Displays 0 void display1_0(void) { SEVEN(0x017E); return; } //Displays 1 void display1_1(void) { SEVEN(0x0130); return; } //Display 2 void display1_2(void) { SEVEN(0x016D); return; } //Displays 3 void display1_3(void) { SEVEN(0x0179); return; } //Display 4 void display1_4(void) { SEVEN(0x0133); return; } //Displays 5 void display1_5(void) { SEVEN(0x015B); return; } //Display 6 void display1_6(void) { SEVEN(0x015F); return; } // 7 Segment Score Display Code For Team 2 //Displays 0 void display2_0(void) { SEVEN(0x027E); return; } //Displays 1 void display2_1(void) { SEVEN(0x0230); return; } //Display 2 void display2_2(void) { SEVEN(0x026D); return; } //Displays 3 void display2_3(void) { LED(0x0279); return; } //Display 4 void display2_4(void) { SEVEN(0x0233); return; } //Displays 5 void display2_5(void) { SEVEN(0x025B); return; } //Display 6 void display2_6(void) { SEVEN(0x025F); return; } //Displays 0 void display2_0x(void) { SEVEN(0x027E); return; } //Displays 1 void display2_1x(void) { SEVEN(0x0230); return; } //Display 2 void display2_2x(void) { SEVEN(0x026D); return; } //Displays 3 void display2_3x(void) { LED(0x0279); return; } //Display 4 void display2_4x(void) { SEVEN(0x0233); return; } //Displays 5 void display2_5x(void) { SEVEN(0x025B); return; } //Display 6 void display2_6x(void) { SEVEN(0x025F); return; } // Score display for Team 1 void score1(int val) { int score0 = 0; int score1 = 1; int score2 = 2; int score3 = 3; int score4 = 4; int score5 = 5; int score6 = 6; int gameover = 7; if(val == score0) { display1_0(); return; } if (val == score1) { display1_1(); return; } if (val == score2) { display1_2(); return; } if (val == score3) { display1_3(); return; } if (val == score4) { display1_4(); return; } if (val == score5) { display1_5(); return; } if (val == score6) { display1_6(); return; } if (val == gameover) { LCD_init(); LCD_printf("Game is over"); delay_s(1); LCD_clear(); gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; sflag3 = 0; sflag4 = 0; sflag5 = 0; sflag6 = 0; delay_ms(100); //blink(); // Blink lights } } //Score display for Team 2 void score2(int val) { int score0 = 0; int score1 = 1; int score2 = 2; int score3 = 3; int score4 = 4; int score5 = 5; int score6 = 6; int gameover = 7; if(val == score0) { display2_0(); return; } if (val == score1) { display2_1(); return; } if (val == score2) { display2_2(); return; } if (val == score3) { display2_3(); return; } if (val == score4) { display2_4(); return; } if (val == score5) { display2_5(); return; } if (val == score6) { display2_6(); return; } if (val == gameover) { LCD_init(); LCD_printf("Game is over"); delay_s(1); LCD_clear(); gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; sflag3 = 0; sflag4 = 0; sflag5 = 0; sflag6 = 0; delay_ms(100); //blink(); // Blink lights } } // 7 Segment Games Won Display Code For Team 1 //Displays 0 void games_display1_0(void) { SEVEN(0x037E); return; } //Displays 1 void games_display1_1(void) { SEVEN(0x0330); return; } //Display 2 void games_display1_2(void) { SEVEN(0x036D); return; } //Displays 3 void games_display1_3(void) { SEVEN(0x0379); return; } //Display 4 void games_display1_4(void) { SEVEN(0x0333); return; } //Displays 5 void games_display1_5(void) { SEVEN(0x035B); return; } //Display 6 void games_display1_6(void) { SEVEN(0x035F); return; } //Display 7 void games_display1_7(void) { SEVEN(0x0370); return; } //Display 8 void games_display1_8(void) { SEVEN(0x037F); return; } //Display 9 void games_display1_9(void) { SEVEN(0x037B); return; } // 7 Segment Games Won Display Code For Team 2 //Displays 0 void games_display2_0(void) { SEVEN(0x047E); return; } //Displays 1 void games_display2_1(void) { SEVEN(0x0430); return; } //Display 2 void games_display2_2(void) { SEVEN(0x046D); return; } //Displays 3 void games_display2_3(void) { SEVEN(0x0479); return; } //Display 4 void games_display2_4(void) { SEVEN(0x0433); return; } //Displays 5 void games_display2_5(void) { SEVEN(0x045B); return; } //Display 6 void games_display2_6(void) { SEVEN(0x045F); return; } //Display 7 void games_display2_7(void) { SEVEN(0x0470); return; } //Display 8 void games_display2_8(void) { SEVEN(0x047F); return; } //Display 9 void games_display2_9(void) { SEVEN(0x047B); return; } void gameswon1(int val) { int games0 = 0; int games1 = 1; int games2 = 2; int games3 = 3; int games4 = 4; int games5 = 5; int games6 = 6; int games7 = 7; int games8 = 8; int games9 = 9; //int gameover = 7; if(val == games0) { games_display1_0(); return; } if (val == games1) { games_display1_1(); return; } if (val == games2) { games_display1_2(); return; } if (val == games3) { games_display1_3(); return; } if (val == games4) { games_display1_4(); return; } if (val == games5) { games_display1_5(); return; } if (val == games6) { games_display1_6(); return; } if (val == games7) { games_display1_7(); return; } if (val == games7) { games_display1_8(); return; } if (val == games9) { games_display1_9(); return; } /*if (val == gameover) { LCD_init(); LCD_printf("Game is over"); delay_s(1); LCD_clear(); gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; delay_ms(100); blink(); // Blink lights }*/ } void gameswon2(int val) { int games0 = 0; int games1 = 1; int games2 = 2; int games3 = 3; int games4 = 4; int games5 = 5; int games6 = 6; int games7 = 7; int games8 = 8; int games9 = 9; //int gameover = 7; if(val == games0) { games_display2_0(); return; } if (val == games1) { games_display2_1(); return; } if (val == games2) { games_display2_2(); return; } if (val == games3) { games_display2_3(); return; } if (val == games4) { games_display2_4(); return; } if (val == games5) { games_display2_5(); return; } if (val == games6) { games_display2_6(); return; } if (val == games7) { games_display2_7(); return; } if (val == games7) { games_display2_8(); return; } if (val == games9) { games_display2_9(); return; } /*if (val == gameover) { LCD_init(); LCD_printf("Game is over"); delay_s(1); LCD_clear(); gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; delay_ms(100); blink(); // Blink lights }*/ } void score2rx(int val) { int score0 = 0; int score1 = 1; int score2 = 2; int score3 = 3; int score4 = 4; int score5 = 5; int score6 = 6; int gameover = 7; int game_reset = 8; if(val == score0) { display2_0(); return; } if (val == score1) { display2_1(); return; } if (val == score2) { display2_2(); return; } if (val == score3) { display2_3(); return; } if (val == score4) { display2_4(); return; } if (val == score5) { display2_5(); return; } if (val == score6) { display2_6(); return; } if (val == gameover) { //LCD_init(); //LCD_printf("Game is over"); delay_s(1); //LCD_clear(); gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; sflag3 = 0; sflag4 = 0; sflag5 = 0; sflag6 = 0; delay_ms(100); //blink(); // Blink lights } if(val == game_reset) { //LCD_init(); //LCD_printf("Reset Everything"); delay_s(1); //LCD_clear(); gameisnotover = 0; // Game is over reset = 0; } } void zigbee_blink(void) { //No_decode(); LCD_init(); LCD_printf("Check"); delay_s(1); LCD_clear(); display_segd1(); delay_ms(100); display_segdp1(); delay_ms(100); display_sege1(); delay_ms(100); display_segc1(); delay_ms(100); display_segg1(); delay_ms(100); display_segb1(); delay_ms(100); display_segf1(); delay_ms(100); display_sega1(); delay_ms(100); display_segd1(); delay_ms(100); display_segdp1(); delay_ms(100); display_sege1(); delay_ms(100); display_segc1(); delay_ms(100); display_segg1(); delay_ms(100); display_segb1(); delay_ms(100); display_segf1(); delay_ms(100); display_sega1(); delay_ms(100); LCD_printf("Check"); delay_s(1); LCD_clear(); all_on1(); return; } void interrupt_init(void) { intcon = 11110000b; pie1.5 = 1; } void games_display2x_0x(void) { SEVEN(0x047E); return; } //Displays 1 void games_display2_1x(void) { SEVEN(0x0430); return; } //Display 2 void games_display2_2x(void) { SEVEN(0x046D); return; } //Displays 3 void games_display2_3x(void) { SEVEN(0x0479); return; } //Display 4 void games_display2_4x(void) { SEVEN(0x0433); return; } //Displays 5 void games_display2_5x(void) { SEVEN(0x045B); return; } //Display 6 void games_display2_6x(void) { SEVEN(0x045F); return; } //Display 7 void games_display2_7x(void) { SEVEN(0x0470); return; } //Display 8 void games_display2_8x(void) { SEVEN(0x047F); return; } //Display 9 void games_display2_9x(void) { SEVEN(0x047B); return; } void interrupt(void) { if(rxflag) { short dat; dat = rcreg; //LCD_rxint(dat); if (dat <=8) { score2rx(dat); //zigbee_blink(); } /*if (dat==10) { games_display2_0x(); } if (dat==11) { games_display2_1x(); } if (dat==12) { games_display2_2x(); } if (dat==13) { games_display2_3x(); } if (dat==14) { games_display2_4x(); } if (dat==15) { games_display2_5x(); } if (dat==16) { games_display2_6x(); } if (dat==17) { games_display2_7x(); } if (dat==18) { games_display2_8x(); } if (dat==19) { games_display2_9x(); }*/ rxflag = 0; return; } //if(intcon.1==1) //{ // gameisnotover = 0; // reset = 0; //Send_Zigbee(8); //LCD_printf("Reset Pressed"); //delay_s(1); //LCD_clear(); // intcon.1 = 0; // return; //} //return; }