I'm trying to get a simple Hello, world LED blinking program
to work, to verify my tool chain and breadboard. Its mostly
working, however it doesn't appear to be honoring the
delays that I'm putting between toggling the LED.
First, the C code:
#ifndef LED_TRIS
#define LED_TRIS TRISB6
#endif
#ifndef LED_PIN
#define LED_PIN RB6
#endif
#include "pic16f687.h"
void delay_ms(long ms)
{
long i;
while (ms--)
for (i=0; i < 330; i++)
;
}
void main()
{
LED_TRIS = 0;
for (;;)
{
LED_PIN = 0;
delay_ms(330);
LED_PIN = 1;
delay_ms(330);
}
}
Here's the first half of the assembly:
...
global STK02
global STK01
global STK00
sharebank udata_ovr 0x0070
...
STK02 res 1
STK01 res 1
STK00 res 1
UDL_helloled_0 udata
r0x1003 res 1
r0x1002 res 1
r0x1001 res 1
r0x1000 res 1
r0x1004 res 1
r0x1005 res 1
r0x1006 res 1
r0x1007 res 1
STARTUP code 0x0000
nop
pagesel __sdcc_gsinit_startup
goto __sdcc_gsinit_startup
_main ;Function start
BANKSEL _TRISB_bits
BCF _TRISB_bits,6
_00117_DS_
; .line 46; "helloled.c" LED_PIN = 0;
BANKSEL _PORTB_bits
BCF _PORTB_bits,6
; .line 47; "helloled.c" delay_ms(330);
MOVLW 0x4a
MOVWF STK02
MOVLW 0x01
MOVWF STK01
MOVLW 0x00
MOVWF STK00
MOVLW 0x00
CALL _delay_ms
; .line 48; "helloled.c" LED_PIN = 1;
BANKSEL _PORTB_bits
BSF _PORTB_bits,6
; .line 49; "helloled.c" delay_ms(330);
MOVLW 0x4a
MOVWF STK02
MOVLW 0x01
MOVWF STK01
MOVLW 0x00
MOVWF STK00
MOVLW 0x00
CALL _delay_ms
GOTO _00117_DS_
RETURN
; exit point of _main
The only funny thing I see here is that, while it does a BANKSEL for
the PORT B register (and later for r1000, ...), it doesn't do it for STK0, ...
I suppose this is because they got mapped to 0xFD, ...
while r1000, ... got put at 0xA0, ...
And here's the code for delay_ms:
_delay_ms ;Function start
; .line 26; "helloled.c" void delay_ms(long ms)
BANKSEL r0x1000
MOVWF r0x1000 ; copy argument to r1000, ... - MSB
MOVF STK00,W
MOVWF r0x1001
MOVF STK01,W
MOVWF r0x1002
MOVF STK02,W
MOVWF r0x1003 ; LSB
_00105_DS_
; .line 30; "helloled.c" while (ms--)
BANKSEL r0x1003
MOVF r0x1003,W ; copy ms since we're doing a post-decrement
MOVWF r0x1004
MOVF r0x1002,W
MOVWF r0x1005
MOVF r0x1001,W
MOVWF r0x1006
MOVF r0x1000,W
MOVWF r0x1007
MOVLW 0xff
ADDWF r0x1003,F ; r1003 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1002,F ; r1002 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1001,F ; r1001 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1000,F ; r1000 += 0xFF
MOVF r0x1004,W ; test old value of ms, W = r1004
IORWF r0x1005,W ; W |= r1005
IORWF r0x1006,W ; W |= r1006
IORWF r0x1007,W ; W |= r1007
BTFSC STATUS,2 ; if zero
GOTO _00111_DS_ ; jump to return
; .line 31; "helloled.c" for (i=0; i < 330; i++)
MOVLW 0x4a
MOVWF r0x1004 ; LSB
MOVLW 0x01
MOVWF r0x1005
CLRF r0x1006
CLRF r0x1007 ; MSB
_00110_DS_
MOVLW 0xff
BANKSEL r0x1004
ADDWF r0x1004,F ; r1004 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1005,F ; r1005 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1006,F ; r1006 += 0xFF
MOVLW 0xff
BTFSS STATUS,0 ; if not carry
ADDWF r0x1007,F ; r1007 += 0xFF
MOVF r0x1004,W ; W = r1004
IORWF r0x1005,W ; W |= r1005
IORWF r0x1006,W ; W |= r1006
IORWF r0x1007,W ; W |= r1007
BTFSS STATUS,2 ; if not zero
GOTO _00110_DS_ ; inner loop
GOTO _00105_DS_ ; outer loop
_00111_DS_
RETURN
I don't see anything strange here. The carry stuff took a little while
to accept was correct, since the behavior looked a little like an
issue with going over 8 bits, but I don't see anything wrong.
Any ideas would be appreciated.
Cheers
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user