Microcontroller › PIC › how to implement interrupt to avoid stack overflow
- This topic has 0 replies, 1 voice, and was last updated 11 years, 5 months ago by John Paul Degala.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
August 18, 2013 at 2:22 pm #2594John Paul DegalaParticipant
hi, i have project that used 5 buttons, lcd and lm35, but when i try to put some codes in 5th button it gives an error of stack overflow, I want to implement interrupt but I dont know how, please help me, this my code in mikroc
//LCD module connections
sbit LCD_RS at RB4_bit;sbit LCD_EN at RB5_bit;sbit LCD_D4 at RB0_bit;sbit LCD_D5 at RB1_bit;sbit LCD_D6 at RB2_bit;sbit LCD_D7 at RB3_bit;sbit LCD_RS_Direction at TRISB4_bit;sbit LCD_EN_Direction at TRISB5_bit;sbit LCD_D4_Direction at TRISB0_bit;sbit LCD_D5_Direction at TRISB1_bit;sbit LCD_D6_Direction at TRISB2_bit;sbit LCD_D7_Direction at TRISB3_bit;//global variables
float temp;char txt[15];unsigned char pointer, pointer1, i, gCnt;//pointer and pointer1 used to point “3 rows” and “2 rows” respectivelybit read_temp; //1 – enable reading, 0 – disable readingconst char Arrow[] = {0,0,4,6,31,6,4,0};//arrow logo
void CustomChar(char pos_row, char pos_char) {char i;Lcd_Cmd(64);for (i = 0; i<=7; i++) Lcd_Chr_CP(Arrow);Lcd_Cmd(_LCD_RETURN_HOME);Lcd_Chr(pos_row, pos_char, 0);}//enable/disable Arrow in a row
void en_Arrow(){if(pointer == 0){CustomChar(1,1);LCD_out(2,1, ” “);LCD_out(3,1, ” “);}else if(pointer == 1){CustomChar(2,1);LCD_out(1,1, ” “);LCD_out(3,1, ” “);}else if(pointer == 2){CustomChar(3,1);LCD_out(1,1, ” “);LCD_out(2,1, ” “);}}//main method
void main(){CMCON = 0X07;//configure ADC
ADCON0 = 0x0B; //CHS3:CHS0 = 0010 (Select AN2), GO/DONE = 1, ADON = 1ADCON1 = 0x0C; //PCFG3:PCFG0 = 1100 (AN2-AN0 as analog pins)ADCON2 = 0X8C; //ADFM = 1, ACQT2:ACQT0 = 001, ADCS2:ADCS0 = 100TRISA = 0x04; //AN2 as analog PINTRISD = 0xff; //Digital input for buttonsADC_init();LCD_Init();LCD_Cmd(_LCD_CURSOR_OFF);lcd_out(1,1, “Initializing……”);delay_ms(1000);LCD_Cmd(_LCD_CLEAR);read_temp = 1;do {//MENU
if(PORTD.F6==0){menu:LCD_Cmd(_LCD_CLEAR);CustomChar(1,1);LCD_out(2,1, ” “);LCD_out(1,2,”Home”);LCD_out(2,2,”System Setting”);LCD_Out(3,2, “Schedule Time”);pointer = 0;read_temp = 0;pointer1 = 3;}//UP and DOWN
else if(PORTD.F4==0 || PORTD.F5==0){if(PORTD.F4==0){if(pointer >0 && pointer < 3) pointer -= 1;else pointer = 0;}else{if(pointer >=0 && pointer < (pointer1 – 1)) pointer += 1;else pointer = pointer1-1;}en_Arrow();}//SELECT
else if(PORTD.F1==0){LCD_cmd(_LCD_clear);if(pointer == 0) read_temp = 1;else if(pointer == 1){pointer1 = 2;CustomChar(1,1);LCD_out(1,3,”Date NOW: 12/12/13″);LCD_out(2,3,”Time NOW: 00:00 AM”);}else{CustomChar(1,1);LCD_out(1,3,”SET Date: 12/12/13″);LCD_out(2,3,”SET Time: 00:00 AM”);LCD_out(3,3,”Duration: 00:00″);}pointer = 0;}//right
else if(PORTD.F2==0){for(i=0; i<; i++){} //got stack overflow!!!. ..}//Read temperature
if(read_temp==1){LCD_Cmd(_LCD_CLEAR);Lcd_Out(1, 1, “Temp:”);Lcd_Chr(1,12,223);Lcd_Chr(1,13,’C’);Lcd_Out(2,1, “12/12/13”);Lcd_out (2,12, “12:00 PM”);while(1){if(PORTD.F6==0){goto menu;break;}temp = (ADC_Get_Sample(2) * 5)/10.325; // Get 10-bit results of AD conversionADCON2.ADON=0;FloatToStr(temp, txt);txt[4] = 0;Lcd_Out(1,7,txt);}}delay_ms(25);} while(1); // endless loop} -
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.