16F877 problem

Started by Gokce Mehmet AY June 28, 2004
I use a simple startup routine, where a command is
send via RS232 to start the
firmware. I simulated my code in ISIS 5.2 and MPLAB
SIM packed with MPLAB IDE
6.2 and it seems that there is no problem. However
when I write the code to PIC
it just don't work. Program does not wait for RS232.
It seems that Interrupts
are not disabled but how this can be, I don't know.

Thanks
Gokce

Parts of my code is below

Configuration bits: 3D31

org 0x00 ;Init. Code
goto init
org 0x04 ;interrupts
goto IntSub

init
movlw d'6' ;
movwf TMR0 ;For 1msec interrupt
bsf STATUS,5 ;Bank1
movlw 0xCF
movwf TRISA ;PortA input
movlw b'01000001' ;datasheet page 50
movwf OPTION_REG ;activate Timer0 as 1:1 timer
movlw b'10100000' ;Timer0 overflow interrupt
movwf INTCON ;interrupt reg.
movlw 0xFF
movwf TRISB ;PortB input
movlw 0xCF
movwf TRISA ;PortA input
clrf TRISD ;PORTD output
movlw 0xFF
movwf TRISC ;PORTC,0 input (Counter1)
movlw b'10000100' ;/RA1(AN1),RA0(AN0), RA3 (AN3)
are \
movwf ADCON1 ;\analog inputs /
bcf STATUS,5
clrf TMR1H ;Clear contents of TMR1H
clrf TMR1L ;Clear contents of TMR1L
movlw b'00000111' ;Set counter F877 datasheet Pg:51
movwf T1CON
;***PWM Prepare
bsf STATUS,RP0
movlw h'FF' ; when TMR2 = 249 = end of Period
for BOTH PWM Signals
movwf PR2
bcf STATUS,RP0
;***PWM READY
movlw d'10'
movwf VCount

;RS232 Init
movlw d'12' ;Baud rate 19.2K
bsf STATUS,5 ;Bank1
movwf SPBRG ;/
bsf TXSTA,2 ;\
bcf TXSTA,4 ;/Enable Assyn. Serial Port
; bsf PIE1,4 ;Interrupt Enabled for Transmit
(PIR1,4 will be Interrupt)
bsf PIE1,5 ;Interrupt Enabled for Receive
(PIR1,5 will be Interrupt)
bsf TXSTA,5 ;Enable transmission
bcf STATUS,5
bsf RCSTA,7 ;\Enable Assyn Ser. port
bsf RCSTA,4 ;Enable receive

movlw d'34' ;
movwf SendData ;

movlw 0xE1
movwf TCount
clrf ComCh
clrf DelPL
clrf DelPH
goto start WaitCom ;Wait until rec. 0x22 '"' from computer
bsf STATUS,5
bcf INTCON,7 ;disable Global Int
bcf STATUS,5
movlw 0x23 ;'#'
call putc ;
call getc ;Check whether there exists command
movwf RecDataL ;
movlw 0x22 ;
subwf RecDataL,W ;
btfsc STATUS,2 ;Check for Zero if zero goto next
step
goto EndWait
movlw 0x21 ; '!'
call putc ;
goto WaitCom
EndWait
bsf STATUS,5
bsf INTCON,5 ;clear Tmr0 Int
bsf INTCON,7 ;enable Global Int
bcf INTCON,6 ;disable Per. Int.
bcf PIE1,5 ;disable rec. Int.
bcf STATUS,5 ;Bank0
bsf Temp,4 ;Don't enter RecCom
movlw d'6'
movwf TMR0
goto start2 start
btfss Temp,4
goto WaitCom
start2
bsf STATUS,5
bsf INTCON,7 ;enable Global Int
bcf STATUS,5 ;Bank0

btfsc Temp,3
goto SendErr
goto start
__________________________________



There is a problem disabling global interrupts
discussed in this app note
http://ww1.microchip.com/downloads/en/AppNotes/00576b.pdf

Basically interrupts could be reenabled at the end of
the interrupt service routine if there is an interrupt
while you disable it.

The following piece of code prevents this

LOOP BCF INTCON, GIE ; Disable Global Interrupt
BTFSC INTCON, GIE ; Global Interrupt Disabled?
GOTO LOOP ; NO, try again

could this be the problem? Peter

