📄 uartapp.c
字号:
uart1count=0;
if((uart1buf[0]=='a')|(uart1buf[1]=='a'))
{
Uart1SendByte(0x0d);
Uart1SendByte('\n');
printstr("Exe Ra",2);
uart1test=0xaa;
}
else if((uart1buf[0]=='b')|(uart1buf[1]=='b'))
{
Uart1SendByte(0x0d);
Uart1SendByte('\n');
printstr("Exe Rb",2);
uart1test=0xbb;
}
else if((uart1buf[0]=='c')|(uart1buf[1]=='c'))
{
Uart1SendByte(0x0d);
Uart1SendByte('\n');
printstr("Exe Rc",2);
uart1test=0xcc;
}
else if((uart1buf[0]=='d')|(uart1buf[1]=='d'))
{
Uart1SendByte(0x0d);
Uart1SendByte('\n');
printstr("Exe Rd",2);
uart1test=0xdd;
}
Uart1SendByte(0x0d);
Uart1SendByte('\n');
}
else
{
Uart1SendByte(uart1buf[uart1count]);
if(uart1count<10)
uart1count++;
}
IO1SET = LED3;
}
VICVectAddr = 0x00; // 中断处理结束
}
/****************************************************************************
* 名称: KeyScan()
* 功能: 返回拨码状态
* 入口参数: 无
* 出口参数: 8位UINTi型字节
*****************************************************************************/
UINT8 KeyScan(void)
{
UINT8 temp = 0;
if((IO1PIN & Sk1) == 0)
{
temp = (temp<<1)+ 1;
}
else
{
temp = (temp<<1) ;
}
if((IO0PIN & Sk2) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO0PIN & Sk3) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO0PIN & Sk4) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & Sk5) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO0PIN & Sk6) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & Sk7) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & Sk8) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
return(temp);
}
/****************************************************************************
* 名称: KeyScan()
* 功能: 返回拨码状态
* 入口参数: 无
* 出口参数: 8位UINTi型字节
*****************************************************************************/
UINT8 KRScan(void)
{
UINT8 temp = 0;
if((IO0PIN & SI6) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & SI5) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & SI4) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO1PIN & SI3) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO0PIN & SI2) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
if((IO0PIN & SI1) == 0)
{
temp = (temp<<1) + 1;
}
else
{
temp = (temp<<1);
}
return(temp);
}
/****************************************************************************
* 延时函数
*****************************************************************************/
void DelayNS(UINT32 dly)
{ UINT32 i;
for(; dly>0; dly--)
for(i=0; i<50000; i++);
}
/*
************************************************************************************************************************
**函数原型 : void Uart0Send(UINT32 Len,UINT8 *Buf)
**参数说明 : Len -->> 发送字符长度;
Buf -->> 要发送数据的缓冲区首址
**返回 值 : 无
**说 明 : 本函数用于UART0发送数据,应用FIFO,非发送中断方式
************************************************************************************************************************
*/
void Uart0Send(UINT32 Len,UINT8 *Buf)
{
UINT32 i,j,k;
UINT8 *p =Buf;
i= Len/16;
j=Len%16;
while(i--)
{
for(k=0;k<16;k++)
{
uU0THR.Word=(UINT32)(*p++);
}
while(0 == (U0LSR &0x40));
}
for(k=0;k<j;k++)
{
uU0THR.Word=(UINT32)(*p++);
}
}
/****************************************************************************
* 名称:IRQ_Eint0()
* 功能:外部中断EINT0服务函数,取反LED1。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void __irq IRQ_Eint0(void)
{
if(0x01 == AD_Sample2)
{
AD_Sample2 = 0x02;
//ABC_Phase_Sample();
}
EXTINT = 0x01; // 清除EINT0中断标志
VICVectAddr = 0x00;
}
/****************************************************************************
* 名称:Eint0_init()
* 功能:外部中断EINT0初始化函数
* 入口参数:无
* 出口参数:无
****************************************************************************/
void Eint0_init(void)
{
PINSEL1 = PINSEL1 | 0x00000001; // 设置管脚连接,P0.16设置为EINT0,P0.20设置为EINT3
EXTMODE = 0x0F; // 设置EINT0、EINT3中断为边沿触发模式
EXTPOLAR = 0x0F; // 设置EINT0、EINT3中断为上升沿触发
/* 打开EINT0、EINT3中断(设置向量控制器,即使用向量IRQ)*/
//VICIntSelect = 0x00000000; // 设置所有中断分配为IRQ中断
VICVectCntl4 = 0x20|14; // 分配EINT0中断到向量中断4
VICVectAddr4 = (int)IRQ_Eint0; // 设置中断服务程序地址
EXTINT = 0x01; // 清除EINT0中断标志
//VICIntEnable = (1<<14); // 使能EINT0、EINT3中断
VICIntEnable = 0x00004000; // 使能EINT0、EINT3中断
}
/*********************************************************************************
*
*
*
*
**********************************************************************************/
void SendDouble(double temp1)
{
union
{
double a;
struct
{
char a1;
char a2;
char a3;
char a4;
char a5;
char a6;
char a7;
char a8;
}b;
}c;
c.a = temp1;
SendByte(c.b.a1);
SendByte(c.b.a2);
SendByte(c.b.a3);
SendByte(c.b.a4);
SendByte(c.b.a5);
SendByte(c.b.a6);
SendByte(c.b.a7);
SendByte(c.b.a8);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -