转载请注明出处!
首先介绍下NY8B062E与NY8B062D最终区别:
其实NY8B062E就是NY8B062D升级款,NY8B062D基本停产了,成本也高于NY8B062E
-
NY8B062E 有ADC 偏移校准 NY8B062D没有
-
NY8B062E ADC耗电只需要500mV,NY8B062D则需要3mA
-
NY8B062E 内部LDO误差只有百分之正负0.5,而NY8B062D是正负百分之1
-
NY8B062E 输入施密特触发 是可以开启和关闭的,NY8B062D是没有的
-
NY8B062E PWM 通道有4组(非常适合RGBW应用),NY8B062只有3路,勉强做个RGB应用
NY8B062D 视频简介
*项目:NY8B062E ADC_Interrupt
*文件:NY8B062E main.c
*描述:NY8B062E ADC转换中断结束
*1.设置ADC时钟频率为1MHz,采样脉冲宽度为8 ADC时钟,
*NY8B062E ADC转换时间=(8+12+2)*1us=22us,ADC转换率=1/22us=45.5KHz
*2.NY8B062E 将AIN1(PA1)设置为ADC模拟输入
*3.NY8B062E 将ADC转换结果bit11~bit4存储到RAM“R_AIN1_DATA_HB”,bit3~bit0存储到RAM“R_ AIN1_ DATA_ LB[3:0]”(x=0~4)
#include <ny8.h>
#include "ny8_constant.h"
unsigned char R_AIN1_DATA_HB;
unsigned char R_AIN1_DATA_LB;
#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
void F_wait_eoc(void);
void delay(int);
//! interrupt service routine
void isr(void) __interrupt(0)
{
ADRbits.ADIF = 0; // Clear adc interrupt flag bit
R_AIN1_DATA_HB = ADD; // RAM "R_AIN1_DATA_HB" Store AIN1's ADC data bit 11~4
R_AIN1_DATA_LB = 0x0F & ADR; // RAM "R_AIN1_DATA_LB" bit3~0 Store AIN1's ADC data bit 3~0
ADMDbits.START =1; // Start a ADC conversion session
}
void main(void)
{
R_AIN1_DATA_HB=R_AIN1_DATA_LB=0x00;
//----- Initial GPIO-----
IOSTA = C_PA_Input; // Set PortA as input port
PORTA = 0xFF; // PortA Data Register = 0xFF
INTE = 0x00; // INTE = 0x00
//----- Initial ADC-----
ADMD = C_ADC_En | C_ADC_CH_Dis | C_ADC_PA1 ; // Enable ADC power, Disable global ADC input channel. Select PA1 pad as ADC input (SFR "ADMD")
//----- ADC high reference voltage source select-----
ADVREFH = C_Vrefh_VDD; // ADC reference high voltage is supplied by internal VDD (Note: ADC clock freq. must be equal or less than 2MHz @ VDD=5.0V)
//ADVREFH = C_Vrefh_4V; // ADC reference high voltage is supplied by internal 4V (Note: ADC clock freq. must be equal or less than 1MHz)
//ADVREFH = C_Vrefh_3V; // ADC reference high voltage is supplied by internal 3V (Note: ADC clock freq. must be equal or less than 500KHz)
//ADVREFH = C_Vrefh_2V; // ADC reference high voltage is supplied by internal 2V (Note: ADC clock freq. must be equal or less than 250KHz)
//----- ADC clock frequency select----------------------------
ADR = C_Ckl_Div1; // ADC clock=Fcpu/1, Clear ADIF, disable ADC interrupt
//ADR = C_Ckl_Div2; // ADC clock=Fcpu/2, Clear ADIF, disable ADC interrupt
//ADR = C_Ckl_Div8; // ADC clock=Fcpu/8, Clear ADIF, disable ADC interrupt
//ADR = C_Ckl_Div16; // ADC clock=Fcpu/16, Clear ADIF, disable ADC interrupt
//----- ADC Sampling pulse width select-------------
//ADCR = C_Sample_1clk | C_12BIT; // Sample pulse width=1 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 500KHz)
//ADCR = C_Sample_2clk | C_12BIT; // Sample pulse width=2 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1MHz)
//ADCR = C_Sample_4clk | C_12BIT; // Sample pulse width=4 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1.25MHz)
ADCR = C_Sample_8clk | C_12BIT; // Sample pulse width=8 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 2MHz)
//--------------------------------------------------
PACON = C_PA1_AIN1; // Set AIN1(PA1) as pure ADC input for reducing power consumption (SFR "PACON")
ADMDbits.GCHS = 1; // Enable global ADC channel (SFR "ADMD")
ADRbits.ADIF = 0; // Clear adc interrupt flag bit
ADRbits.ADIE = 1; // Enable adc interrupt bit
delay(50); // Delay 1.12ms(Instruction clock=4MHz/4T) for waiting ADC stable
ADMDbits.START =1; // Start a ADC conversion session
ENI();
while(1)
{
CLRWDT(); // Clear WatchDog
}
}
void delay(int count)
{
int i;
for(i=1;i<=count;i++)
;
}