📄 uart0_main.c
字号:
// *********************************
// LPC2000 SYSTEM WITHOUT OS
// FILE: MAIN.C
// MODIFIED: ZPCYP 2005-3-16 20:16
// *********************************
//串口发送字符
#include <stdio.h>
#include "lpc22xx.h"
#include "init_c.h"
#include "vic.h"
#include "eint.h"
#include "main.h"
#include "config.h"
#include "serial.h"
//extern short adc_data[];
// #define a F_OSC
#define UART_BPS 19200; //波特率
unsigned char SEND_STRING[] = "Hello World!\n";
/****************************************************************************
* 名称:DelayNS()
* 功能:长软件延时
* 入口参数:dly 延时参数,值越大,延时越久
* 出口参数:无
****************************************************************************/
void DelayNS(int dly)
{ int i;
for(; dly>0; dly--)
for(i=0; i<5000; i++);
}
/****************************************************************************
* 名称:UART0_Ini()
* 功能:初始化串口0。设置为8位数据位,1位停止位,无奇偶校验,波特率为9600
* 入口参数:无
* 出口参数:无
****************************************************************************/
void UART0_Ini(void)
{
int Fdiv;
/*VPBDIV = 0x00;
PLLCON = 0x03;
PLLCFG = 0x02;
PLLFEED = 0XAA;
PLLFEED = 0X55;
*/
/////设置串口参数
/* U0LCR = 0x83; // DLAB = 1,可设置波特率
Fdiv = (F_PCLK / 16) / UART0_BAUD; //设置波特率
//Fdiv = (F_PCLK / 16) / 9600; //设置波特率
U0DLM = (Fdiv >> 8);
U0DLL = (Fdiv & 0xff);
// U0DLL = 20;
U0LCR = 0x03;
*/
/*
U0LCR = 0x83; // DLAB = 1
U0DLM = (F_PCLK / 16 / UART0_BAUD) >> 8; // Set baud rate
U0DLL = (PCLK / 16 / UART0_BAUD) & 0xff;
U0LCR = 0x03;
*/
U0LCR = 0x83; // DLAB = 1
U0DLM = (F_PCLK / 16 / 14400) >> 8; // Set baud rate
U0DLL = (F_PCLK / 16 / 14400) & 0xff; // N, 8, 1
U0LCR = 0x03;
}
/****************************************************************************
* 名称:UART0_SendByte()
* 功能:向串口发送字节数据,并等待发送完毕。
* 入口参数:data 要发送的数据
* 出口参数:无
****************************************************************************/
void UART0_SendByte(unsigned char data)
{
while( (U0LSR & 0x40)==0 ); // 等待数据发送完毕
U0THR = data;
//while( (U0LSR & 0x40)==0 ); // 等待数据发送完毕
// 发送数据
// while( (U0LSR & 0x40)==0 ); // 等待数据发送完毕
}
/****************************************************************************
* 名称:UART0_SendStr()
* 功能:向串口发送一字符串
* 入口参数:srt 要发送的字符串的指针
* 出口参数:无
****************************************************************************/
/*
void UART0_SendStr(unsigned char *str)
{ while(1)
{ if( *str == '\0' ) break;
UART0_SendByte(*str++); // 发送数据
}
}
*/
int main(void)
{
/* //unsigned char ch ='r';
unsigned char ch;
int ctc1, ctc2;
int x;
x =1 ;
ch = 0x55;
//UART0_Ini();
init_serial_0();*/
/*测试GPI/O 口
IODIR1 = 0X00700000;//输出方式
IOSET1 = 0X00100000;//对应位输出高
IOCLR1 = 0X00600000;//对应位输出低
*/
/* while(1)
{
UART0_SendStr(SEND_STRING);
DelayNS(10);
};*/
target_init();
/* PLLCON = 0x00000003;
PLLCFG = 0x00000043;
PLLFEED = 0XAA;
PLLFEED = 0X55;
VPBDIV = 0x00;
*/
init_serial_0();
//UART0_Ini();
while(1)
{
//UART0_SendByte(0x55);
//UART0_SendByte(0x55);
UART0_SendByte(0x7c);
DelayNS(10);
}
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -