📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
** http://www.zyinside.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2006-02-22
** Last Version: 1.0
** Descriptions: header file of the specific codes for LPC2200 target boards
** Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#define IN_MAIN
#include "config.h"
#include <stdio.h>
#include "UART.H"
#include "ADC.h"
#pragma import(__use_no_semihosting_swi) //don't delete this line
/*********************************************************************************************************
** Function name: IRQ_Exception
**
** Descriptions: interrupt exceptional handler , change it as needed
** don't delete this function
** input parameters: None
** Returned value: None
**
**
** Created by: Chenmingji
** Created Date: 2006/02/22
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void IRQ_Exception(void)
{
}
/*********************************************************************************************************
**函数名称:PC_DispChar( )
**函数功能:向PC机发送显示字符
**入口参数:x 显示位置X坐标
** y 显示位置Y坐标
char 显示的字符,不能为0xff
color 显示的颜色
**出口参数:无
********************************************************************************************************/
void PC_DispChar(uint8 x, uint8 y, uint8 chr, uint8 color)
{
UARTn_SendByte(0, 0xFF); //帧头
UARTn_SendByte(0, x);
UARTn_SendByte(0, y);
UARTn_SendByte(0, chr);
UARTn_SendByte(0, color);
}
/*********************************************************************************************************
**函数名称:ISendStr( )
**函数功能:向PC机发送字符串
**入口参数:x 字符串显示起始位置X坐标
** y 字符串显示起始位置Y坐标
color 显示的颜色
*str 要显示的字符串
**出口参数:无
********************************************************************************************************/
void ISendStr(uint8 x, uint8 y, uint8 color, char *str)
{
while(1)
{
if(*str == '\0') break;
PC_DispChar(x, y, *str, color);
x++;
str++;
if(x>= 80)
{
x= 0;
y++;
}
}
}
/*********************************************************************************************************
**函数名称:DelayNS( )
**函数功能:延时函数
**入口参数:dly 延时值
**出口参数:无
********************************************************************************************************/
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
{
for(i=0; i<50000; i++);
}
}
/*********************************************************************************************************
** Function name: Main
**
** Descriptions: 利用ADC对通道0 的电压进行采样,并把值发送到PC机显示出来。
********************************************************************************************************/
void Main(void)
{
char str[20];
uint32 val;
TargetInit(VPBDIV_DATA, PLLCFG_DATA, MAMTIM_DATA); // don't delete
while((PLLSTAT & (1 << 10)) == 0); // can delete
ADC_InitToSW(0, 3000000, 1, 0); //ADC配置成软件模式
UARTn_Init(0,115200,8,1,0,0); //串口配置
while(1)
{
Read_ADC(&val); //读取通道0的结果
val = (val * 3300)/1024; //ADC的参考电压为3300mV
sprintf(str,"%4d mV VIN0", val); //格式化显示数据
ISendStr(0,0,0x30,str); //将数据发送到PC机显示
DelayNS(1);
}
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -