PDA

View Full Version : MCU seset and stop



Sabahan
- 29th January 2017, 09:55
I'm not sure why this happened,I. using PIC16F1828 DIP version MCU,without the LCD code,the MCU works fine,after adding the LCD code in,which I copy from my other project using PIC16F877A,the MCU keep reset itset,after few reset there are nothing happed to the MCU,the oscillation is still running,below are the code

#CONFIG
__config _CONFIG1, _FOSC_HS
#ENDCONFIG
Define LOADER_USED 1
Define OSC 20
TRISC.0 = 0
i var word
for i = 1 to 10
PORTC.0 = 1
pause 500
PORTC.0 = 0
pause 200
next i

DEFINE LCD_DREG PORTB ' Set LCD Data Port
DEFINE LCD_DBIT 4 ' Set Starting Data Bit(0 or 4) if 4-bit bus
define LCD_RSREG PORTC ' Set LCD Register Select Port
define LCD_RSBIT 6 ' Set LCD Register Bus
define LCD_EREG PORTC
define LCD_EBIT 3 ' Set LCD Enable Port
define LCD_Bits 4 ' Set LCD Bus size(4 or 8 Bits)
define LCD_LINES 2 ' Set Number of lines on LCD
define LCD_COMMANDUS 1500 ' Set Command delat time in us
define LCD_DATAUS 44 ' Set data delay time in us
wind_speed var word
wind_speed = 2345
pause 500
mainloop:
PORTC.0 = 1
lcdout $fe,1,dec(wind_speed)
pause 2000
PORTC.0 = 0
lcdout $fe,1,"Wait "
pause 1000
goto mainloop
end






the first for..next loop is to test weather the MCU is running or not,is the LCD code is disable,it can run to the low part of the code,but once the LCD code is enable,it will reset itself a few times than stop operating,but the oscillator is still running normally

Charlie
- 29th January 2017, 14:49
Are you sure all your code is here? There is no "for... next loop" in what you posted.

Scampy
- 29th January 2017, 16:08
I think Charlie is right, but the code does seem to read correctly to a degree, but I think the resetting may because the config is only setting the speed of the processor, no other options have been set which to me might be the cause as to the resetting of the PIC. But then I use PBP 2.60c and this config statement looks different so I guessing the OP is using PBP3, so maybe this thread needs moving to the correct section ?

Also I have to ask



i var word
for i = 1 to 10
PORTC.0 = 1
pause 500
PORTC.0 = 0
pause 200
next i


Why use a word variable for i when it's only running 10 cycles of the for next loop. Defining it as a byte would be fine

Dave
- 29th January 2017, 22:01
What resistance are you using for the reset line? Also is the power supply solid?

richard
- 29th January 2017, 22:06
not to mention

define LCD_Bits 4 ' Set LCD Bus size(4 or 8 Bits)

define LCD_BITS 4 ' Set LCD Bus size(4 or 8 Bits)

Sabahan
- 1st February 2017, 08:24
I figure out the problem,the PIC16F1828 port a,b and C are all analog pin,which need to set it to digital before the LCD sequence