From: SourceForge.net <no...@so...> - 2006-10-16 02:41:23
|
Bugs item #1577882, was opened at 2006-10-15 21:33 Message generated for change (Comment added) made by mcody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1577882&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Mac Cody (mcody) Assigned to: Nobody/Anonymous (nobody) Summary: Partial BANKSEL for PORTA assignment at while(1) loop start Initial Comment: This problems appears to be related to bug report 1570934. Testing was performed on a PIC16F628 using Slackware Linux 10.2 (kernel 2.4.31). The compiler is SDCC 2.6.1 #4409 (Oct 15 2006) (UNIX). The command line for the compile is sdcc -debug -mpic14 -p16f628 SDCC_Test2.c The problem appears to occur when a PORTA assignment occurs at the beginning of a while(1) loop (i.e. endless). The first C code examples compiles and yelds the expected results on the 16F628 (the LED connected to PORTA0 flashes. Note that the PORTA assignment follows the assignment of the variable count1. The compiled assembly follows. Note that the bcf command is used to clear both bits 5 and 6 of the STATUS register. The second C code example has the PORTA assignment immediately following the head of the while(1) loop. While the code compiles, the code running on the PIC16F628 only flashes once. Note that the bcf command is used to only clear bit 5. Bit 6 is cleared as part of the TRISA code outside of the while(1) loop. The TRISA code at the beginning of the program causes PORTA0 pin to become an output and the PORTA0 bit is already 0 due to system reset. This causes the LED to light. Latter on in the program, PORTA0 is set to 1, which turns the LED off. It appears that the BANKSEL associated with second "count--" performs a bsf for STATUS bit 6, which is not cleared when the branch goes back to the beginning of the while loop. I don't have a patch to fix the problem, but I think I tracked down the cause of the problem. **** START FIRST C CODE EXAMPLE **** #define __16f628 #include "pic/pic16f628.h" // Set the __CONFIG word: typedef unsigned int word; word at 0x2007 __CONFIG = 0x3D90; #pragma nogcse void main(void) { unsigned short count1; TRISA = 0; while(1) { count1 = 0x7fff; PORTA = 0; while(count1 != 0) { count1--; } PORTA = 1; count1 = 0x7fff; while(count1 != 0) { count1--; } } } **** END FIRST C CODE EXAMPLE **** **** START FIRST ASSEMBLY CODE EXAMPLE **** **** NOTE: LEADING ASSEMBLY DEFINITIONS LEFT OFF **** _main ;Function start ; 2 exit points ; .line 12; "SDCC_Test2.c" TRISA = 0; BSF STATUS,5 BCF STATUS,6 CLRF _TRISA _00112_DS_ ; .line 14; "SDCC_Test2.c" count1 = 0x7fff; MOVLW 0xff BANKSEL r0x1002 MOVWF r0x1002 BANKSEL r0x1000 MOVWF r0x1000 MOVLW 0x7f BANKSEL r0x1003 MOVWF r0x1003 BANKSEL r0x1001 MOVWF r0x1001 ; .line 15; "SDCC_Test2.c" PORTA = 0; BCF STATUS,5 <== Bit 5 cleared BCF STATUS,6 <== Bit 6 cleared CLRF _PORTA ;;99 MOVF r0x1000,W ;;100 MOVF r0x1001,W _00105_DS_ ; .line 16; "SDCC_Test2.c" while(count1 != 0) { BANKSEL r0x1002 MOVF r0x1002,W ;; peep 1 - test/jump to test/skip ; .line 17; "SDCC_Test2.c" count1--; BANKSEL r0x1003 IORWF r0x1003,W BTFSC STATUS,2 GOTO _00107_DS_ MOVLW 0xff BANKSEL r0x1002 ADDWF r0x1002,F BTFSC STATUS,0 GOTO _00001_DS_ BANKSEL r0x1003 DECF r0x1003,F _00001_DS_ GOTO _00105_DS_ _00107_DS_ ; .line 19; "SDCC_Test2.c" PORTA = 1; MOVLW 0x01 BCF STATUS,5 BCF STATUS,6 MOVWF _PORTA ; .line 20; "SDCC_Test2.c" count1 = 0x7fff; MOVLW 0xff BANKSEL r0x1000 MOVWF r0x1000 MOVLW 0x7f BANKSEL r0x1001 MOVWF r0x1001 _00108_DS_ ; .line 21; "SDCC_Test2.c" while(count1 != 0) { BANKSEL r0x1000 MOVF r0x1000,W ;; peep 1 - test/jump to test/skip ; .line 22; "SDCC_Test2.c" count1--; BANKSEL r0x1001 IORWF r0x1001,W BTFSC STATUS,2 GOTO _00112_DS_ MOVLW 0xff BANKSEL r0x1000 ADDWF r0x1000,F BTFSC STATUS,0 GOTO _00002_DS_ BANKSEL r0x1001 DECF r0x1001,F _00002_DS_ GOTO _00108_DS_ RETURN ; exit point of _main ; code size estimation: ; 41+ 14 = 55 instructions ( 138 byte) end **** END FIRST ASSEMBLY CODE EXAMPLE **** **** START SECOND C CODE EXAMPLE **** #include "pic/pic16f628.h" // Set the __CONFIG word: typedef unsigned int word; word at 0x2007 __CONFIG = 0x3D90; #pragma nogcse void main(void) { unsigned short count1; TRISA = 0; while(1) { PORTA = 0; count1 = 0x7fff; while(count1 != 0) { count1--; } PORTA = 1; count1 = 0x7fff; while(count1 != 0) { count1--; } } } **** END SECOND C CODE EXAMPLE **** **** START SECOND ASSEMBLY CODE EXAMPLE **** **** NOTE: LEADING ASSEMBLY DEFINITIONS LEFT OFF **** _main ;Function start ; 2 exit points ; .line 12; "SDCC_Test2.c" TRISA = 0; BSF STATUS,5 BCF STATUS,6 CLRF _TRISA _00112_DS_ ; .line 14; "SDCC_Test2.c" PORTA = 0; BCF STATUS,5 <== Only bit 5 cleared CLRF _PORTA ; .line 15; "SDCC_Test2.c" count1 = 0x7fff; MOVLW 0xff BANKSEL r0x1002 MOVWF r0x1002 BANKSEL r0x1000 MOVWF r0x1000 MOVLW 0x7f BANKSEL r0x1003 MOVWF r0x1003 BANKSEL r0x1001 MOVWF r0x1001 ;;99 MOVF r0x1000,W ;;100 MOVF r0x1001,W _00105_DS_ ; .line 16; "SDCC_Test2.c" while(count1 != 0) { BANKSEL r0x1002 MOVF r0x1002,W ;; peep 1 - test/jump to test/skip ; .line 17; "SDCC_Test2.c" count1--; BANKSEL r0x1003 IORWF r0x1003,W BTFSC STATUS,2 GOTO _00107_DS_ MOVLW 0xff BANKSEL r0x1002 ADDWF r0x1002,F BTFSC STATUS,0 GOTO _00001_DS_ BANKSEL r0x1003 DECF r0x1003,F _00001_DS_ GOTO _00105_DS_ _00107_DS_ ; .line 19; "SDCC_Test2.c" PORTA = 1; MOVLW 0x01 BCF STATUS,5 BCF STATUS,6 MOVWF _PORTA ; .line 20; "SDCC_Test2.c" count1 = 0x7fff; MOVLW 0xff BANKSEL r0x1000 MOVWF r0x1000 MOVLW 0x7f BANKSEL r0x1001 MOVWF r0x1001 _00108_DS_ ; .line 21; "SDCC_Test2.c" while(count1 != 0) { BANKSEL r0x1000 MOVF r0x1000,W ;; peep 1 - test/jump to test/skip ; .line 22; "SDCC_Test2.c" count1--; BANKSEL r0x1001 IORWF r0x1001,W BTFSC STATUS,2 GOTO _00112_DS_ MOVLW 0xff BANKSEL r0x1000 <== bcf STATUS,5; bsf STATUS,6 ADDWF r0x1000,F BTFSC STATUS,0 GOTO _00002_DS_ BANKSEL r0x1001 DECF r0x1001,F _00002_DS_ GOTO _00108_DS_ RETURN ; exit point of _main ; code size estimation: ; 40+ 14 = 54 instructions ( 136 byte) end **** END SECOND ASSEMBLY CODE EXAMPLE **** ---------------------------------------------------------------------- >Comment By: Mac Cody (mcody) Date: 2006-10-15 21:41 Message: Logged In: YES user_id=497809 Note: I labeled the wrong BANKSEL on the second assembly example. It should be the line "BANKSEL r0x1001" three lines prior to "GOTO _00112_DS". ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1577882&group_id=599 |