在线时间2 小时
UID52696
注册时间2008-6-7
NXP金币0
该用户从未签到
高级会员

- 积分
- 799
- 最后登录
- 1970-1-1
|
MC9S08JM60 12位AD转换的源代码主题部分 :
/********************************************************
* Copyright (c) 2009, LONGQIU S.&T.
* LONGQIU Application Note
* File name : LQadc.c
* Project name: JM60 Evaluation code
* Description : This software is the demo code for JM60 ADC module
*
* History :
* 2009/01/17 : Initial Development
*
龙丘MC9S08jm60多功能USB开发板V1.0
编写:龙丘
Designed by Chiu Sir
E-mail:chiusir@163.com
软件版本:V1.0
最后更新:2009年01月18日
相关信息参考下列地址:
博客: http://longqiu.21ic.org
淘宝店:http://shop36265907.taobao.com
使用说明:
1.串口9600波特率输出;
2.LCD显示转换后的电压数据;
3.LED指示数据显示状态,闪烁:程序正常,否则死机;
4.12位ADC测试功能,模拟输入用ADP11;
5.总线配置为24MHz;
6.整数转字符数据格式转换方法.
**********************************************************/
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include
#include "LQadc.h"
#include "LQ12864.h"
#include "LQprintp.h"
/**********************************************************************************************
* ADC_Init: This function initilizes the ADC module
*
* Parameters: none
*
* Subfunctions: none.
*
* Return: void
*********************************************************************************************/
void ADC_Init(void)
{
ADCCFG = 0x61; //busclk/2, Div by 8,ADCK = 1.5MHz
/* 0b0000000 0
* ||||||| |__ bit0,1: ADICLK : input clock select
* |||||||_|
* ||||||_____ bit2,3: MODE : Conversion Mode selection
* |||||_|
* ||||______ bit4: ADLSMP: long sample time configuration
* |||_______ bit5,6 : ADIV: Clock Divide Select
* ||______|
* |_________ bit7: ADLPC: Low power configuration
*/
ADCSC2 = 0x00; //
/* 0b00000000
* ||||||||__ bit0:
* |||||||___ bit1:
* ||||||____ bit2:
* |||||_____ bit3:
* ||||______ bit4: ACFGT: Compare function greater than enable
* |||_______ bit5: ACFE : Compare enable
* ||________ bit6: ADTRG: Conversion trigger select
* |_________ bit7: ADACT: Convert active
*/
ADCCFG |= 0x04; //BIT2--3 00:8BIT,01:12BIT,10:102BIT,11:RES
/*Change the channel, to check the releation between pins and channels */
APCTL1 = 0x00; //others I/O Enabled
APCTL2 = 0x08; //Enable ADP11 ADC input
}
/****************************************************************************************
* ADC_Cvt : start to conversion of one channel
* input: channel is the channel number which will do conversion
*
* Return : None
***************************************************************************************/
word ADC_Cvt12B(unsigned char Channel)
{
word AdcResult=0;
if(Channel
|
|