I don't think you are sending a full start bit.  (I haven't worked
with any 8051 in a long time, so I'm not even looking at the
hardware specifics.)

This is my crack at rewriting the ISR.  Instead of using 'rotate'
to rotate the st_char an increasing number of bits each time, just
keep a partially rotated copy in new variable 'st_temp'.

Also, you only need the 16x interrupt rate for receiving.  If you
can cut the rate by 16 on transmit, you could delete 'st_count'
and associated code.

void timer1_isr()  interrupt 3
{
    if (--st_count)             // time to change the bit?
        return;
    st_count = ST_SPEED;
   
    if (st_status == 0)         // send start bit
    {
        TxD1 = 0;
        st_temp = st_char;
    }
    else if (st_status < 9)     // send data bit
    {
        B = st_temp;
        TxD1 = b_0;
        st_temp >>= 1;
    }
    else if (st_status == 9)    // send stop bit
        TxD1 = 1;
    else                        // done
    {
        st_status = 0;
        return;
    }
    st_status++;
}

-Ken Jackson


Ulhas Vaidya writes:
 > hi,
 > 
 > I am trying to implement a second UART on 89C52 by looking at atmel
 > application note no. ANM 055.
 > On a simulator I see the P3.4 (corresponding to TxD) changing properly but
 > nothing gets received by a computer. The connections are fine. I am
 > appending the code below wherein character 'A' is intended to be transmitted
 > continuously.. I shall be thankful for any help / insight.
 > 
 > #define TxD1 P3_4
 > #define RxD1 P3_3
 > 
 > #define ST_SPEED 16
 > 
 >   bit  sr_ready;
 >   bit sr_error;
 >   bit sr_incom;
 > 
 >  unsigned char sr_ch;
 >  unsigned char sr_count;
 >  unsigned char sr_status;
 >  unsigned char sr_char;
 >  unsigned char rotate;
 >  unsigned char st_char;
 >  unsigned char st_count;
 >  unsigned char st_status;
 > 
 > 
 > 
 > void timer1_isr()  interrupt 3
 > {    unsigned char a;
 > 
 > if(!st_status) {TxD1=1; TxD1=0;  st_count=  ST_SPEED; st_status++; return;}
 > //send start bit
 > st_count--; if(st_count!=0) { return;} // time to change the bit?
 > 
 > if(st_status<=8) { a=st_char>>rotate; B=a;TxD1=b_0; st_count=ST_SPEED;
 > rotate++;st_status++; return;}  //send bit
 > else  if (st_status==9){ st_ready=1; TxD1=1; rotate=0; st_count=
 > ST_SPEED;st_status++;return;}   // send stop bit
 > else if(st_status>9) { st_status=0;return;}
 > }
 > 
 > 
 > void main()
 > {  rotate=0;
 >  st_char ='A'; st_count=ST_SPEED; st_status=0;   TCON=0x40; TMOD=0x20;
 > TH1=0xe8; SCON=0x52;
 >  PCON=0;   ET1=1; EA=1;
 > while(1){}
 > }
 > 
 > -- 
 > Ulhas Vaidya
 > Cell No: 098695 74699


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to