printf 函数在keil2 中的使用

来源:互联网 发布:大数据行业股票 编辑:程序博客网 时间:2024/05/18 02:22
/****************************************************************************/
/*                                                                          */
/*       SERIAL.C:  Interrupt Controlled Serial Interface                   */
/*                                                                          */
/****************************************************************************/
//采用中断接收串口数据
//发送数据到串口可使用<stdio.h>定义的函数
//有疑义可访问bbs.21ic.com进行讨论。
//测试:古道热肠
//#include <reg52.h>
#include "STC_NEW_8051.H"
#include <stdio.h>
volatile unsigned char UartIsSending;


char putchar (char ucWriteData)
{
SBUF=ucWriteData;
UartIsSending=1;
while(UartIsSending);
return (ucWriteData);
}


volatile unsigned char UartIsSending;
void UartIsr(void) interrupt 4
{
if(TI) //发送中断
{
    UartIsSending=0;
    TI=0;
}
if(RI) //接收中断
{
  RI=0;
}
}
/****************************************************************************/
/*       serial_init: initialize serial interface                           */
/****************************************************************************/
serial_init ()  
{
  SCON  = 0x50;                      /* mode 1: 8-bit UART, enable receiver */
  TMOD |= 0x20;                      /* timer 1 mode 2: 8-Bit reload        */
  TH1   = 0xfa;                      /* reload value 2400 baud              */
  TR1   = 1;                         /* timer 1 run                         */
  ES=1;
}




void Delay(void)
{
unsigned char ucDelayCount;
for(ucDelayCount=0; ucDelayCount<0xFF; ucDelayCount++)
{
  ;

}
unsigned long sum=0;
unsigned long __checksum=0xE728 ;
void main(void)
{
serial_init();
EA = 1;
while(1)
{
  putchar('8');
  putchar('\n');
  Delay();
  printf("welcome to www.21ic.com\n");
  printf("Checksum failed: 0x%04lX (calculated) "
                "vs 0x%04lX (from linker)\n", sum, __checksum);
}
}
0 0