HCS08QG8 UART: mix C and Assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08QG8 UART: mix C and Assembly

925 Views
Designer11
Contributor IV

Hello Everyone,

 

I am adding a serial feature to a previous written C codes.  The serial code is in assembly that i obtained from (AN2295SW). I understand that assembly codes in C file don't behave the same as "standard" assembly file. Could anyone give me some suggestions on what i need to modify to get this piece of code up and running. Another question is can i branch to a "regular" C function within the asm brackets ?

 

I am currently using CodeWarrior MCU 6.3

 

asm   {          MOV     0b00001100,SCIC2;   // transmit & receive enable          CLR   SCIBDH;          MOV   #26, SCIBDL;        //BUS (8.0M)/(16 *26) = 19200Bd          CLR     SCIC3;              // clear SCIC3          LDA   SCIS1;              // Load Accumulator A with SCIS1          MOV   #ACK, SCID;         // Move from SCID to ACK          LDX   #T100MS;            // Load Accumulator X with 100ms     L2:   CLRA;    L1:   BRSET   SCIS1_RDRF,SCIS1,CAUGHT; //Branch to "CAUGHT" if SCIIS1_RDRF is           DBNZA   L1; //Decrement A and Branch to "L1" if not Zero          DBNZX   L2; //Decrement X and Branch to "L2" if not Zero    ILOP:    //       timeout          ILOP;       //generate RESET by doing illegal operation    CAUGHT:         // CAUGHT IN SELF-PROGRAMMING?          BSR     READ1;             //Branch to "READ"          CBEQA   #ACK, SUCC;        //Got ACK! or               ILOP;                      //generate RESET by doing illegal operation    SUCC:          LDA     #ACK;              //          BSR     Serial();          //functions that handles serial commands                 READ1:           BRCLR   SCIS1_RDRF,SCIS1,READ1;          LDA   SCID;          RTS;  }

 I get the following error messages after each compiling the codes

 


Error   : C18113: Bitno expected
main.c line 1117  
Error   : C18101: Object is not a field
main.c line 1117  
Error   : C18110: Comma expected
main.c line 1117  
Error   : C18123: end of line expected
main.c line 1117  
Error   : C18125: Invalid opcode or ':' expected
main.c line 1122  
Error   : C18125: Invalid opcode or ':' expected
main.c line 1126  
Error   : C18123: end of line expected
main.c line 1129  
Error   : C18101: Object is not a field
main.c line 1134  
Error   : C18113: Bitno expected
main.c line 1134   
Error   : C18110: Comma expected
main.c line 1134  
Error   : C18110: Comma expected
main.c line 1134  
Error   : C18103: Factor expected
main.c line 1134  
Error   : C18123: end of line expected
main.c line 1134  
Error   : C18101: Object is not a field
main.c line 1135  
Error   : C18123: end of line expected
main.c line 1135  
Error   : C18000: Label not set
main.c line 1134  
Error   : C18000: Label not set
main.c line 1117  
Error   : Compile failed

Labels (1)
0 Kudos
Reply
1 Reply

353 Views
bigmac
Specialist III

Hello,

 

There are a few reasons why your code will not compile without error.

 

Firstly, I assume that you have already defined ACK and T100MS as numeric macros?  How have you defined the macro ILOP, since this is one of the problem areas?  I also notice that you have used ILOP as a label name, as well as a macro name.

 

You are assuming that the macro SCIS1_RDRF represents a bit number.  In fact, the macro identifies a component of a bit field, and is normally used in the context of ... if (SCIS1_RDRF)  {   }   You will presumably need to define your own macro to represent the bit number for the RDRF bit.

 

When a C function is called via inline assembly, the empty parameter braces should not be included.  Additionally, you should call using JSR, rather than BSR, because you do not know the precise location of the C function code.  If the C function requires any parameters, or returns a value, the assembly code would need to take into account the C calling convention for the MCU type.  If this is the case, it is sometimes less error prone to make use of global variables for the passing of values.

 

I assume that your inline code forms part of a separate function?  It must not be placed directly within main() because of the presence of the RTS instruction (and main() must never exit).  Actually, the final RTS is not required because the compiler will automatically provide the RTS when it exits the function.

 

Finally, I would tend to convert all binary numbers to hexadecimal format as it is possible that some compilers will not recognise the binary format.  It is my understanding that ANSI C does not include binary numbers - maybe others can clarify this aspect.

 

Regards,

Mac

 

0 Kudos
Reply