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

serial port and timer

Hi,

I have a problem.I must send through the serial port the number 1 and the number 0 every second using a timer of the c167cs. Would someone know me to help?

Parents
  • The have inserted to "if" in such way to make me stamp, alternatively, "0" and "1" to distance of to second. The tails is the following:

    #include "c167cs.h"
    #include "intrins.h"
    
    int a;
    a=0;
    
    void GPT1_viTmr3(void) interrupt 0x23 {
    
      if(a=0)
         {S0TBUF = '0';
          a=1;}
      else
         {S0TBUF = '1';
          a=0;}
    
      P2 ^= 0x0001;  /* toggle P2.0 */
    }
    
    void main(void) {
      /* setup the serial port */
      S0BG  = 0x0040; /* 9.600 kbaud @ 20 MHz clock */
      S0CON = 0x0011; /* format: 8-N-1 */
    
      /* P3.10 is used for TxD and P3.11 is used for RxD */
      _bfld_( P3,0x0C00,0x0400);    /**/
      _bfld_(DP3,0x0C00,0x0400);    /* set data direction */
    
      S0CON |= 0x8000; /* enable baud rate */
    
      /* use GPT1 for the 1 second time base */
      T3CON = 0x0087;  /* clock tick is 51.2 usec, count down */
      T3    = 0x4C4B;  /* 1 second load value */
    
      T2CON = 0x0027;  /* t2 reloads T3 on the interrupt */
      T2    = 0x4C4B;
    
      T3IC  = 0x004B;  /* set up the interrupt level and enable it */
      T3R   = 1;       /* start timer 3 running */
    
      DP2   = 1;       /* toggle P2.0 every second */
    
      IEN   = 1;       /* globally enable interrupts */
    
      for(;;){};
    }
    

    The problem is that it stamps only me "1" every second. would someone know me to explain because? Thanks so much.

Reply
  • The have inserted to "if" in such way to make me stamp, alternatively, "0" and "1" to distance of to second. The tails is the following:

    #include "c167cs.h"
    #include "intrins.h"
    
    int a;
    a=0;
    
    void GPT1_viTmr3(void) interrupt 0x23 {
    
      if(a=0)
         {S0TBUF = '0';
          a=1;}
      else
         {S0TBUF = '1';
          a=0;}
    
      P2 ^= 0x0001;  /* toggle P2.0 */
    }
    
    void main(void) {
      /* setup the serial port */
      S0BG  = 0x0040; /* 9.600 kbaud @ 20 MHz clock */
      S0CON = 0x0011; /* format: 8-N-1 */
    
      /* P3.10 is used for TxD and P3.11 is used for RxD */
      _bfld_( P3,0x0C00,0x0400);    /**/
      _bfld_(DP3,0x0C00,0x0400);    /* set data direction */
    
      S0CON |= 0x8000; /* enable baud rate */
    
      /* use GPT1 for the 1 second time base */
      T3CON = 0x0087;  /* clock tick is 51.2 usec, count down */
      T3    = 0x4C4B;  /* 1 second load value */
    
      T2CON = 0x0027;  /* t2 reloads T3 on the interrupt */
      T2    = 0x4C4B;
    
      T3IC  = 0x004B;  /* set up the interrupt level and enable it */
      T3R   = 1;       /* start timer 3 running */
    
      DP2   = 1;       /* toggle P2.0 every second */
    
      IEN   = 1;       /* globally enable interrupts */
    
      for(;;){};
    }
    

    The problem is that it stamps only me "1" every second. would someone know me to explain because? Thanks so much.

Children