?? pca.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 + -