I have this problem in two projects both codes are so similar. I have TMR1 interrupt each 100ms and also UART1_Write_Text in some place of code.
Problem is Random reset occur in both project or some time my program halt or do wrong code. At first I wonder that my Micro has some damage or Flash rom is not well ! but by erasing UART functions problem has solved totally!!! Now I think random reset and code error happen when within UART functions interrupt is occur but I need to have both! so i would be happy to hear about solving this problem from you guys.
Code:
Code: Select all
program test
Dim encoder_count,Motor_HZ,old_encoder_count as word
txt as string[5]
sub procedure interrupt
Intcon.7=0
if PIR1.TMR1IF then
timer=timer+1
if encoder_count > old_encoder_count then
Motor_HZ= encoder_count - old_encoder_count
else
Motor_HZ=old_encoder_count - encoder_count
end if
old_encoder_count = encoder_count
TMR1H = 11 TMR1L = 220
clrwdt
PIR1.TMR1IF=0
end if
Intcon.7=1
end sub
main:
OPTION_REG=%11001111
Intcon=%11011000
T1CON=%00110001
TMR1H = 11
TMR1L = 220
PIE1 =%00000001
UART1_INIT(115200)
lop:
wordtostr(PCON,txt)
UART1_Write_Text("PCON="+txt+chr(10)+chr(13))
delay_ms(100)
goto lop