--- Gokce Mehmet AY <> wrote:
> I use a simple startup routine, where a command is
> send via RS232 to start the
> firmware. I simulated my code in ISIS 5.2 and MPLAB
> SIM packed with MPLAB IDE
> 6.2 and it seems that there is no problem. However
> when I write the code to PIC
> it just don't work. Program does not wait for RS232.
> It seems that Interrupts
> are not disabled but how this can be, I don't know.
>
> Thanks
> Gokce
>
> Parts of my code is below
>
> Configuration bits: 3D31
>
> org 0x00 ;Init. Code
> goto init
> org 0x04 ;interrupts
> goto IntSub
>
> init
> movlw d'6' ;
> movwf TMR0 ;For 1msec interrupt
> bsf STATUS,5 ;Bank1
> movlw 0xCF
> movwf TRISA ;PortA input
> movlw b'01000001' ;datasheet page 50
> movwf OPTION_REG ;activate Timer0 as 1:1 timer
> movlw b'10100000' ;Timer0 overflow interrupt
> movwf INTCON ;interrupt reg.
> movlw 0xFF
> movwf TRISB ;PortB input
> movlw 0xCF
> movwf TRISA ;PortA input
> clrf TRISD ;PORTD output
> movlw 0xFF
> movwf TRISC ;PORTC,0 input (Counter1)
> movlw b'10000100' ;/RA1(AN1),RA0(AN0), RA3 (AN3)
> are \
> movwf ADCON1 ;\analog inputs /
> bcf STATUS,5
> clrf TMR1H ;Clear contents of TMR1H
> clrf TMR1L ;Clear contents of TMR1L
> movlw b'00000111' ;Set counter F877 datasheet
> Pg:51
> movwf T1CON
> ;***PWM Prepare
> bsf STATUS,RP0
> movlw h'FF' ; when TMR2 = 249 = end of Period
> for BOTH PWM Signals
> movwf PR2
> bcf STATUS,RP0
> ;***PWM READY
> movlw d'10'
> movwf VCount
>
> ;RS232 Init
> movlw d'12' ;Baud rate 19.2K
> bsf STATUS,5 ;Bank1
> movwf SPBRG ;/
> bsf TXSTA,2 ;\
> bcf TXSTA,4 ;/Enable Assyn. Serial Port
> ; bsf PIE1,4 ;Interrupt Enabled for Transmit
> (PIR1,4 will be Interrupt)
> bsf PIE1,5 ;Interrupt Enabled for Receive
> (PIR1,5 will be Interrupt)
> bsf TXSTA,5 ;Enable transmission
> bcf STATUS,5
> bsf RCSTA,7 ;\Enable Assyn Ser. port
> bsf RCSTA,4 ;Enable receive
>
> movlw d'34' ;
> movwf SendData ;
>
> movlw 0xE1
> movwf TCount
> clrf ComCh
> clrf DelPL
> clrf DelPH
> goto start > WaitCom ;Wait until rec. 0x22 '"' from
> computer
> bsf STATUS,5
> bcf INTCON,7 ;disable Global Int
> bcf STATUS,5
> movlw 0x23 ;'#'
> call putc ;
> call getc ;Check whether there exists command
> movwf RecDataL ;
> movlw 0x22 ;
> subwf RecDataL,W ;
> btfsc STATUS,2 ;Check for Zero if zero goto next
> step
> goto EndWait
> movlw 0x21 ; '!'
> call putc ;
> goto WaitCom
> EndWait
> bsf STATUS,5
> bsf INTCON,5 ;clear Tmr0 Int
> bsf INTCON,7 ;enable Global Int
> bcf INTCON,6 ;disable Per. Int.
> bcf PIE1,5 ;disable rec. Int.
> bcf STATUS,5 ;Bank0
> bsf Temp,4 ;Don't enter RecCom
> movlw d'6'
> movwf TMR0
> goto start2 > start
> btfss Temp,4
> goto WaitCom
> start2
> bsf STATUS,5
> bsf INTCON,7 ;enable Global Int
> bcf STATUS,5 ;Bank0
>
> btfsc Temp,3
> goto SendErr
> goto start >
> __________________________________

__________________________________





Hi!
During my assignment on PIC16f877,i've encountered that my
program keep on reseting. After moving some of the subroutine to
program memory page 1, the problem was solved. When i check my
program, it's only H'0168' which is still within the memory page 0.
Has anyone encountered this problem before? What's the root cause?
Thnaks! Regards,

bryan




You probably forgot to set the program memory to the page you want to be in after the return or retlw instruction.  Make sure the wdt is not timing out.

 

Martin

 

From: quanbot [mailto:q...@yahoo.com]
Sent: Monday, 4 October 2004 3:20
To: p...@yahoogroups.com
Subject: [piclist] 16F877 problem

 



Hi!
   During my assignment on PIC16f877,i've encountered that my
program keep on reseting. After moving some of the subroutine to
program memory page 1, the problem was solved. When i check my
program, it's only H'0168' which is still within the memory page 0.
Has anyone encountered this problem before? What's the root cause?
Thnaks! Regards,

bryan


to unsubscribe, go to http://www.yahoogroups.com and follow the instructions