/*
项目:示例程序
芯片:PIC16F1503
功能:
休眠唤醒
2.7uA
脚位定义
________________________
|VDD VSS|
|RA5 AN0/RA0|
|RA4/AN3 AN1/RA1|
|RA3 PWM3/AN2/RA2|
|RC5/CWG1A/PWM1 AN4/RC0|
|RC4/CWG1B PWM4/AN5/RC1|
|RC3/AN7/PWM2 AN6/RC2|
------------------------
*/
#include <pic.h>
//芯片配置字
__CONFIG(0x3924);
__CONFIG(0x3FFF);
void main()
{
/*
振荡器控制寄存器
<6-3>IRCF 内部振荡器频率选择位
5V供电 3.3V供电 T0
1111 16MHz 887uA 125us
1110 8MHz 613uA 250us
1101 4MHz 470uA 500us
1100 2MHz 389uA 1ms
1011 1MHz 354uA 2ms
1010 500kHz 331uA 4ms
1001 250kHz
1000 125kHz
0111 500kHz 复位默认 332uA 290uA 4ms
0110 250kHz
0101 125kHz 320uA
0100 62.5kHz
001x 31.25kHz 317uA
000x 31kHz 20uA 18.3uA
*/
OSCCON = 0B00000000; //<6-3>IRCF;<1:0>SCS
VREGCON= 0B00000010; //<1>VREGPM
/*
PS 预分频比选择位
000 1:2
001 1:4
010 1:8
011 1:16
100 1:32
101 1:64
110 1:128
111 1:256
*/
OPTION_REG = 0B00000000;//<7>#WPUEN;<6>INTEDG;<5>TMR0CS;<4>TMR0SE;<3>PSA;<2:0>PS
APFCON = 0B00000000; //备用引脚选择
ANSELA = 0B00000000; //模拟数字 1:模拟; 0:数字
ANSELC = 0B00000000; //模拟数字 1:模拟; 0:数字
LATA = 0B00001000; //数据锁存器
TRISA = 0B00001000; //输入输出 1:输入; 0:输出
PORTA = 0B00001000; //电平 1:高; 0:低
WPUA = 0B00001000; //上拉 1:使能; 0:禁止
LATC = 0B00000000; //数据锁存器
TRISC = 0B00000000; //输入输出 1:输入; 0:输出
PORTC = 0B00000000; //电平 1:高; 0:低
IOCAP = 0B00000000; //PA电平变化中断正边沿
IOCAN = 0B00000000; //PA电平变化中断负边沿
//ADC
FVRCON = 0B01000000; //<7>FVREN;<6>FVRRDY;<5>TSEN;<4>TSRNG;<3:2>CDAFVR;<1:0>ADFVR
/*<6-2>CHS
00000 AN0
00001 AN1
00010 AN2
00011 AN3
00100 AN4
00101 AN5
00110 AN6
00111 AN7
11101 温度
11110 DAC
11111 FVR
*/
ADCON0 = 0B01111100; //<6-2>CHS;<1>GO/DONE;<0>ADON
ADCON1 = 0B10100000; //<7>ADFM;<6-4>ADCS;<1:0>ADPREF
//Timer0
TMR0 = 0x00;
//Timer1
/*
<5:4>T1CKPS Timer1输入时钟预分频比选择位
11 1:8
10 1:4
01 1:2
00 1:1
*/
T1CON = 0B00000000; //<7:6>TMR1CS;<5:4>T1CKPS;<2>#T1SYNC;<0>TMR1ON
T1GCON = 0B00000000; //<7>TMR1GE;<6>T1GPOL;<5>T1GTM;<4>T1GSPM;<3>T1GGO;<2>T1GVAL;<1:0>T1GSS
TMR1H = 0x00; //递增到FFFFh发生中断
TMR1L = 0x00;
//Timer2
/*
<6-3>T2OUTPS Timer2输出后分频比选择位
0000 1:1
0001 1:2
0010 1:3
...
1101 1:14
1110 1:15
1111 1:16
<1:0>Timer2时钟预分频比选择位 影响PWM周期
00 1
01 4
10 16
11 64
*/
T2CON = 0B00000000; //<6-3>T2OUTPS;<2>TMR2ON;<1:0>T2CKPS
PR2 = 0x68; //周期寄存器//PWM周期=(PR2+1)×4Tosc×(TMR2预分频值)
TMR2 = 0x00; //计数保持寄存器
//PWM1
/*
38kHz T2CKPS预分频1, PR2=0X68;PWM1DCH=0x1A;
*/
PWM1CON= 0B00000000; //<7>PWM1EN;<6>PWM1OE;<5>PWM1OUT;<4>PWM1POL
PWM1DCH= 0x1A; //PWM占空比高位
PWM1DCL= 0x00; //<7:6>PWM占空比低位 10位分辨率的占空比
//CWG模块
CWG1DBR= 0x0A; //<5-0>上升沿死区计数
CWG1DBF= 0x0A; //<5-0>下降沿死区计数
CWG1CON0=0B00000000; //<7>G1EN;<6>G1OEB;<5>G1OEA;<4>G1POLB;<3>G1POLA;<0>G1CS0
/* <2-0>G1IS
111 LC1OUT
110 N1OUT
101 PWM4OUT
100 PWM3OUT
011 PWM2OUT
010 PWM1OUT
001 ASYNC_C1OUT
000 ASYNC_C2OUT
*/
CWG1CON1=0B10100010; //<7:6>G1ASDLB;<5:4>G1ASDLA;<2-0>G1IS
CWG1CON2=0B00000000; //<7>G1ASE;<6>G1ARSEN;<3>G1ASDC2;<2>G1ASDC1;<1>G1ASDFLT;<0>G1ASDCLC2
PIE1 = 0B00000000; //<7>TMR1GIE;<6>ADIE;<3>SSP1IE;<1>TMR2IE;<0>TMR1IE
PIR1 = 0B00000000; //<7>TMR1GIF;<6>ADIF;<3>SSP1IF;<1>TMR2IF;<0>TMR1IF
INTCON = 0B00000000; //<7>GIE;<6>PEIE;<5>TMR0IE;<4>INTE;<3>IOCIE;<2>TMR0IF;<1>INTF;<0>IOCIF
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
while(1)
{
SLEEP();
///////////////////////////////////////////////////////////
}
}
数据手册上写典型值是 0.5uA, 实测是 2.7uA。不知道哪里有问题。芯片只接了电源和地,其它脚都悬空输出低的。
大神们帮看看,谢谢! |