#include "C:\MentorProjects\Kees_Display\Kees_Display.h" #include "C:\MentorProjects\Kees_Display\PCF8574_Driver.c" #include "C:\MentorProjects\Kees_Display\RTC_TIMER1.c" #include "C:\MentorProjects\Kees_Display\ccs_rf12_receiver.c" #include // 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,H ,N ,A ,L ,I BYTE CONST LED_MAP[16] = {0x6f ,0x03 ,0x5d ,0x57 ,0x33 ,0x76 ,0x7E ,0x43 ,0x7F ,0x77 ,0x3B ,0x6B ,0x7B ,0x2C ,0x28}; /********************************************************************************************** * Segment nummering * address Functie * 0 thuis tiental score * 1 thuis eenheden score * 2 klok tiental minuten * 3 klok eenheden minuten * 4 klok tiental seconden * 5 klok eenheden seconden * 6 uit tiental * 7 uit tiental ***********************************************************************************************/ #define JUNIOR_SENIOR PIN_A0 #define START PIN_A1 #define UIT_MIN PIN_A2 #define UIT_PLUS PIN_A3 #define KLOK_MIN PIN_A4 #define KLOK_PLUS PIN_A5 #define MIA_MIN PIN_B2 #define MIA_PLUS PIN_B3 #define DEBOUNCE_PERIOD_IN_MS 100 #define DEBOUNCE_COUNT 50 int address = 0; int prev_second = 0; int seconden = 0; int minuten = 0; float enkel_seconds = 0.0; float tiental_seconds = 0.0; float enkel_minuten = 0.0; float tiental_minuten = 0.0; float temp_seconds = 0.0; float temp_minuten = 0.0; int score_MIA = 0; float temp_MIA_score = 0.0; float enkel_MIA_score = 0.0; float tiental_MIA_score = 0.0; int score_UIT = 0; float temp_UIT_score = 0.0; float enkel_UIT_score = 0.0; float tiental_UIT_score = 0.0; int start_first = 1; int start_again = 0; int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int count5 = 0; int count6 = 0; int count7 = 0; int count8 = 0; int count9 = 0; int count10 = 0; int16 i=0, j=0; int16 CheckSum; extern int minutes; void set_display_uit() { for(address = 0; address < 8; ++address)// seconde teller op alle segmenten { i2c_pcf8574_set_io(PCF8574_ID, address, 0); delay_ms(20); } } void set_display_HOI_MIA() { i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[10]); //H i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[0]); //O i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[14]); //I i2c_pcf8574_set_io(PCF8574_ID, 2, 0);//SEGMENT UIT delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[11]); //n i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[11]); //n i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[14]); //I i2c_pcf8574_set_io(PCF8574_ID, 2, LED_MAP[12]); //A delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); } // 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,H ,N ,A ,L ,I // BYTE CONST LED_MAP[16] = {0x6f ,0x03 ,0x5d ,0x57 ,0x33 ,0x76 ,0x7E ,0x43 ,0x7F ,0x77 ,0x3B ,0x6B ,0x7B ,0x2C ,0x28}; void set_display_GOAL_MIA() { i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[10]); //G i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[0]); //O i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[12]); //A i2c_pcf8574_set_io(PCF8574_ID, 2, LED_MAP[13]); //L delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[11]); //n i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[11]); //n i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[14]); //I i2c_pcf8574_set_io(PCF8574_ID, 2, LED_MAP[12]); //A delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); delay_ms(255); } void display_speeltijd() { if(seconden == 0) { minuten = minuten -1; } seconden = 59 - seconds; temp_seconds = ((float)seconden / 10.0); enkel_seconds = modf((temp_seconds) , &tiental_seconds); enkel_seconds = floor((enkel_seconds*10)+0.5); i2c_pcf8574_set_io(PCF8574_ID, 2, LED_MAP[((int)enkel_seconds)]); i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[((int)tiental_seconds)]); temp_minuten = ((float)minuten / 10.0); enkel_minuten = modf((temp_minuten) , &tiental_minuten); enkel_minuten = floor((enkel_minuten*10)+0.5); i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[((int)enkel_minuten)]); i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[((int)tiental_minuten)]); prev_second = seconds; } void set_beginstand() { i2c_pcf8574_set_io(PCF8574_ID, 0, LED_MAP[0]);//tiental score MIA i2c_pcf8574_set_io(PCF8574_ID, 1, LED_MAP[0]);//enkel score MIA i2c_pcf8574_set_io(PCF8574_ID, 2, LED_MAP[0]);//enkel sec i2c_pcf8574_set_io(PCF8574_ID, 3, LED_MAP[0]);//tiental sec i2c_pcf8574_set_io(PCF8574_ID, 4, LED_MAP[5]);//enkel min i2c_pcf8574_set_io(PCF8574_ID, 5, LED_MAP[3]);//tiental min i2c_pcf8574_set_io(PCF8574_ID, 6, LED_MAP[0]);//tiental score UIT i2c_pcf8574_set_io(PCF8574_ID, 7, LED_MAP[0]);//enkel score UIT } void set_stand() { temp_MIA_score = ((float)score_MIA / 10.0); enkel_MIA_score = modf((temp_MIA_score) , &tiental_MIA_score); enkel_MIA_score = floor((enkel_MIA_score*10)+0.5); i2c_pcf8574_set_io(PCF8574_ID, 6, LED_MAP[((int)enkel_MIA_score)]); i2c_pcf8574_set_io(PCF8574_ID, 7, LED_MAP[((int)tiental_MIA_score)]); temp_UIT_score = ((float)score_UIT / 10.0); enkel_UIT_score = modf((temp_UIT_score) , &tiental_UIT_score); enkel_UIT_score = floor((enkel_UIT_score*10)+0.5); i2c_pcf8574_set_io(PCF8574_ID, 0, LED_MAP[((int)enkel_UIT_score)]); i2c_pcf8574_set_io(PCF8574_ID, 1, LED_MAP[((int)tiental_UIT_score)]); } void main() { setup_adc_ports(AN0|VSS_VDD); setup_adc(ADC_CLOCK_DIV_32); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); //setup_timer_1(T1_DISABLED); setup_ccp2(CCP_PWM); set_pwm2_duty(512); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_low_volt_detect(FALSE); setup_oscillator(False); Initialize_RTC(); set_display_uit(); set_display_HOI_MIA(); set_display_uit(); minuten = 35; Seconden = 0; set_beginstand(); Init_RF12(); while (1) { while(!(input(nIRQ))) { RF_RXBUF[i++]=RF12_RDFIFO(); if(i==17) { i=0; WriteCMD(0xCA80); WriteCMD(0xCA83); CheckSum=0; for(j=0;j<16;j++) CheckSum+=RF_RXBUF[j]; CheckSum&=0x0FF; if(CheckSum==RF_RXBUF[16]) { } Delay_us(1); } } while(1) { if((input(UIT_PLUS) == 0) && (input(MIA_PLUS) == 0)) count10++; else count10 = 0; if(count10 == DEBOUNCE_COUNT) { disable_interrupts( GLOBAL ); delay_ms(200); Seconds = 0; minutes = 35; start_first = 1; start_again = 0; score_MIA = 0; score_UIT = 0; minuten = 35; seconden = 0; prev_second = 0; enkel_seconds = 0.0; tiental_seconds = 0.0; enkel_minuten = 5.0; tiental_minuten = 3.0; temp_seconds = 0.0; temp_minuten = 0.0; score_MIA = 0; temp_MIA_score = 0.0; enkel_MIA_score = 0.0; tiental_MIA_score = 0.0; score_UIT = 0; temp_UIT_score = 0.0; enkel_UIT_score = 0.0; tiental_UIT_score = 0.0; start_first = 1; start_again = 0; count1 = 0; count2 = 0; count3 = 0; count4 = 0; count5 = 0; count6 = 0; count7 = 0; count8 = 0; count9 = 0; count10 = 0; set_stand(); set_beginstand(); while((input(MIA_PLUS) == 0)); } break; } while(1) { if(input(MIA_PLUS) == 0) count1++; else count1 = 0; if(count1 == DEBOUNCE_COUNT) { score_MIA = score_MIA+1; set_stand(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count1 = 0; // while((input(MIA_PLUS) == 0)); } break; } while(1) { if(input(MIA_MIN) == 0) count2++; else count2 = 0; if(count2 == DEBOUNCE_COUNT) { score_MIA = score_MIA-1; set_stand(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count2 = 0; while(!(input(MIA_MIN))); } break; } while(1) { if(input(UIT_PLUS) == 0) count3++; else count3 = 0; if(count3 == DEBOUNCE_COUNT) { score_UIT = score_UIT+1; set_stand(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count3 = 0; // while(!(input(UIT_PLUS))); } break; } while(1) { if(input(UIT_MIN) == 0) count4++; else count4 = 0; if(count4 == DEBOUNCE_COUNT) { score_UIT = score_UIT-1; set_stand(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count4 = 0; while(!(input(UIT_MIN))); } break; } while(1) { if(input(KLOK_PLUS) == 0) count5++; else count5 = 0; if(count5 == DEBOUNCE_COUNT) { minuten = minuten + 5; display_speeltijd(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count5 = 0; while(!(input(KLOK_PLUS))); } break; } while(1) { if(input(KLOK_MIN) == 0) count6++; else count6 = 0; if(count6 == DEBOUNCE_COUNT) { minuten = minuten - 5; display_speeltijd(); delay_ms(DEBOUNCE_PERIOD_IN_MS); count6 = 0; while(!(input(KLOK_MIN))); } break; } while(1) { if((input(START)== 0) && (start_first)) count7++; else count7 = 0; if(count7 == DEBOUNCE_COUNT) { start_first = 0; enable_interrupts( GLOBAL ); delay_ms(DEBOUNCE_PERIOD_IN_MS); count7 = 0; while((input(START) == 0)); } break; } while(1) { if((input(START)== 0) && ((start_again == 0)) && ((start_first == 0))) count8++; else count8 = 0; if(count8 == DEBOUNCE_COUNT) { disable_interrupts( GLOBAL ); start_again = (!(start_again)); while((input(START) == 0)); } break; } while(1) { if((input(START)== 0) & (start_again) && (!(start_first))) count9++; else count9 = 0; if(count9 == DEBOUNCE_COUNT) { enable_interrupts( GLOBAL ); start_again = (!(start_again)); while((input(START) == 0)); } break; } if((((minuten == 1) & (seconden == 0)) & (input(JUNIOR_SENIOR) == 1))) { disable_interrupts( GLOBAL ); } if((((minuten == 0) & (seconden == 0)) & (input(JUNIOR_SENIOR) == 0))) { disable_interrupts( GLOBAL ); } if (seconds != prev_second) // er is dus een seconde verstreken { display_speeltijd(); } } }