标题:
LQ_K60正交解码-MINI编码器测试程序
[打印本页]
作者:
卿卿卿卿卿卿
时间:
2018-9-25 16:23
标题:
LQ_K60正交解码-MINI编码器测试程序
单片机源程序如下:
/********************************************************
【平 台】龙丘K60DN多功能开发板
【编 写】龙丘
【Designed】by Chiu Sir
【E-mail 】chiusir@aliyun.com
【软件版本】V1.0
------------------------------------------------
【dev.env.】IAR6.60
【Target 】K60FX/DN
【Crystal 】50.000Mhz
【busclock】100.000MHz
【pllclock】200.000MHz
------------------------------------
下载器设置方式:
菜单project-->options-->debuger-->setup-->driver:
1.PE Micro:LQ_ARMJTAG/OSJTAG
2.Jlink/Trace:LQ_JLINKV8
********************************************************
实验说明:LPTMR脉冲计数器实验
实验操作:连接PTC1和PTC5,连接串口至电脑,即可在串口助手上看到脉冲的技术
*********************************************************/
#include "common.h"
#include "include.h"
/*************************************************************************
* 函数名称:void main(void)
* 功能说明:工程的主函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void main(void)
{
LED_INIT(); //初始化LED
uart_init (UART4,9600); //初始化串口模块4,设置波特率9600
pulse_init();
pit_init_ms(PIT0,1);
EnableInterrupts; //开总中断
while(1)
{
}
}
复制代码
/********************************************************
【平 台】龙丘K60DN多功能开发板
【编 写】龙丘
【Designed】by Chiu Sir
【E-mail 】chiusir@aliyun.com
------------------------------------------------
【dev.env.】IAR6.30
【Target 】K60FX/DN
【Crystal 】50.000Mhz
【busclock】100.000MHz(默认)
【pllclock】200.000MHz
------------------------------------
下载器设置方式:
菜单project-->options-->debuger-->setup-->driver:
1.PE Micro:LQ_ARMJTAG/OSJTAG
2.Jlink/Trace:LQ_JLINKV8
*********************************************************/
#include "common.h"
#include "include.h"
void speed_read(void);
int A_leftMotor,B_rightMotor ;
/*************************************************************************
* 函数名称:UART4_IRQHandle()
* 功能说明:串口4中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void UART4_IRQHandle()
{
char Rec[20];
if(uart_pendstr(UART4, Rec))
{
printf("你发送的数据是:%s\r\n", Rec);
}
}
/*************************************************************************
* 函数名称:PORTA_IRQHandle()
* 功能说明:PTA口中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void PORTA_IRQHandle()
{
if(PORTA_ISFR & (1<<19))
{
PORTA_ISFR |= (1<<19);
LED1_TURN();
LED2_TURN();
delayms(100);
}
}
/*************************************************************************
* 函数名称:PORTB_IRQHandle()
* 功能说明:PTB口中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void PORTB_IRQHandle()
{
if(PORTB_ISFR & (1<<10))
{
PORTB_ISFR |= (1<<10);
LED3_TURN();
LED4_TURN();
delayms(100);
}
}
/*************************************************************************
* 函数名称:FTM0_IRQHandle
* 功能说明:FTMO中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void FTM0_IRQHandle()
{
if( FTM0_STATUS & (1 << CH0) )
{
FTM_IRQ_DIS(FTM0, CH0); //关闭中断
LED(); //翻转LED
FTM_IRQ_EN(FTM0, CH0); //使能FTM中断
FTM0_STATUS = 0x00; //清除中断标志位
}
}
/*************************************************************************
* 函数名称:PIT0_IRQHandle()
* 功能说明:定时器1中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void PIT0_IRQHandle()
{
speed_read();
PIT_Flag_Clear(PIT0);
}
/*************************************************************************
* 函数名称:PIT0_IRQHandle()
* 功能说明:定时器1中断函数
* 参数说明:无
* 函数返回:无
* 修改时间:2014-1-4
* 备 注:官方例程
*************************************************************************/
void speed_read(void)
{
A_leftMotor = FTM2_CNT;
FTM2_CNT = 0;
B_rightMotor = FTM1_CNT;
FTM1_CNT = 0;
printf("编码器1转速为: %d\r\n", A_leftMotor);
printf("编码器2转速为: %d\r\n", B_rightMotor);
LED1_TURN();
LED2_TURN();
LED3_TURN();
LED4_TURN();
}
复制代码
所有资料51hei提供下载:
http://www.51hei.com/bbs/dpj-135837-1.html
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1