完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
[代码]
以上来自于百度翻译 以下为原文 Hello everyone, I had a question about the sleep mode (SLEEP Mode) of the microcontroller to check the consumption of it. I would just like to use my code activate the activation of the PIC old mode without button or interruption. The problem is that the code does nothing and the consumption remains the same. Can you tell me my mistake? Thank you in advance ! // CONFIG1 #pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC with 2x PLL (32MHz)) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is enabled; FOSC/4 clock appears at OSC2) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) // CONFIG2 #pragma config MCLRE = ON // Master Clear Enable bit (MCLR/VPP pin function is MCLR; Weak pull-up enabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config WDTE = OFF // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored) #pragma config LPBOREN = OFF // Low-power BOR enable bit (ULPBOR disabled) #pragma config BOREN = SBOREN // Brown-out Reset Enable bits (Brown-out Reset enabled according to SBOREN) #pragma config BORV = LOW // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V) #pragma config PPS1WAY = OFF // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will not cause a Reset) #pragma config DEBUG = OFF // Debugger enable bit (Background debugger disabled) // CONFIG3 #pragma config WRT = OFF // User NVM self-write protection bits (Write protection off) #pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.) // CONFIG4 #pragma config CP = OFF // User NVM Program Memory Code Protection bit (User NVM code protection disabled) #pragma config CPD = OFF // Data NVM Memory Code Protection bit (Data NVM code protection disabled) #include #define _XTAL_FREQ 3000000 // Oscillateur réglé à 1MHz // PORT A #define ICSPDAT RA0 // Port de programmation #define POWER RA1 // Retour d etat charge batterie #define MCLR RA3 // Port de programmation /*// PORT B #define ledR RB7 // +LED rouge // PORT C #define BP RC5 // Bouton poussoir*/ void main(void) { // Reglages des entrees/sorties TRISA = 0b00001011; // Choix entrees/sorties LATA = 0b00000000; // RAZ des ports ANSELA = 0; // Choix mode analogique/numerique INLVLA = 0b00000010; // Niveaux TTL WPUA = 0b00000010; // Resistances de pull-up interne TRISB = 0b01010000; // Choix entrees/sorties LATB = 0b10000000; // RAZ des ports ANSELB = 0; // Choix mode analogique/numerique INLVLB = 0b10000000; // Niveaux TTL SLRCONB = 0b10101111; // Slew rate WPUB = 0; // Resistances de pull-up interne TRISC = 0b00111000; // Choix entrees/sorties LATC = 0b11000000; // RAZ des ports ANSELC = 0b00011000; // Choix mode analogique/numerique INLVLC = 0b11000111; // Niveaux TTL SLRCONC = 0b11111111; // Slew rate WPUC = 0b00100000; // Resistances de pull-up interne __delay_ms(2); while(1){ SLEEP(); // boucle infinie } [/code] |
|
相关推荐
15个回答
|
|
|
请不要把代码标签放在问题的文本周围。如果你查看你的帖子,你会看到所有的文本都被截断了。
以上来自于百度翻译 以下为原文 Please do NOT put code tags around the text of your question. If you look at your post, you will see all that text is truncated. Here it is with the code tags removed. |
|
|
|
|
|
设置振荡器,像这样,首先做一个简单的LED测试,以确保系统运行。然后我认为你需要在睡眠功能被调用之前设置一些东西。像这样,Microchip代码配置器(MCC)是值得学习使用的,如果你长期使用它。它将产生振荡器和其他位的代码。
以上来自于百度翻译 以下为原文 Setup the oscillator, Like this // NOSC HFINTOSC; NDIV 4; OSCCON1 = 0x62; // CSWHOLD may proceed; SOSCPWR Low power; SOSCBE crystal oscillator; OSCCON3 = 0x00; // LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled; OSCEN = 0x00; // HFFRQ 1_MHz; OSCFRQ = 0x00; // HFTUN 0; OSCTUNE = 0x00; Then do a simple LED test first, to make sure the system is running. Then i think you need to set somethings before the sleep function is called. Like this VREGCON = 0b11; //lowest power mode but slowest wake up time IDLEN =0; //when set to 0, SLEEP() causes full pwr down mode. 1 = idle mode The Microchip Code Configurator (MCC) is worthwhile learning to use, if you are in it for the long run. It will generate the code for the oscillator and other bits. |
|
|
|
|
|
[代码]
以上来自于百度翻译 以下为原文 Hello, The PIC I'm using has three power off modes: DOZE mode, IDLE mode, and standby mode (P113). I would like using the button to vary these three modes by an interruption. On my test plate, I put a push button connected to RC5 (at rest 5V on RC5 and if a press on the BP, 0V on RC5), I thus wish to use the interrupts and the different mode of consumption of the mode sleep of my PIC16F18345 1 / BP at rest-> no interruption on RC5-> PIC in SLEEP mode 2 / Press BP-> interrupt on RC5-> PIC in DOZE mode -> Program in operation 3 / RE Press BP-> interrupt on RC5-> stop program-> PIC in IDLE Mode My current code does the following thing: power on -> sleep mode, press the button -> normal mode I can not vary the different modes. Thank you in advance ![quote=brownt]// CONFIG1 #pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz)) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; I/O or oscillator function on OSC2) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config MCLRE = ON // Master Clear Enable bit (MCLR/VPP pin function is MCLR; Weak pull-up enabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config WDTE = OFF // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored) #pragma config LPBOREN = OFF // Low-power BOR enable bit (ULPBOR disabled) #pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled) #pragma config BORV = LOW // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V) #pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a Reset) #pragma config DEBUG = OFF // Debugger enable bit (Background debugger disabled) // CONFIG3 #pragma config WRT = OFF // User NVM self-write protection bits (Write protection off) #pragma config LVP = ON // Low Voltage Programming Enable bit (Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.) // CONFIG4 #pragma config CP = OFF // User NVM Program Memory Code Protection bit (User NVM code protection disabled) #pragma config CPD = OFF // Data NVM Memory Code Protection bit (Data NVM code protection disabled) // PORT A #define ICSPDAT RA0 // Port de programmation #define POWER RA1 // Retour d etat charge batterie #define MCLR RA3 // Port de programmation // PORT B #define ledR RB7 // +LED rouge // PORT C #define BP RC5 // Bouton poussoir #define ON 0 // Led tirée au +VCC #define OFF 1 // Led tiréé au gnd //#define _XTAL_FREQ 1000000 // Oscillateur réglé à 1MHz //int etat_Bp; // Variable bouton #include #include void interrupt ISR () { if(PIE0bits.IOCIE) // IT changement d'etat bouton { CPUDOZEbits.IDLEN = 1; IOCCFbits.IOCCF5 = 0; // RAZ flag IT } else if (PIE0bits.IOCIE){ CPUDOZEbits.DOZEN = 1; IOCCFbits.IOCCF5 = 0; // RAZ flag IT } } void main(void) { OSCCON1 = 0x37; // Oscillateur interne OSCFRQ = 0x06; // Frequence oscillateur a 16MHz CPUDOZE = 0x00; // Choix DOZE/IDLE mode pour economie d energie en veille VREGCON = 0x03; // Choix DOZE/IDLE mode pour economie d energie en veille // Reglages des entrees/sorties TRISA = 0x37; // Choix entrees/sorties LATA = 0x00; // RAZ des ports ANSELA = 0x37; // Choix mode analogique/numerique WPUA = 0x20; // Resistances de pull-up interne TRISB = 0xFF; // Choix entrees/sorties LATB = 0x00; // RAZ des ports ANSELB = 0x70; // Choix mode analogique/numerique WPUB = 0x00; // Resistances de pull-up interne TRISC = 0xFF; // Choix entrees/sorties LATC = 0x00; // RAZ des ports ANSELC = 0xDF; // Choix mode analogique/numerique WPUC = 0x20; // Resistances de pull-up interne //WDTCON = 0x3C; //Reglage des interuptions INTCON = 0b11000000; // Autorisation des interruptions : GIE=1, PEIE=1 , INTED=0 donc sur front descendant IOCCNbits.IOCCN5 = 1; // Interruption sur la pin RC5 negative activee PIE0bits.IOCIE = 1; // Valide le changement d'etat IOCCFbits.IOCCF5 = 0; // RAZ flag IT SLEEP(); while(1){ } } [/code] |
|
|
|
|
|
HTTP//WW1.MICCHIP.COM/DeLoSt/En/DeVICECD/OC0401795E.PDFP 113至118 -&节电运行模式
以上来自于百度翻译 以下为原文 http://ww1.microchip.com/downloads/en/DeviceDoc/40001795E.pdf P 113 to 118--> power-saving operation modes |
|
|
|
|
|
你是说你的代码现在起作用了。你可以用按钮按压唤醒睡眠模式,然后移动到正常操作?我不知道为什么你做了下面的两个步骤,但是不管怎样,IOC被启用是不被检查的,而你需要检查中断标志IOCDFBIT.IOCFCF5在中断中,清除它,然后运行你的代码。
以上来自于百度翻译 以下为原文 are you saying that your code now works. In that you can wake it from sleep mode with a button press, and it moves to normal operation? I am not sure why you have done the following twice if(PIE0bits.IOCIE) But regardless, the IOC being enabled is not to be checked, rather you need to check for the interrupt flag IOCDFbits.IOCCF5 within the interrupt, clear it, and then run your code. |
|
|
|
|
|
我的程序不正常工作,我不能停止在第二次按下返回正常模式
以上来自于百度翻译 以下为原文 My program is not working properly I can not stop at the second press to return to normal mode |
|
|
|
|
|
第一台新闻是怎么做的?你能确认设备处于休眠状态吗?是否正在检查IOC标志?
以上来自于百度翻译 以下为原文 What does the first press do? Can you confirm that the device is in sleep mode? Is the IOC flag being checked? |
|
|
|
|
|
在上电时,μC直接进入休眠模式。当我第一次按下时,它进入正常模式。
以上来自于百度翻译 以下为原文 On power up, the μc goes directly into sleep mode. When I press a first time, it goes into normal mode. |
|
|
|
|
|
|
|
|
|
|
|
CIO,我不明白你的意思。你是说国际奥委会吗?按下按钮时,中断例程将运行。在例行程序中,应该检查IOC标志,如果它被设置,那么你就知道按钮被按下了。然后清除标志并运行代码,直到再次按下按钮。
以上来自于百度翻译 以下为原文 CIO, I don't know what you mean. Do you mean IOC? When the button is pressed the interrupt routine will run. Within the routine the IOC flag should be checked, if it is set, then you know the button has been pressed. You then clear the flag and run your code, until the button is pressed again. |
|
|
|
|
|
|
|
|
|
|
|
为什么两次?但不管怎样,它不是IICIE你想检查,它是IOCIF,中断标志。您要检查是否已经设置了标志,因为在按下按钮时将设置标志。检查是否设置了标志,清除标志,然后运行代码,直到再次按下按钮。
以上来自于百度翻译 以下为原文 why PIE0bits.IOCIE twice? if(PIE0bits.IOCIE) // IT changement d'etat bouton { CPUDOZEbits.IDLEN = 1; IOCCFbits.IOCCF5 = 0; // RAZ flag IT } else if (PIE0bits.IOCIE){ CPUDOZEbits.DOZEN = 1; IOCCFbits.IOCCF5 = 0; // RAZ flag IT } but anyway, it is not IOCIE that you want to check, it is IOCIF, the interrupt flag. You want to check if the flag has been set because the flag will be set when the button is pressed. You check if the flag is set, clear the flag, and run your code until the button is pressed again. |
|
|
|
|
|
我现在不能改变模式,当我按按钮时什么也没发生。
以上来自于百度翻译 以下为原文 I can not change the mode now, when I press the button nothing happens void interrupt ISR () { if(IOCCFbits.IOCCF5 == 1) // IT changement d'etat bouton { CPUDOZEbits.IDLEN = 1; IOCCFbits.IOCCF5 = 0; // RAZ flag IT } } |
|
|
|
|
|
这里有一些建议HTTP://PcPosial.RIC323……PIC.PHP?F=11和t=649
以上来自于百度翻译 以下为原文 Hi Made some suggestions here http://picforum.ric323.co...pic.php?f=11&t=649 |
|
|
|
|
|
你如何确定系统处于正常模式?你可以像这样测试中断。你可能会有一些开关跳动,但是你应该看到一些事情正在发生。
以上来自于百度翻译 以下为原文 how are you determining that the system is in normal mode? You could test the interrupt like this. You might get some switch bouncing, but you should see something happening. void interrupt ISR () { if(IOCCFbits.IOCCF5 == 1) // IT changement d'etat bouton { //LED = !LED; Each time BP is pressed the LED will change. Or measure with meter or oscilloscope IOCCFbits.IOCCF5 = 0; // RAZ flag IT } } |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 10:29 , Processed in 1.171918 second(s), Total 100, Slave 83 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1318