📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2004-09-16
** Last Version: 1.0
** Descriptions: The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2004-09-16
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
typedef struct UartMode
{
uint8 datab ;
uint8 stopb;
uint8 parity;
}UARTMODE ;
//uint8 rec_buf[8];
uint8 rec_buf;
uint8 rec_new,sed_new;
void __irq IRQ_UART0()
{
uint8 i;
if((U0IIR & 0x0F) == 0x04)
{
rec_new = 1;
rec_buf = U0RBR;
}
else if((U0IIR & 0x0F) == 0x02)
{
sed_new = 1;
}
/*for(i=0;i<8;i++)
{
rec_buf[i] = U0RBR;
}*/
i = U0IIR ;
VICVectAddr = 0x00;
}
void __irq IRQ_UART0_SED()
{
VICVectAddr = 0x00;
}
int8 UART0_Init(uint32 baud,UARTMODE set)
{
uint32 bak;
if((baud == 0) || (baud >115200)) return 0;
if((set.datab < 5) || (set.datab > 8)) return 0;
if((set.stopb == 0) || (set.stopb >2)) return 0;
if(set.parity >4) return 0;
U0LCR = 0x80;
bak = (Fpclk >> 4) / baud ;
U0DLM = bak >> 8;
U0DLL = bak & 0xFF;
bak = set.datab - 5;
if(set.stopb == 2) bak |= 0x04;
if(set.parity != 0)
{
set.parity = set.parity - 1;
bak |= 0x08;
}
bak |= set.parity << 4 ;
U0LCR =bak;
return (1);
}
void UART0_SendByte(uint8 dat)
{
U0THR = dat ;
}
void UART0_SendBuf()
{
uint8 i;
/* for(i=0;i<8;i++)
{
UART0_SendByte(rec_buf[i]) ;
}*/
sed_new = 0;
UART0_SendByte(rec_buf) ;
i=U0THR;
// while((U0LSR & 0x20) == 0) ;
}
int main (void)
{// add user source code
UARTMODE set;
set.datab = 8;
set.stopb = 1;
set.parity = 0;
rec_new = 0;
sed_new = 1;
PINSEL0 = 0x00000005;
UART0_Init(115200,set);
U0FCR = 0x01;
U0IER =0x03;
IRQEnable() ;
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x20 | 0x06 ;
VICVectAddr0 = (uint32) IRQ_UART0;
VICIntEnable = 1<<0x06;
while(1)
{
if(rec_new == 1)
{
rec_new = 0;
if(sed_new)
UART0_SendBuf();
}
}
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -