📄 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++;
}
}
}
/*********************************************************************************************************
**函数名称:ADC_ISR( )
**函数功能:ADC转换结束中断服务函数。读取通道0的值并发送到PC机显示出来
**入口参数:无
**出口参数:无
********************************************************************************************************/
void ADC_ISR(void)
{
char str[20];
uint32 val;
val = (AD0DR0 >>6) & 0x3ff; //读取通道0的结果
val = (val * 3300)/1024; // ADC的参考电压为3300mV
sprintf(str,"%4d mV VIN0", val); //格式化显示数据
ISendStr(0,0,0x30,str); //将数据发送到PC机显示
AD0STAT &= (~(1<<16));
VICVectAddr = 0;
}
/*********************************************************************************************************
** Function name: Main
**
** Descriptions: 利用P0.16脚下降沿触发AD转换。中断方式读取转换结果并发送到PC机显示出来
**
********************************************************************************************************/
void Main(void)
{
TargetInit(VPBDIV_DATA, PLLCFG_DATA, MAMTIM_DATA); // don't delete
while((PLLSTAT & (1 << 10)) == 0); // can delete
PINSEL1 = 0x00; //P0.16选择GPIO
//其他测试情形
//PINSEL1 = 0x01; //P0.16选择EINT0
IO0DIR = 0;
ADC_InitToSW(0,3000000,2,0); //ADC 初始化:通道0,AD转换频率预设3MHz(实际值可能有误差),P0.16脚下降沿触发AD转换
UARTn_Init(0,115200,8,1,0,0); //串口0初始化:115200bps,8位数据,1位停止位,无校验,禁止中断
SetADnIntEn(0); //使能通道0 AD中断
SetISR(18,0, (unsigned int)ADC_ISR); //指定中断函数和中断优先级
IRQEnable(); //打开IRQ中断
while(1);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -