📄 main.c
字号:
#include <LPC22xx.h>
#include <stdio.h>
#include "Public.h"
#include "Uart.h"
#include "Queue.h"
#include "I2C.h"
/*****************************************************************************************
* 函数名称: void Sys_Init(void)
* 函数描述: 系统初始化
*****************************************************************************************/
void Sys_Init(void)
{
U32 M;
U32 VDIV;
M = (PLLCFG & 0x1F)+1;
VDIV = VPBDIV & 0x3;
GD.Fcclk = Fosc * M;
switch(VDIV)
{
case 0 : GD.Fpclk = GD.Fcclk / 4; break;
case 1 : GD.Fpclk = GD.Fcclk; break;
case 2 : GD.Fpclk = GD.Fcclk / 2; break;
default : GD.Fpclk = GD.Fcclk / 4; break;
}
//IO2DIR = 0xF0000000;
//IO2SET = 0xF0000000;
}
/*****************************************************************************************
* 函数名称: void wait(INT32U dly)
* 函数描述: 延迟函数
*****************************************************************************************/
void wait(U32 dly)
{
U32 i;
for (; dly > 0; dly--){
for (i = 0; i < 5000; i++);
}
}
/*****************************************************************************************
* 函数名称: int main(void)
* 函数描述: 主程序 串口发送@W#,写数据,@R#读数据
*****************************************************************************************/
int main (void)
{
U8 *s;
char s1[30];
U32 WD, RD;
Sys_Init();
Uart_Init(115200, 8, 0, 1);
Queue_Init(&CommQueue);
I2C_Init(100000);
while(1)
{
s = Queue_Get(&CommQueue); //读取串口数据 @R#,@W#
while (s > 0)
{
if (*(s+1) == 'W')
{
WD = 11223344;
I2C_WriteU32(4, WD);
}
else if (*(s+1) == 'R')
{
RD = I2C_ReadU32(4);
sprintf(s1, "%d", RD);
Uart_SendStr((U8 *)s1);
Uart_SendByte('\r');
Uart_SendByte('\n');
}
s = Queue_Get(&CommQueue);
}
wait(5);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -