单片机/MCU论坛
直播中

longxiongliang

11年用户 29经验值
私信 关注
[文章]

c8051f060 使用定时器1溢出作为波特率的问题

这次要做个调试板,接手别人的程序。他使用定时器1的溢出作为串口的波特率。在新华龙的例程里没有写time1的中断处理函数。
但我在使用中发现。要是不写time1的中断处理函数就没法进 UART0的中断也就是没法通信
程序如下:
void UART0_Init(void)
{
        unsigned char temp = SFRPAGE;                // Save current SFR page
        SFRPAGE = UART0_PAGE;
       
        SCON0 = 0x50;                                                // 8-Bit UART,variable baud rate.
                                                                                // Receive Enable.

        SSTA0 = 0x00;                                                // Timer1 Overflow generates UART0 TX and
                                                                                // RX baud rate.
                                                                               
        SFRPAGE = TIMER01_PAGE;
       
        TMOD = 0x20;                                                // Timer1 enabled,Timer is in Auto-Reload Mode.       
        CKCON = 0x00;                                                // Timer1 clock = SYSCLK/12. 22118400/12/19200=96       
   TH1 = 0xA0;                                                        // Baud rate = 19200.  TH1=256-96=160
   TL1 = 0xA0;                   //TL0 must be initialized to desired value before
                                 //enable the timer for the first count
        TCON = 0x40;                                                // Timer1 run.

   ET1=1;                         // ENable the interrupt ( ie)
   ES0=1;                        // enable the seria0 (ie)

                                                                                     
        SFRPAGE = temp;                                                   // Restore SFR page.               
}

写得中断处理函数如下:
void Timer1_ISR_handle(void) interrupt 3
{
}//空函数

有人知道原因?

回帖(1)

longxiongliang

2012-8-18 11:31:41
补充下:在计算波特率时 还要除以32
  1. THD=0xFD;
  2. THL=0xFD;
不过也不行
举报

更多回帖

发帖
×
20
完善资料,
赚取积分