diff options
Diffstat (limited to 'main.c')
-rwxr-xr-x | main.c | 158 |
1 files changed, 85 insertions, 73 deletions
@@ -17,16 +17,17 @@ void main(void) {
TRISA0 = 0x01; // RA is input (ADC)
-
- TRISBbits.TRISB0 = 0; // Set RB0 as output
- PORTBbits.RB0 = 0; // Set RB0 low
-
+
TRISC = 0x00; // Set PORTC as outputs
PORTC = 0x00; // Set all PORTC pins LOW
TRISD = 0x00; // Set PORTD as outputs
PORTD = 0x00; // Set all PORTD pins LOW
+ GIE = 1; // Enable global interrupt
+ PEIE = 1; // Enable the peripheral interrupt
+ INTE = 1; // Enable RB0 as external interrupt
+
#ifdef DEBUG
Initialize_UART(); //Initialize UART module
UART_send_string(CLS); // Clear screen
@@ -73,6 +74,7 @@ void main(void) { //Set_Time();
//Set_Date();
//Set_DayOfWeek(Get_DayOfWeek(year, month, date));
+ Set_Sqwe(0x40); //1Hz
// Write default alarm values
@@ -87,83 +89,86 @@ void main(void) { #ifdef VFD
Vfd_Set_Brightness(3); //Max brightness 3 - minimum
#endif
+
+ while(1){
+
+ }
+}
- while (1) {
-
- // Set time and date variables from DS3231
- //#ifdef DEBUG
- // UART_send_string("Updating current date time from DS3231\r\n");
- //#endif
- Update_Current_Date_Time();
-
- // Read temp
- //#ifdef DEBUG
- // UART_send_string("Reading Alarms and Temperature");
- //#endif
- Read_Alarms_Temp();
-
- // Get Alarm Status
- Get_Alarm_Status();
-
- // Separate the int timedate variables into chars
- //#ifdef DEBUG
- // UART_send_string("Formatting chars");
- //#endif
- format_DateTimeChars();
-
- // Format temperature
- //#ifdef DEBUG
- // UART_send_string("Formating temperature");
- //#endif
- format_Temperature();
-
- // Determine day of the week from Calendar Date
- //#ifdef DEBUG
- // UART_send_string("Determining day of week");
- //#endif
- getWeekDay(Get_DayOfWeek(year, month, date));
-
- // Enter loop and update display if sec changes from DS3231
- if (sec_chg != sec) {
-
- update_Display();
-
- // Set temp_sec to current sec from DS3231
- sec_chg = sec;
- }
+void New_Second() {
+ // Set time and date variables from DS3231
+ //#ifdef DEBUG
+ // UART_send_string("Updating current date time from DS3231\r\n");
+ //#endif
+ Update_Current_Date_Time();
+
+ // Read temp
+ //#ifdef DEBUG
+ // UART_send_string("Reading Alarms and Temperature");
+ //#endif
+ Read_Alarms_Temp();
+
+ // Get Alarm Status
+ Get_Alarm_Status();
+
+ // Separate the int timedate variables into chars
+ //#ifdef DEBUG
+ // UART_send_string("Formatting chars");
+ //#endif
+ format_DateTimeChars();
+
+ // Format temperature
+ //#ifdef DEBUG
+ // UART_send_string("Formating temperature");
+ //#endif
+ format_Temperature();
+
+ // Determine day of the week from Calendar Date
+ //#ifdef DEBUG
+ // UART_send_string("Determining day of week");
+ //#endif
+ getWeekDay(Get_DayOfWeek(year, month, date));
+
+ // Enter loop and update display if sec changes from DS3231
+ if (sec_chg != sec) {
+
+ update_Display();
+
+ // Set temp_sec to current sec from DS3231
+ sec_chg = sec;
+ }
#ifdef ADC
- // Get current LDR reading and calculate for brightness levels 0 - 3
- ldr = Adc_Read(0);
+ // Get current LDR reading and calculate for brightness levels 0 - 3
+ ldr = Adc_Read(0);
- if (brtlvl_chg != brtlvl) {
- Vfd_Set_Brightness(brtlvl);
- brtlvl_chg = brtlvl;
- }
+ if (brtlvl_chg != brtlvl) {
+ Vfd_Set_Brightness(brtlvl);
+ brtlvl_chg = brtlvl;
+ }
#endif
#ifdef DEBUG
- UART_send_string(CURSOR(19, 1));
- sprintf(buf, "%sTIME:%s\t%02d:%02d:%02d\t%sDATE:%s\t%02d/%02d/%02d\r\n", YELLOW, CLRATTR,
- hour, min, sec, YELLOW, CLRATTR, date, month, year);
- UART_send_string(buf);
- sprintf(buf, "%sAL1:%s\t%02d:%02d:%02d\t%sSTATUS:%s %d\r\n", YELLOW,
- CLRATTR, alarm1_hour, alarm1_min, alarm1_sec, YELLOW,
- CLRATTR, alarm1_status);
- UART_send_string(buf);
- sprintf(buf, "%sAL2:%s\t%02d:%02d\t\t%sSTATUS:%s %d\r\n", YELLOW,
- CLRATTR, alarm2_hour, alarm2_min, YELLOW, CLRATTR,
- alarm2_status);
- UART_send_string(buf);
- sprintf(buf, "%sWKDAY:%s\t%d\t\t%sDAY:%s\t%s\r\n", YELLOW, CLRATTR,
- day, YELLOW, CLRATTR, weekday);
- UART_send_string(buf);
- sprintf(buf, "%sTEMP:\t%s%c%c%c.%c%cC%s\t\t%sLDR:%s\t\%04d %d\r\n",
- YELLOW, CLRATTR, temp_sign, temp_2, temp_1, temp_0, 0xB0,
- CLRATTR, YELLOW, CLRATTR, ldr, brtlvl);
- UART_send_string(buf);
+ UART_send_string(CURSOR(19, 1));
+ sprintf(buf, "%sTIME:%s\t%02d:%02d:%02d\t%sDATE:%s\t%02d/%02d/%02d\r\n", YELLOW, CLRATTR,
+ hour, min, sec, YELLOW, CLRATTR, date, month, year);
+ UART_send_string(buf);
+ sprintf(buf, "%sAL1:%s\t%02d:%02d:%02d\t%sSTATUS:%s %d\r\n", YELLOW,
+ CLRATTR, alarm1_hour, alarm1_min, alarm1_sec, YELLOW,
+ CLRATTR, alarm1_status);
+ UART_send_string(buf);
+ sprintf(buf, "%sAL2:%s\t%02d:%02d\t\t%sSTATUS:%s %d\r\n", YELLOW,
+ CLRATTR, alarm2_hour, alarm2_min, YELLOW, CLRATTR,
+ alarm2_status);
+ UART_send_string(buf);
+ sprintf(buf, "%sWKDAY:%s\t%d\t\t%sDAY:%s\t%s\r\n", YELLOW, CLRATTR,
+ day, YELLOW, CLRATTR, weekday);
+ UART_send_string(buf);
+ sprintf(buf, "%sTEMP:\t%s%c%c%c.%c%cC%s\t\t%sLDR:%s\t\%04d %d\r\n",
+ YELLOW, CLRATTR, temp_sign, temp_2, temp_1, temp_0, 0xB0,
+ CLRATTR, YELLOW, CLRATTR, ldr, brtlvl);
+ UART_send_string(buf);
#endif
- }
}
// Format unsigned int to unsigned chars
@@ -339,4 +344,11 @@ void update_Display() { if (min == 30 && sec == 00) {
alarm(1);
}
+}
+
+void __interrupt() isr(void) {
+ if (INTF == 1) {
+ INTF = 0;
+ New_Second();
+ }
}
\ No newline at end of file |