这个程序为什么返回数据总是0?
#include "compiler_defs.h" #include "c8051f930_defs.h" #include "stddef.h" #include "stdio.h" #define SYSCLK 24500000 // SYSCLK frequency in Hz #define BAUDRATE 9600 // Baud rate of UART in bps 115200 unsigned char RXD; unsigned char TXD; //unsigned char i; SBIT (t,SFR_P2,3); //接收使能 void Timer_Init(void); void UART_Init(void); void Port_IO_Init(void); void Oscillator_Init(void); void Interrupts_Init(void); void Init_Device(void); void TXD_SUB(void); void RXD_SUB(void); void UART_ISR(void); void main(void) { PCA0MD &= ~0x40; // 关闭看门狗 Init_Device(); while (1) { } } //波特率为7500 void Timer_Init() { TCON = 0x50; TMOD = 0x20; CKCON = 0x01; if (SYSCLK/BAUDRATE/2/256 < 1) {TH1 = -(SYSCLK/BAUDRATE/2); CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx CKCON |= 0x08; } else if (SYSCLK/BAUDRATE/2/256 < 4) {TH1 = -(SYSCLK/BAUDRATE/2/4); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01 CKCON |= 0x01; } else if (SYSCLK/BAUDRATE/2/256 < 12) {TH1 = -(SYSCLK/BAUDRATE/2/12); CKCON &= ~0x0B; } // T1M = 0; SCA1:0 = 00 else {TH1 = -(SYSCLK/BAUDRATE/2/48); CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10 CKCON |= 0x02; } TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload TMOD |= 0x20; TR1 = 1; // START Timer1 TI0 = 1; } void UART_Init() { EA=1; SCON0 = 0x10; } void Port_IO_Init() { // UART TX P0MDOUT |= 0x10; // Set TX pin to push-pull XBR0 = 0x01; XBR2 = 0x40; } void Oscillator_Init() { OSCICN = 0x82; } //允许中断,允许串口中断; void Interrupts_Init() { IE = 0x90; } // Initialization function for device, // Call Init_Device() from your main program void Init_Device(void) { Timer_Init(); UART_Init(); Port_IO_Init(); Oscillator_Init(); Interrupts_Init(); t=0; } //串口中断子程序 //此处的延时是对串口接受的响应延时,不可改变 void UART_ISR(void) interrupt 4 { IE =0x00; //禁止中断 RI0=0; TXD=SBUF0; TXD_SUB(); if (TI0==1) { TI0=0; RI0=0; IE=0x90; } } //串口发送一个字节子程序 //此处的延时涉及到89C52的接受,不可改变 void TXD_SUB() { IE =0x00; //禁止中断 t=1; SBUF0=7; while(!TI0); //等待发送结束 TI0 = 0; //发送结束标志清零 t=0; IE=0x90; } 本文来自电子工程师之家:http://www.eehome.cn/read.php?tid=45865
|