#565 PIC 14 Case-Select

closed-fixed
nobody
5
2014-08-18
2003-08-11
Anonymous
No

Version: Aug 4 2003 [MINGW32] running on Windows 98
SE 2.

Command Line:
C:\sdcc\bin\sdcc.exe -S -mpic14 -p16f877 test.c

From: David Brainerd brainerd@camasnet.com

If I set up the Switch - Case statements as shown
below, when ReceivePacketAddress = 'V' the case 'S' is
executed rather than the 'V' case. If I move the
case 'V' section in front of the case 'S' section the code
functions as indended. I attached the relevent section
of the .asm file generated by SDCC. Note that I run this
under Windows 98 SE.

//-----< Include Files >-----
#include "p16f877.h"

//-----< General Program Defines >-----
#define FALSE 0
#define TRUE 1

char RX_Packet_Ready; // TRUE If a receive packet
is ready
unsigned char TransmitPacketIdentifier;
unsigned char ReceivePacketAddress;

unsigned char getc(void)
{
while (RCIF == 0); //wait until character available
return(RCREG);
}

void putc(unsigned char c)
{
while (TXIF == 0); //wait until xmit register is clear
TXREG = c; //load character into transmit register
return;
}

//-----< Transmit a packet >---------------------------
---------------
void send_packet(void)
{
// Just send the packet out, one byte at a time
putc(TransmitPacketIdentifier);
}

void rs232_isr(void) interrupt 0
{

if(RCIF) { // serial received

ReceivePacketAddress = getc();
RX_Packet_Ready = TRUE;
// putc(ReceivePacketAddress); //echo back for
diagnostic only
// print_hex(ReceivePacketAddress);
}
}

void test(void)
{
_asm
nop
_endasm;
}

void decode_rs232(void)
{
RX_Packet_Ready = FALSE;

switch(ReceivePacketAddress)
{
case 'S':
{

TransmitPacketIdentifier = 'S';
break;
}
case 'V':
{
TransmitPacketIdentifier = 'V';
break;
}
case '?':
{
TransmitPacketIdentifier = 0xFF; // 255 (0xff) -
Always 255
break;
}

}
}
//=====< Main
>=========================================
=============
void main(void)
{

NOT_RBPU=0;
// Configure UART serial transmit

SPBRG = 32; // 10MHz => 19200 baud
BRGH = 1; // High Baud Rate mode
SYNC = 0; //Asynchronous Mode
SPEN = 1;
RCIE = 1;
CREN = 1;
TXEN = 1;//enable RS232 xmit

GIE = 1; //General Interrupt Enable
PEIE = 1;

ADCON1 = 7; //set all digital inputs

//----- Initialize global variables
RX_Packet_Ready = FALSE;

//----- Main loop -----
test();
// puts("This is the start of the main loop");
while(1)
{

// Just sit here cooling our jets
if( RX_Packet_Ready == TRUE) //decode_rs232();
{
decode_rs232();
}

} // End of main loop

} //----- End of main -----

; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.3.5 Thu Jul 17 22:26:46 2003

;#CSRC C:/sdcc/PIC/testswitch.c 63
; switch(ReceivePacketAddress)
MOVF _ReceivePacketAddress,W
XORLW 0x3f
BTFSC STATUS,2
GOTO _00132_DS_
MOVF _ReceivePacketAddress,W
XORLW 0x53
BTFSC STATUS,2
GOTO _00130_DS_
MOVF _ReceivePacketAddress,W
;; peep 1 - test/jump to test/skip
XORLW 0x56
BTFSS STATUS,2
GOTO _00134_DS_
_00130_DS_
MOVLW 0x53
MOVWF _TransmitPacketIdentifier
;#CSRC C:/sdcc/PIC/testswitch.c 69
; break;
GOTO _00134_DS_
;#CSRC C:/sdcc/PIC/testswitch.c 73
; TransmitPacketIdentifier = 'V';
MOVLW 0x56
MOVWF _TransmitPacketIdentifier
;#CSRC C:/sdcc/PIC/testswitch.c 74
; break;
GOTO _00134_DS_
_00132_DS_
;#CSRC C:/sdcc/PIC/testswitch.c 78
; TransmitPacketIdentifier = 0xFF; // 255 (0xff) -
Always 255
MOVLW 0xff
MOVWF _TransmitPacketIdentifier
_00134_DS_
GOTO _00142_DS_
RETURN
; exit point of _main

Discussion

  • Raphael Neider
    Raphael Neider
    2005-07-22

    • status: open --> closed
     
  • Raphael Neider
    Raphael Neider
    2005-07-22

    Logged In: YES
    user_id=1115835

    Fixed in SDCC 2.5.1 #1064 (probably already before that).

     
  • Raphael Neider
    Raphael Neider
    2005-07-22

    • milestone: --> fixed
    • status: closed --> closed-fixed