#define LCD #include "freedom.h" #include unsigned char my_is_alarm_ON_RTCC (void); void High_Int_Event(void); #pragma code high_vector = 0x08 void high_interrupt(void) { _asm GOTO High_Int_Event _endasm } #pragma code #pragma interrupt High_Int_Event void High_Int_Event(void) { BUZZER = 1; } void main() { InitFreedom(); RCONbits.IPEN = 1; //architettura PIC18 INTCONbits.GIEH = 1; INTCONbits.GIEL = 1; //abilita interrupt su INT2 (JP9 in posizione 1-2) INTCON3bits.INT2IE = 1; INTCON2bits.INTEDG2 = 0; //fronte di discesa INTCON3bits.INT2IP = 1; // Inizializza il modulo I2C a 400KHz @20MHz OpenI2C(MASTER, SLEW_ON); SSPADD = 12; // Inizializzo la data set_days_RTCC (0x30); set_months_RTCC (0x12); set_years_RTCC (0x08); // Inizializzo l'ora set_hours_RTCC (0x02); set_minutes_RTCC (0x56); set_seconds_RTCC (0x53); //imposta l'allarme (stesso giorno dopo mezzo minuto) enable_alarm_interrupt_RTCC(); //set_days_alarm_RTCC(0x30,0); //set_hours_alarm_RTCC(0x02,0); set_minutes_alarm_RTCC(0x57,0); // buzzer test BUZZER = 1; delay_ms(50); BUZZER = 0; delay_ms(50); BUZZER = 1; delay_ms(50); BUZZER = 0; delay_ms(50); BUZZER = 1; delay_ms(50); BUZZER = 0; while (1) { HomeLCD(); WriteStringLCD("Time: "); WriteVarLCD(get_date_RTCC ()); Line2LCD(); WriteStringLCD("Date: "); WriteVarLCD(get_time_seconds_RTCC ()); if (my_is_alarm_ON_RTCC()) WriteStringLCD(" X"); else WriteStringLCD(" _"); } } //************************************************************ // IsAlarmON function implementation //************************************************************ unsigned char my_is_alarm_ON_RTCC (void) { unsigned char value; value = EERandomRead (WRITE_ADD,CONTROL_REG_2_ADDR); // Just AF bit is controlled if (value & 0x08) { value = value & 0xF7; // I clean AF bit without canging the other bits //modificata !!!!!!! //EEByteWrite (WRITE_ADD,0x01,value); return (1); } else { return (0); } }