#include #include #include #include #include #include #define LCD_DEFAULT #include #include #pragma config FOSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config PBADEN = OFF //OSC = HS Impostato per lavorare ad alta frequenza //WDT = OFF Disabilito il watchdog timer //LVP = OFF Disabilito programmazione LVP //PBADEN = OFF Disabilito gli ingressi analogici #define BT1 0b11100000 #define BT2 0b11010000 #define BT3 0b10110000 #define BT4 0b01110000 /******************************************/ // Prototipo di funzione /******************************************/ void High_Int_Event (void); //Interrupt vector per modalita' compatibile #pragma code high_interrupt_vector = 0x08 void high_interrupt (void) { // Salto per la gestione dell'interrupt _asm GOTO High_Int_Event _endasm } #pragma code /******************************************/ // Gestione Interrupt /******************************************/ #pragma interrupt High_Int_Event // Funzione per la gestione dell'interruzione void High_Int_Event (void) { // Indice per il ciclo di pausa int i; unsigned char button; // Controllo che l'interrupt sia stato generato da PORTB if (INTCONbits.RBIF == 1 ) { //pausa filtraggio spike delay_ms (30); button = PORTB; button = button & 0xF0; // Controllo del tasto premuto switch(button) { case BT1 & BT3: increment_minutes_RTCC (); BacklightLCD (TURN_ON_LED); break; case BT1 & BT4: increment_hours_RTCC (); BacklightLCD (TURN_ON_LED); break; case BT2: increment_years_RTCC (); BacklightLCD (TURN_ON_LED); break; case BT3: increment_months_RTCC (); BacklightLCD (TURN_ON_LED); break; case BT4: increment_days_RTCC (); BacklightLCD (TURN_ON_LED); break; } // Resetto il flag d'interrupt per permettere nuove interruzioni INTCONbits.RBIF = 0; } } /******************************************/ // Programma Principale /******************************************/ void main (void){ // Variabile per salvare il dato di ritorno unsigned char data = 0; unsigned int count = 0; // Imposto PORTA tutti ingressi LATA = 0x00; TRISA = 0xFF; // Imposto PORTB tutti ingressi LATB = 0x00; TRISB = 0xFF; // Imposto PORTC tutti ingressi, RC1 come output LATC = 0x00; TRISC = 0b11111100; // Imposto PORTD tutte uscite LATD = 0x00; TRISD = 0x00; // Imposto PORTE tutti ingressi LATE = 0x00; TRISE = 0xFF; // Inizializza il modulo I2C a 400KHz @20MHz OpenI2C(MASTER, SLEW_ON); SSPADD = 12; OpenLCD (20); BacklightLCD (TURN_ON_LED); // Inizializzo la data set_days_RTCC (0x14); set_months_RTCC (0x05); set_years_RTCC (0x12); // Inizializzo l'ora set_hours_RTCC (0x02); set_minutes_RTCC (0x56); set_seconds_RTCC (0x33); // Abilita i resistori di pull-up sulla PORTB EnablePullups(); // Abilito le interruzioni su PORTB INTCONbits.RBIE = 1; // Abilito modalita' compatibile (di default vale gia' 0) RCONbits.IPEN = 0; // Abilito l'interrupt globale INTCONbits.GIE = 1; // Abilito l'interrupt periferiche INTCONbits.PEIE = 1 ; // Ciclo infinito while (1) { count++; if(count==200) { BacklightLCD (TURN_OFF_LED); count = 0; } WriteVarLCD (get_date_RTCC ()); WriteStringLCD (" "); WriteVarLCD (get_time_RTCC ()); HomeLCD (); } }