⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pca.h

📁 机器人部分C语言编码 c语言 供大家参考学习
💻 H
字号:
// *********************************************************************************** //
//
//	Filename		:   pca.c
//	Title        	:   TowerBuilder PCA setting
//	Author			:   Fung Tin Ching
//	Created Date	:   2007.11.27
//	Revisited Date	:   2008.01.16
//	Description		:   This file is set the Programmable Counter Array(PCA) to gernerate
//                      PWM signal to servo and used two of it interrupt for wheel count
//	Version         :   1.2
//
//  Copyright (c) 2008, All rights reserved.
// *********************************************************************************** //
#ifndef _PCA_H
#define _PCA_H

#include "Global.h"


volatile u16 wheelCountLeft=0;    // Wheel count for Left Wheel
volatile u16 wheelCountRight=0;   // Wheel count for Right Wheel
                                  // **RM. One Cycle of Wheel have 16 pulse

//-----------函数声明----------------------------------
void PWM_Init(void);//初始化PWM


void setPWM0(u16 value);//PWM0装载匹配值设置
void setPWM1(u16 value);//PWM1装载匹配值设置
void setPWM2(u16 value);//PWM2装载匹配值设置


void change_high(u08 h);//升降
void change_angle(u08 a);//夹东西





//==========PCA=======================
void PCA(void) interrupt 6 using 2
{
	if (CF==1)
	{
		CF=0;
 		CH = 0xB7;
		CL = 0xFF;
	    PWM1=1;
  	    PWM2=1;
  	    PWM3=1;
	}
	if (CCF3==1)
	{
		CCF3=0;
		wheelCountLeft++;		
	}
	if (CCF4==1)
	{	
		CCF4=0;
		wheelCountRight++;
	}
	
}

void PWM_Init(void)
{
	PWM1=1;
    PWM2=1;
	PWM3=1;
	
	CMOD = 0x01;	//使能Timer PCA中断
	   
	EC = 1;      	//允许中断
	CH = 0xB7;		//Timer PCA中断周期为20ms
	CL = 0xFF;
	CR = 1;       
}

void setPWM1(u16 value)
{
	CCAP0L = low_byte(0xBf9b-value);    
	CCAP0H = high_byte(0xBf9b-value); 
}

void setPWM2(u16 value)
{
	CCAP1L = low_byte(0xBBCF+value);    
	CCAP1H = high_byte(0xBBCF+value);   
}

void setPWM3(u16 value)
{
	CCAP2L = low_byte(0xB9fC+value);    
	CCAP2H = high_byte(0xB9fC+value);   
}



/***********************************************************************
函数功能:升高物品
入口参数:h		中臂向外张开的量值
定值参数:101	中臂从初始位置0到物品升到最高时的位置800之间均分成100份
************************************************************************/
void change_high(u08 h)
{
	if(h>0&&h<=101)		//锁定高度于8*h
	{
		CCAPM1=0x4C;
		setPWM2(8*h);
	}
	else if(h==0)				//h=0,则松开
	{
		CCAPM1=0;
	}
}

/**************************************************************
函数功能:夹取物品
入口参数:a		双臂向外张开的量值
定值参数:101	双臂从初始位置0到90度角位置800之间均分成100份
***************************************************************/
void change_angle(u08 a)
{
	CCAPM0=0;
	CCAPM2=0;
	delay_ms(70);
	if(a>0&&a<=101)		//锁定张开角度于8*a
	{
		CCAPM0=0x4C;
		setPWM1(8*a);
		CCAPM2=0x4C;
		setPWM3(8*a);
	}
	else if(a==0)				//a=0,则松开
	{
		CCAPM0=0;
		CCAPM2=0;
	}
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -