I am learning about PIC development, and I have been tinkering with interrupts, I am using a RTC clock module to wake my PIC every minute for reading temp, time etc. I have been having issues with the interrupt routine not working, So I put the code in the main loop so when my PIC comes back to life the code is executed to reset registers. Can anyone help it would be awesome to have this happen in the Interrupt procedure instead of the main loop.
Code: Select all
program RealTimeClock;
//uses RTC2_DS1307;
uses RTC_DS3231SN, EEPROM_24LC512;
{ Declarations section }
// For DS1307 to uses
Var ts : String[8]; // String to hold the time from DS1307
Var ds : String[10]; // String to hold the date from DS1307
Var text3,text4 : String[20];
Var text1 : String[10];
Var text2 : String[3];
Var EEPROM_Byte : Byte;
Var Values : Array[256] of Byte;
Var Count : Byte;
// LCD module connections
var LCD_RS : sbit at LATE4_bit;
var LCD_EN : sbit at LATE5_bit;
var LCD_D4 : sbit at LATE0_bit;
var LCD_D5 : sbit at LATE1_bit;
var LCD_D6 : sbit at LATE2_bit;
var LCD_D7 : sbit at LATE3_bit;
var LCD_RS_Direction : sbit at TRISE4_bit ;
var LCD_EN_Direction : sbit at TRISE5_bit ;
var LCD_D4_Direction : sbit at TRISE0_bit;
var LCD_D5_Direction : sbit at TRISE1_bit;
var LCD_D6_Direction : sbit at TRISE2_bit;
var LCD_D7_Direction : sbit at TRISE3_bit;
// End LCD module connections
var Flag : Bit;
Procedure Interrupt_Low;
Begin
Flag := 1;
if TestBit(INTCON, INT0IF) = 1 then
begin
INTCON.INT0IF := 0;
INTCON.INT0IE := 1;
ClearBit(INTCON, INT0IF); //Clear the interrupt Flag
end;
end;
begin org 0x1000;
orgall(0x1000);
{ Main program }
TRISB := 1;
INTCON := 0x10;
INTCON2.6 := 0;
TRISG0_Bit := 0;
PORTG.0 := 1;
EEPROM_Byte := 99;
//initialize the LCD display
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,'Booted !');
//initialize the I2C
i2c1_init(100000);
Lcd_Out(1,1,'I2C Init Done !');
initRTC; //Initialize Connection to the RTC
RtcSetInterruptMinute;
RTCClearInterrupt;
Lcd_Out(1,1,'RTC Init Done !');
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
while true do
begin
if TestBit(INTCON, INT0IF) = 1 then
begin
INTCON.INT0IF := 0;
INTCON.INT0IE := 1;
ClearBit(INTCON, INT0IF); //Clear the interrupt Flag
RTCClearInterrupt; //Clear the RTC Interrupt Flag
end;
RtcTimeDateStr(text3, text4); //Get the Time and Date
Lcd_Out(1, 1, text3); // Print text at LCD
Lcd_Out(2, 1, text4); // Print text at LCD
RtcTempStr(text1);
Lcd_Out(1,9,text1);
Lcd_Chr(1,15,223); // Print degree character, 'C' for Centigrades
// Different LCD displays have different char code for degree
Lcd_Chr(1,16,'C');
delay_ms(2500);
LCD_CMD(_LCD_CLEAR);
LCD_Out(1,1,'Sleeping....');
PORTG.0 := 0;
asm
sleep; //Send Processor to sleep
end;
end;
end.
Phil