#include "AD18F06A.h"
#include <stdio.h>
#include "common.h"

/*******************************************************************************
// ----Function: GPIO_Init
// --Parameters:
// -----Returns: None
//---------Note:所有IO初始化
*******************************************************************************/
void GPIO_Init(void)
{
	TRISA = 0X00;   //PA输出模式
	TRISB = 0X00;   //PB输出模式
	TRISC = 0X00;   //PC输出模式

	PORTA = 0X00;	//PORTA输出0
	PORTB = 0X00;	//PORTB输出0
	PORTC = 0X00;	//PORTC输出0

	PAPD = 0XFF;    //关闭PA下拉
	PAPU = 0XFF;    //关闭PA上拉
	PBPD = 0XFF;    //关闭PB下拉
	PBPU = 0XFF;    //关闭PB上拉
	PCPD = 0XFF;    //关闭PC下拉
	PCPU = 0XFF;    //关闭PC上拉

	PAOD = 0X00;    //关PA开漏输出
	PBOD = 0X00;    //关PB开漏输出
	PCOD = 0X00;    //关PC开漏输出

	ANASEL0 = 0X00; //关PA模拟量通道
	ANASEL1 = 0X00; //关PB模拟量通道
	ANASEL2 = 0X00; //关PC模拟量通道
}

void timer3_PWM2(void)
{
	T3CLKEN = 1;
    PWM2CON0 = 0xFF;
    PWM2CON1 = 0x00;
	TRISA0 = 0;       //PA0输出
	PWM2_MAP = MAP_PA0;  //PWM2_MAP映射到PA0
    PWM3_MAP = MAP_PA1;
    PWM4_MAP = MAP_PA2;
    PWM5_MAP = MAP_PA3;
	PR3H = 0X0F;      //周期4ms
	PR3L = 0XA0;
	TMR3H = 0X00;
	TMR3L = 0X00;

	T3CON = 0X07;      //使能timer3，预分频16，后分频1
}

void PWM2_Duty(unsigned short Duty)
{
   unsigned char PWMH = 0;
   unsigned char PWML = 0;

   Duty     = Duty-1;
   PWMH     = (Duty >> 8) & 0xFF;
   PWML     = Duty & 0xFF;

	PWM2H = PWMH;      //占空比50%
	PWM2L = PWML;
}
void PWM3_Duty(unsigned short Duty)
{
   unsigned char PWMH = 0;
   unsigned char PWML = 0;

   Duty     = Duty-1;
   PWMH     = (Duty >> 8) & 0xFF;
   PWML     = Duty & 0xFF;

   PWM3H    = PWMH;
   PWM3L    = PWML;   //设置PWM占空比
}
void PWM4_Duty(unsigned short Duty)
{
   unsigned char PWMH = 0;
   unsigned char PWML = 0;

   Duty     = Duty-1;
   PWMH     = (Duty >> 8) & 0xFF;
   PWML     = Duty & 0xFF;

   PWM4H    = PWMH;
   PWM4L    = PWML;   //设置PWM占空比
}
void PWM5_Duty(unsigned short Duty)
{
   unsigned char PWMH = 0;
   unsigned char PWML = 0;

   Duty     = Duty-1;
   PWMH     = (Duty >> 8) & 0xFF;
   PWML     = Duty & 0xFF;

   PWM5H    = PWMH;
   PWM5L    = PWML;   //设置PWM占空比
}

/*******************************************************************************

*******************************************************************************/



