Utilicé el microcontrolador PIC18F452 para mi proyecto. Y estoy usando el software mikroc pro. Mi código compilado con éxito. Pero en proteus, dará el error "El desbordamiento de pila está forzando el restablecimiento del dispositivo". Y no obtengo la salida de LCD.
He adjuntado el código aquí:
// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections
void main() {
double m,a,voltage,level,noise_level;
//char *text;
int l;
char ch,ch1,ch2,ch3;
//long tlong; //
int pot_value;
TRISB = 0x00; // PORTB is output
TRISC = 0x00; // PORTC is output
TRISD = 0x00; // PORTD is output
TRISA = 0xFF; // All port A pins are configured as inputs
ADCON0 = 0x81; //AN0 for analogue input
ADCON1 = 0xC4; //voltage at AN3 as Vref
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Noise Level");//Write text'Hello World' in first row
while(1)
{
pot_value = ADC_Read(0);
voltage = pot_value * 5.0/1023.0;
a=voltage/1.573;
if(1<=a<10)
{
l=0;
ch=a;
}
if (0.1<=a<1)
{
l=-1;
ch=a*10;
}
if (0.01<=a<0.1)
{
l=-2;
ch=a*100;
}
if (0.001<=a<0.01)
{
l=-3;
ch=a*1000;
}
if (0.0001<=a<0.001)
{
l=-4;
ch=a*10000;
}
switch (ch)
{
case 1: m=0.0; break;
case 2: m=0.39; break;
case 3: m=0.544; break;
case 4: m=0.65; break;
case 5: m=0.74; break;
case 6: m=0.813; break;
case 7: m=0.875; break;
case 8: m=0.929; break;
case 9: m=0.977; break;
default: m=0.977;
}
level=40*(l+m);
noise_level=94.0+level;
ch1=noise_level/10;
Lcd_Chr(2,2,48+ch1);
m = (a*10);
ch2=m-ch1*10;
Lcd_Chr_CP(48+ch2);
Lcd_Chr_CP('.');
m = (a*100);
ch3=m-(ch1*10+ch2)*10;
Lcd_Chr_CP(48+ch3);
Lcd_Out_Cp("dBA");
Delay_ms(1);
}
}
Y el esquema:
Losmensajesdeerror:
Y la asamblea:
_main:
;MyProject.c,17 :: void main() {
;MyProject.c,26 :: TRISB = 0x00; // PORTB is output
CLRF TRISB+0
;MyProject.c,27 :: TRISC = 0x00; // PORTC is output
CLRF TRISC+0
;MyProject.c,28 :: TRISD = 0x00; // PORTD is output
CLRF TRISD+0
;MyProject.c,30 :: TRISA = 0xFF; // All port A pins are configured as inputs
MOVLW 255
MOVWF TRISA+0
;MyProject.c,31 :: ADCON0 = 0x81; //AN0 for analogue input
MOVLW 129
MOVWF ADCON0+0
;MyProject.c,32 :: ADCON1 = 0xC4; //voltage at AN3 as Vref
MOVLW 196
MOVWF ADCON1+0
;MyProject.c,34 :: Lcd_Init(); // Initialize LCD
CALL _Lcd_Init+0, 0
;MyProject.c,35 :: Lcd_Cmd(_LCD_CLEAR); // Clear display
MOVLW 1
MOVWF FARG_Lcd_Cmd_out_char+0
CALL _Lcd_Cmd+0, 0
;MyProject.c,36 :: Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
MOVLW 12
MOVWF FARG_Lcd_Cmd_out_char+0
CALL _Lcd_Cmd+0, 0
;MyProject.c,37 :: Lcd_Out(1,1,"Noise Level");//Write text'Hello World' in first row
MOVLW 1
MOVWF FARG_Lcd_Out_row+0
MOVLW 1
MOVWF FARG_Lcd_Out_column+0
MOVLW ?lstr1_MyProject+0
MOVWF FARG_Lcd_Out_text+0
MOVLW hi_addr(?lstr1_MyProject+0)
MOVWF FARG_Lcd_Out_text+1
CALL _Lcd_Out+0, 0
;MyProject.c,39 :: while(1)
L_main0:
;MyProject.c,41 :: pot_value = ADC_Read(0);
CLRF FARG_ADC_Read_channel+0
CALL _ADC_Read+0, 0
;MyProject.c,42 :: voltage = pot_value * 5.0/1023.0;
CALL _Int2Double+0, 0
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 32
MOVWF R6
MOVLW 129
MOVWF R7
CALL _Mul_32x32_FP+0, 0
MOVLW 0
MOVWF R4
MOVLW 192
MOVWF R5
MOVLW 127
MOVWF R6
MOVLW 136
MOVWF R7
CALL _Div_32x32_FP+0, 0
;MyProject.c,43 :: a=voltage/1.573;
MOVLW 16
MOVWF R4
MOVLW 88
MOVWF R5
MOVLW 73
MOVWF R6
MOVLW 127
MOVWF R7
CALL _Div_32x32_FP+0, 0
MOVF R0, 0
MOVWF main_a_L0+0
MOVF R1, 0
MOVWF main_a_L0+1
MOVF R2, 0
MOVWF main_a_L0+2
MOVF R3, 0
MOVWF main_a_L0+3
;MyProject.c,45 :: if(1<=a<10)
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 0
MOVWF R6
MOVLW 127
MOVWF R7
CALL _Compare_Double+0, 0
MOVLW 0
BTFSC STATUS+0, 0
MOVLW 1
MOVWF R0
MOVLW 10
SUBWF R0, 0
BTFSC STATUS+0, 0
GOTO L_main2
;MyProject.c,47 :: l=0;
CLRF main_l_L0+0
CLRF main_l_L0+1
;MyProject.c,48 :: ch=a;
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch_L0+0
;MyProject.c,49 :: }
L_main2:
;MyProject.c,50 :: if (0.1<=a<1)
MOVLW 205
MOVWF R4
MOVLW 204
MOVWF R5
MOVLW 76
MOVWF R6
MOVLW 123
MOVWF R7
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
CALL _Compare_Double+0, 0
MOVLW 0
BTFSC STATUS+0, 0
MOVLW 1
MOVWF R0
MOVLW 1
SUBWF R0, 0
BTFSC STATUS+0, 0
GOTO L_main3
;MyProject.c,52 :: l=-1;
MOVLW 255
MOVWF main_l_L0+0
MOVLW 255
MOVWF main_l_L0+1
;MyProject.c,53 :: ch=a*10;
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 32
MOVWF R6
MOVLW 130
MOVWF R7
CALL _Mul_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch_L0+0
;MyProject.c,54 :: }
L_main3:
;MyProject.c,55 :: if (0.01<=a<0.1)
MOVLW 10
MOVWF R4
MOVLW 215
MOVWF R5
MOVLW 35
MOVWF R6
MOVLW 120
MOVWF R7
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
CALL _Compare_Double+0, 0
MOVLW 0
BTFSC STATUS+0, 0
MOVLW 1
MOVWF R0
CALL _Byte2Double+0, 0
MOVLW 205
MOVWF R4
MOVLW 204
MOVWF R5
MOVLW 76
MOVWF R6
MOVLW 123
MOVWF R7
CALL _Compare_Double+0, 0
MOVLW 1
BTFSC STATUS+0, 0
MOVLW 0
MOVWF R0
MOVF R0, 1
BTFSC STATUS+0, 2
GOTO L_main4
;MyProject.c,57 :: l=-2;
MOVLW 254
MOVWF main_l_L0+0
MOVLW 255
MOVWF main_l_L0+1
;MyProject.c,58 :: ch=a*100;
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 72
MOVWF R6
MOVLW 133
MOVWF R7
CALL _Mul_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch_L0+0
;MyProject.c,59 :: }
L_main4:
;MyProject.c,60 :: if (0.001<=a<0.01)
MOVLW 111
MOVWF R4
MOVLW 18
MOVWF R5
MOVLW 3
MOVWF R6
MOVLW 117
MOVWF R7
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
CALL _Compare_Double+0, 0
MOVLW 0
BTFSC STATUS+0, 0
MOVLW 1
MOVWF R0
CALL _Byte2Double+0, 0
MOVLW 10
MOVWF R4
MOVLW 215
MOVWF R5
MOVLW 35
MOVWF R6
MOVLW 120
MOVWF R7
CALL _Compare_Double+0, 0
MOVLW 1
BTFSC STATUS+0, 0
MOVLW 0
MOVWF R0
MOVF R0, 1
BTFSC STATUS+0, 2
GOTO L_main5
;MyProject.c,62 :: l=-3;
MOVLW 253
MOVWF main_l_L0+0
MOVLW 255
MOVWF main_l_L0+1
;MyProject.c,63 :: ch=a*1000;
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 122
MOVWF R6
MOVLW 136
MOVWF R7
CALL _Mul_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch_L0+0
;MyProject.c,64 :: }
L_main5:
;MyProject.c,65 :: if (0.0001<=a<0.001)
MOVLW 23
MOVWF R4
MOVLW 183
MOVWF R5
MOVLW 81
MOVWF R6
MOVLW 113
MOVWF R7
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
CALL _Compare_Double+0, 0
MOVLW 0
BTFSC STATUS+0, 0
MOVLW 1
MOVWF R0
CALL _Byte2Double+0, 0
MOVLW 111
MOVWF R4
MOVLW 18
MOVWF R5
MOVLW 3
MOVWF R6
MOVLW 117
MOVWF R7
CALL _Compare_Double+0, 0
MOVLW 1
BTFSC STATUS+0, 0
MOVLW 0
MOVWF R0
MOVF R0, 1
BTFSC STATUS+0, 2
GOTO L_main6
;MyProject.c,67 :: l=-4;
MOVLW 252
MOVWF main_l_L0+0
MOVLW 255
MOVWF main_l_L0+1
;MyProject.c,68 :: ch=a*10000;
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 64
MOVWF R5
MOVLW 28
MOVWF R6
MOVLW 140
MOVWF R7
CALL _Mul_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch_L0+0
;MyProject.c,69 :: }
L_main6:
;MyProject.c,71 :: switch (ch)
GOTO L_main7
;MyProject.c,73 :: case 1: m=0.0; break;
L_main9:
CLRF main_m_L0+0
CLRF main_m_L0+1
CLRF main_m_L0+2
CLRF main_m_L0+3
GOTO L_main8
;MyProject.c,74 :: case 2: m=0.39; break;
L_main10:
MOVLW 20
MOVWF main_m_L0+0
MOVLW 174
MOVWF main_m_L0+1
MOVLW 71
MOVWF main_m_L0+2
MOVLW 125
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,75 :: case 3: m=0.544; break;
L_main11:
MOVLW 150
MOVWF main_m_L0+0
MOVLW 67
MOVWF main_m_L0+1
MOVLW 11
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,76 :: case 4: m=0.65; break;
L_main12:
MOVLW 102
MOVWF main_m_L0+0
MOVLW 102
MOVWF main_m_L0+1
MOVLW 38
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,77 :: case 5: m=0.74; break;
L_main13:
MOVLW 164
MOVWF main_m_L0+0
MOVLW 112
MOVWF main_m_L0+1
MOVLW 61
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,78 :: case 6: m=0.813; break;
L_main14:
MOVLW 197
MOVWF main_m_L0+0
MOVLW 32
MOVWF main_m_L0+1
MOVLW 80
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,79 :: case 7: m=0.875; break;
L_main15:
MOVLW 0
MOVWF main_m_L0+0
MOVLW 0
MOVWF main_m_L0+1
MOVLW 96
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,80 :: case 8: m=0.929; break;
L_main16:
MOVLW 242
MOVWF main_m_L0+0
MOVLW 210
MOVWF main_m_L0+1
MOVLW 109
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,81 :: case 9: m=0.977; break;
L_main17:
MOVLW 172
MOVWF main_m_L0+0
MOVLW 28
MOVWF main_m_L0+1
MOVLW 122
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
GOTO L_main8
;MyProject.c,82 :: default: m=0.977;
L_main18:
MOVLW 172
MOVWF main_m_L0+0
MOVLW 28
MOVWF main_m_L0+1
MOVLW 122
MOVWF main_m_L0+2
MOVLW 126
MOVWF main_m_L0+3
;MyProject.c,83 :: }
GOTO L_main8
L_main7:
MOVF main_ch_L0+0, 0
XORLW 1
BTFSC STATUS+0, 2
GOTO L_main9
MOVF main_ch_L0+0, 0
XORLW 2
BTFSC STATUS+0, 2
GOTO L_main10
MOVF main_ch_L0+0, 0
XORLW 3
BTFSC STATUS+0, 2
GOTO L_main11
MOVF main_ch_L0+0, 0
XORLW 4
BTFSC STATUS+0, 2
GOTO L_main12
MOVF main_ch_L0+0, 0
XORLW 5
BTFSC STATUS+0, 2
GOTO L_main13
MOVF main_ch_L0+0, 0
XORLW 6
BTFSC STATUS+0, 2
GOTO L_main14
MOVF main_ch_L0+0, 0
XORLW 7
BTFSC STATUS+0, 2
GOTO L_main15
MOVF main_ch_L0+0, 0
XORLW 8
BTFSC STATUS+0, 2
GOTO L_main16
MOVF main_ch_L0+0, 0
XORLW 9
BTFSC STATUS+0, 2
GOTO L_main17
GOTO L_main18
L_main8:
;MyProject.c,85 :: level=40*(l+m);
MOVF main_l_L0+0, 0
MOVWF R0
MOVF main_l_L0+1, 0
MOVWF R1
CALL _Int2Double+0, 0
MOVF main_m_L0+0, 0
MOVWF R4
MOVF main_m_L0+1, 0
MOVWF R5
MOVF main_m_L0+2, 0
MOVWF R6
MOVF main_m_L0+3, 0
MOVWF R7
CALL _Add_32x32_FP+0, 0
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 32
MOVWF R6
MOVLW 132
MOVWF R7
CALL _Mul_32x32_FP+0, 0
;MyProject.c,86 :: noise_level=94.0+level;
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 60
MOVWF R6
MOVLW 133
MOVWF R7
CALL _Add_32x32_FP+0, 0
;MyProject.c,89 :: ch1=noise_level/10;
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 32
MOVWF R6
MOVLW 130
MOVWF R7
CALL _Div_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch1_L0+0
;MyProject.c,90 :: Lcd_Chr(2,2,48+ch1);
MOVLW 2
MOVWF FARG_Lcd_Chr_row+0
MOVLW 2
MOVWF FARG_Lcd_Chr_column+0
MOVF R0, 0
ADDLW 48
MOVWF FARG_Lcd_Chr_out_char+0
CALL _Lcd_Chr+0, 0
;MyProject.c,91 :: m = (a*10);
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 32
MOVWF R6
MOVLW 130
MOVWF R7
CALL _Mul_32x32_FP+0, 0
MOVF R0, 0
MOVWF main_m_L0+0
MOVF R1, 0
MOVWF main_m_L0+1
MOVF R2, 0
MOVWF main_m_L0+2
MOVF R3, 0
MOVWF main_m_L0+3
;MyProject.c,92 :: ch2=m-ch1*10;
MOVLW 10
MULWF main_ch1_L0+0
MOVF PRODL+0, 0
MOVWF R0
MOVF PRODH+0, 0
MOVWF R1
CALL _Int2Double+0, 0
MOVF R0, 0
MOVWF R4
MOVF R1, 0
MOVWF R5
MOVF R2, 0
MOVWF R6
MOVF R3, 0
MOVWF R7
MOVF main_m_L0+0, 0
MOVWF R0
MOVF main_m_L0+1, 0
MOVWF R1
MOVF main_m_L0+2, 0
MOVWF R2
MOVF main_m_L0+3, 0
MOVWF R3
CALL _Sub_32x32_FP+0, 0
CALL _Double2Byte+0, 0
MOVF R0, 0
MOVWF main_ch2_L0+0
;MyProject.c,93 :: Lcd_Chr_CP(48+ch2);
MOVF R0, 0
ADDLW 48
MOVWF FARG_Lcd_Chr_CP_out_char+0
CALL _Lcd_Chr_CP+0, 0
;MyProject.c,94 :: Lcd_Chr_CP('.');
MOVLW 46
MOVWF FARG_Lcd_Chr_CP_out_char+0
CALL _Lcd_Chr_CP+0, 0
;MyProject.c,95 :: m = (a*100);
MOVF main_a_L0+0, 0
MOVWF R0
MOVF main_a_L0+1, 0
MOVWF R1
MOVF main_a_L0+2, 0
MOVWF R2
MOVF main_a_L0+3, 0
MOVWF R3
MOVLW 0
MOVWF R4
MOVLW 0
MOVWF R5
MOVLW 72
MOVWF R6
MOVLW 133
MOVWF R7
CALL _Mul_32x32_FP+0, 0
MOVF R0, 0
MOVWF main_m_L0+0
MOVF R1, 0
MOVWF main_m_L0+1
MOVF R2, 0
MOVWF main_m_L0+2
MOVF R3, 0
MOVWF main_m_L0+3
;MyProject.c,96 :: ch3=m-(ch1*10+ch2)*10;
MOVLW 10
MULWF main_ch1_L0+0
MOVF PRODL+0, 0
MOVWF R0
MOVF PRODH+0, 0
MOVWF R1
MOVF main_ch2_L0+0, 0
ADDWF R0, 1
MOVLW 0
ADDWFC R1, 1
MOVLW 10
MOVWF R4
MOVLW 0
MOVWF R5
CALL _Mul_16x16_U+0, 0
CALL _Int2Double+0, 0
MOVF R0, 0
MOVWF R4
MOVF R1, 0
MOVWF R5
MOVF R2, 0
MOVWF R6
MOVF R3, 0
MOVWF R7
MOVF main_m_L0+0, 0
MOVWF R0
MOVF main_m_L0+1, 0
MOVWF R1
MOVF main_m_L0+2, 0
MOVWF R2
MOVF main_m_L0+3, 0
MOVWF R3
CALL _Sub_32x32_FP+0, 0
CALL _Double2Byte+0, 0
;MyProject.c,97 :: Lcd_Chr_CP(48+ch3);
MOVF R0, 0
ADDLW 48
MOVWF FARG_Lcd_Chr_CP_out_char+0
CALL _Lcd_Chr_CP+0, 0
;MyProject.c,98 :: Lcd_Out_Cp("dBA");
MOVLW ?lstr2_MyProject+0
MOVWF FARG_Lcd_Out_CP_text+0
MOVLW hi_addr(?lstr2_MyProject+0)
MOVWF FARG_Lcd_Out_CP_text+1
CALL _Lcd_Out_CP+0, 0
;MyProject.c,99 :: Delay_ms(1);
MOVLW 3
MOVWF R12, 0
MOVLW 151
MOVWF R13, 0
L_main19:
DECFSZ R13, 1, 1
BRA L_main19
DECFSZ R12, 1, 1
BRA L_main19
NOP
NOP
;MyProject.c,100 :: }
GOTO L_main0
;MyProject.c,102 :: }
L_end_main:
GOTO $+0
; end of _main