跨届大侠
北京龙邱智能科技有限公司
- 积分
- 10332
- 威望
- 2905
- 贡献
- 6151
- 兑换币
- 4515
- 注册时间
- 2008-6-7
- 在线时间
- 638 小时
|
/**************************************************************************************
龙丘MC9S12XS128 多功能开发板
Designed by Chiu Sir
E-mail:chiusir@163.com
软件版本:V1.1
最后更新:2009年2月16日
相关信息参考下列地址:
博客: http://longqiu.21ic.org
淘宝店:http://shop36265907.taobao.com
------------------------------------
Code Warrior 4.7
Target : MC9S12XS128
Crystal: 16.000Mhz
busclock: 8.000MHz
pllclock:16.000MHz
本程序主要包括以下功能:
1.设置锁相环和总线频率;
2.IO口使用;
3.共四路ATD使用及显示方法。
LED计数,根据灯亮可以读取系统循环了多少次
*****************************************************************************************/
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#include "LQprintp.h"
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 20 SCI0_ISR(void)
{
SCI0CR2_RIE=0;
//此处为串口中断需要处理的事情
uart_putchar(uart_getkey());
PORTA_PA0=~PORTA_PA0;
SCI0CR2_RIE = 1;
}
#pragma CODE_SEG DEFAULT
//-----------------------------------------------------
void setbusclock(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=1;
REFDV=1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
_asm(nop); //BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
//-----------------------------------------------------
static void SCI_Init(void)
{
SCI0CR2=0x2c; //enable Receive Full Interrupt,RX enable,Tx enable
SCI0BDH=0x00; //出口波特率为9600
SCI0BD =0x68; //SCI0BDL=busclk/(16*SCI0BDL)
//busclk 8MHz, 9600bps,SCI0BD=0x34
//busclk 16MHz, 9600bps,SCI0BD=0x68
//busclk 24MHz, 9600bps,SCI0BD=0x9C
} //busclk 32MHz, 9600bps,SCI0BD=0xD0
//busclk 40MHz, 9600bps,SCI0BD=0x106
//-----------------------------------------------------
void AD_Init(void)
{
ATD0CTL1=0x00; //7:1-外部触发,65:00-8位精度,4:放电,3210:ch
ATD0CTL2=0x40; //禁止外部触发, 中断禁止
ATD0CTL3=0xa0; //右对齐无符号,每次转换4个序列, No FIFO, Freeze模式下继续转
ATD0CTL4=0x01; //765:采样时间为4个AD时钟周期,ATDClock=[BusClock*0.5]/[PRS+1]
ATD0CTL5=0x30; //6:0特殊通道禁止,5:1连续转换 ,4:1多通道轮流采样
ATD0DIEN=0x00; //禁止数字输入
}
//-----------------------------------------------------
void Dly_ms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<2670;jj++); //busclk:16MHz--1ms
}
byte ReadATD(byte ch)
{
byte ad=0;
while(!ATD0STAT0_SCF);
switch(ch)
{
default:
case 0:
ad= ATD0DR0L;
break;
case 1:
ad= ATD0DR1L;
break;
case 2:
ad= ATD0DR2L;
break;
case 3:
ad= ATD0DR3L;
break;
case 4:
ad= ATD0DR4L;
break;
case 5:
ad= ATD0DR5L;
break;
case 6:
ad= ATD0DR6L;
break;
case 7:
ad= ATD0DR7L;
break;
}
return ad;
}
void main(void){
unsigned char LedCnt=0;
int fenwei=0,gewei=0;
setbusclock();
SCI_Init();
AD_Init();
DDRA=0xFF;
PUCR_PUPAE=1;
putstr("\nLongQiu s.&t.\n");
EnableInterrupts;
for(;;)
{
LedCnt=(LedCnt>0XFE?0:++LedCnt);
Dly_ms(1000); //修改延时以修改数据发送频率
//低电平灯亮用这句,注释掉下面那句
PORTA_PA0=~PORTA_PA0;
//高电平灯亮用这句,注释掉上面那句
//PORTB=LedCnt;
putstr("\nWeb: shop36265907.taobao.com");
fenwei=ReadATD(0) *100/51;//参考电压5V, 500/255
gewei=fenwei/100;
fenwei=fenwei%100;
printp("\nAD0:%d.%02dV,",gewei,fenwei);
fenwei=ReadATD(1) *100/51;//参考电压5V, 500/255
gewei=fenwei/100;
fenwei=fenwei%100;
printp("\nAD1:%d.%02dV,",gewei,fenwei);
fenwei=ReadATD(2) *100/51;//参考电压5V, 500/255
gewei=fenwei/100;
fenwei=fenwei%100;
printp("\nAD2:%d.%02dV,",gewei,fenwei);
fenwei=ReadATD(3) *100/51;//参考电压5V, 500/255
gewei=fenwei/100;
fenwei=fenwei%100;
printp("\nAD3:%d.%02dV;",gewei,fenwei);
}
} |
|