This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf doesn't work !

I don't know why, I would like to implement a printf function in my C program for my T89C51CC01. When I run the debugger, my program stop during the execution of the printf function.

The manual say that printf use the putchar function. OK. I try to take a look on the disassembly windows, and the program stop just when it tries to send the first character of my string.

This is a sample of my program:

void main(void)
{
while(1)
{
// Fonctionnement normal

// Mode de configuration
modeConfig = 1;
init_mode_config();
TR0 = 1;
while(modeConfig == 1)
{
switch(niveauMenu)
{
// Attente des caractères CR,CR pour activer le menu
case 0x00:	if(flgDataRecu)		// Test si le mode config a bien été demandé ?
							{					// Attente de 2 CR
								flgDataRecu = 0;

								if(cara_recu == CR)
								{
									temps = 0;
									if(flgDemandeMenu == 1)
									{
										TR0 = 0;
										niveauMenu = 0x01;
									}
									else
										flgDemandeMenu = 1;
								}
								else
								{
									if(flgDemandeMenu == 1)
										flgDemandeMenu = 0;
									// Mauvais caractère !
								}
							}
							break;

				// Menu principal
				case 0x01:	printf("\n---------- STDI ----------", table_divers[1], "\n\n"); //
							printf("A - Vitesse de Transmission serie\n");
							printf("B - Format des Donnees\n");

Parents
  • Hi Mark, thanks for your help!
    (I'm agree with you about the indenting but my copy and paste do that)
    the

     table_divers[1] 
    is another string, so i can accumulate it in my printf.

    It seems to me that my problem is essentially hardware! I do many investigation and i find a really strange solution!!! See what i need to do to execute my printf function:
    void main(void)
    {
    while(1)
    {
    // Fonctionnement normal
    
    // Mode de configuration
    modeConfig = 1;
    init_mode_config();
    TR0 = 1;
    while(modeConfig == 1)
    {
    switch(niveauMenu)
    {
    // Attente des caractères CR,CR pour activer le menu
    case 0x00:
    .
    .
    .
    break;
    // Menu principal
    case 0x01:
    ES = 0;
    TI = 1;
    printf("\n---------- STDI ----------", table_divers[1], "\n\n");
    printf("A - Vitesse de Transmission serie\n");
    printf("B - Format des Donnees\n");
    .
    .
    .
    .
    
    After disable the serial interruption and set the TI flag, all printf execute correctly !!!! That's really strange !!!!

    sorry for the double post.

Reply
  • Hi Mark, thanks for your help!
    (I'm agree with you about the indenting but my copy and paste do that)
    the

     table_divers[1] 
    is another string, so i can accumulate it in my printf.

    It seems to me that my problem is essentially hardware! I do many investigation and i find a really strange solution!!! See what i need to do to execute my printf function:
    void main(void)
    {
    while(1)
    {
    // Fonctionnement normal
    
    // Mode de configuration
    modeConfig = 1;
    init_mode_config();
    TR0 = 1;
    while(modeConfig == 1)
    {
    switch(niveauMenu)
    {
    // Attente des caractères CR,CR pour activer le menu
    case 0x00:
    .
    .
    .
    break;
    // Menu principal
    case 0x01:
    ES = 0;
    TI = 1;
    printf("\n---------- STDI ----------", table_divers[1], "\n\n");
    printf("A - Vitesse de Transmission serie\n");
    printf("B - Format des Donnees\n");
    .
    .
    .
    .
    
    After disable the serial interruption and set the TI flag, all printf execute correctly !!!! That's really strange !!!!

    sorry for the double post.

Children
No data