当前位置:首页 > 单片机 > 单片机
[导读]主文件代码:/******************************************************************************/ /* This file is part of the uVision/ARM development tools */ /* Copyright KEIL ELEKTRONIK GmbH 2002-2004

主文件代码:

/******************************************************************************/
/* This file is part of the uVision/ARM development tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
/******************************************************************************/
/* */
/* HELLO.C: Hello World Example */
/* */
/******************************************************************************/

#include /* prototype declarations for I/O functions */
#include /* LPC21xx definitions */


/****************/
/* main program */
/****************/
int main (void) { /* execution starts here */

/* initialize the serial interface */
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */

printf ("Hello Worldn"); /* the 'printf' function call */

while (1) { /* An embedded program does not stop and */
; /* ... */ /* never returns. We've used an endless */
} /* loop. You may wish to put in your own */
} /* code were we've printed the dots (...). */
串口程序代码:

/******************************************************************************/
/* This file is part of the uVision/ARM development tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
/******************************************************************************/
/* */
/* SERIAL.C: Low Level Serial Routines */
/* */
/******************************************************************************/

#include /* LPC21xx definitions */

#define CR 0x0D


int putchar (int ch) { /* Write character to Serial Port */

if (ch == 'n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x20));
return (U1THR = ch);
}


int getchar (void) { /* Read character from Serial Port */

while (!(U1LSR & 0x01));

return (U1RBR);
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