完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
海都…我写了一个简单的程序,在PIC16F87A中用MPLAB编写高技术-C编译器,一个接一个地闪烁8个LED。当我们使用while循环时,重复执行直到失败为止。我还没有给出.(1)循环(无限运行,以重复执行),那么它应该在最后一个led闪烁之后停止。但是它重复执行就像(1)循环一样。有人解释这个…当我们在没有使用(无限)循环的主函数中执行程序时会发生什么?
以上来自于百度翻译 以下为原文 Hai all.. I wrote a simple program to blink 8 led's one by one in PIC16F877a with MPLAB writing HighTech-C compiler. When we use while loop it repeats the execution until it fails. I haven't given the while(1) loop (which runs infinitely, to repeat the execution) , then it should stop after blinking last led. But it's repeat the execution like while(1) loop.. Anyone explain this ... What happens when we execute the program in main function without using (infinite) loops.... |
|
相关推荐
15个回答
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
示例启动代码;;;;;用于dsPIC30 C编译器的C运行时启动模块;;(c)版权200220042007微芯片技术,保留所有权利;;;;主版本,具有数据初始化支持;;;当选择--data-init;;选项时,链接器加载此版本;;;;参见文件crt1。s用于备用版本,而不支持;;数据初始化。;;;;Entry_reset在设备重置时进行控制;;执行以下操作:;;;1。初始化堆栈和堆栈极限寄存器;2。初始化PSV窗口,如果y-常数长度>0;3。处理数据初始化模板;4。在链接器脚本中的特定地址调用用户的_main入口点;;;分配给..init,这可以被分配;;;;;;默认情况下支持main()的零参数形式;;如果定义了符号_u ARGV,则支持main()的两参数形式;;;;;取消注释以下行以定义符号_u ARGV:;.equiv_u ARGV,1;.equ_30F2010,1.include"p30f2010.inc"..init,code..u resetPR。ififdef_C30ELF.I_C30ELF.type_uC30ELF.type_resetPRI,@function_endif_endif_resetPRI,@function.ififififififIF_C30ELF.type_C30FI_resetFI_resetPRI_resetPRI,@function_C30ELF_resetPRI_resetPRI_resetPRI_resetPRI._resetPRI,@function_reseuuu_reseuu_resetifififififififififififififififififfffffFFFFFIIIIIIIIIIFFFFFFIIIIIIIIIIffffff0._reset:不返还处理器);;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; u_psv_ini;u_data_ini; u_data_ini;u_data_ini;\u init;;;;;;u_psv_init;u_init;u_data_init;u init;u data_init;u init_init;u init_init;u init;u init;u_init;u init;u init;u_init;;u_init_init;u init;;;;;;ARGV rcall_main;调用双参数main()setup.else call_main;调用用户的main().endif.pword 0xDA4000;停止模拟器重置;重置处理器。
以上来自于百度翻译 以下为原文 Sample start up code. ;; ;; C Run-time startup module for dsPIC30 C compiler. ;; (c) Copyright 2002,2004,2007 Microchip Technology, All rights reserved ;; ;; Primary version, with data initialization support. ;; The linker loads this version when the --data-init ;; option is selected. ;; ;; See file crt1.s for the alternate version without ;; data initialization support. ;; ;; Entry __reset takes control at device reset and ;; performs the following: ;; ;; 1. initialize stack and stack limit register ;; 2. initialize PSV window if __const_length > 0 ;; 3. process the data initialization template ;; 4. call the user's _main entry point ;; ;; Assigned to section .init, which may be allocated ;; at a specific address in linker scripts. ;; ;; Supports the zero-parameter form of main() by default. ;; If the symbol __ARGV is defined, supports the two-parameter ;; form of main(). ;; ;; Un-comment the following line to define symbol __ARGV: ;; .equiv __ARGV,1 ;; .equ __30F2010, 1 .include "p30f2010.inc" .section .init,code .global __resetPRI .ifdef __C30ELF .type __resetPRI,@function .endif __resetPRI: .weak __reset .ifdef __C30ELF .type __reset,@function .endif __reset: ;; ;; Initialize stack, PSV, and data ;; ;; registers used: w0 ;; ;; Inputs (defined by user or linker): ;; __SP_init ;; __SPLIM_init ;; ;; Outputs: ;; (does not return - resets the processor) ;; ;; Calls: ;; __psv_init ;; __data_init ;; _main or __main ;; mov #__SP_init,w15 ; initialize w15 mov #__SPLIM_init,w0 ; mov w0,_SPLIM ; initialize SPLIM nop ; wait 1 cycle rcall __psv_init ; initialize PSV rcall __data_init ; initialize data ; clears w0, so ARGC = 0 .ifdef __ARGV rcall __main ; call two-parameter main() setup .else call _main ; call user's main() .endif .pword 0xDA4000 ; halt the simulator reset ; reset the processor .end |
|
|
|
|
|
好的,兄弟。因此,它一次又一次地重置&执行工作,直到我们以.(1)结束;因此,为什么人们使用诸如.(1)、(;)&all……这样的无限循环执行多次。然后,代替我们不需要放置.(1),bcoz没有.(1)it(主函数本身)像无限循环实际所做的那样工作……我希望你能理解我想要传达的东西…
以上来自于百度翻译 以下为原文 Ok bro. so, it resets & do the work again and again until we terminate by while(1); So, multiple executions why people go with infinite loops like while(1) , for(;;) & all.... Then instead of we no need to put while(1) , bcoz without while(1) it (main function itself) do the work like what infinite loops actually does... I hope you understand what i'm trying to convey... |
|
|
|
|
|
|
|
|
|
|
|
不要这样做。为什么要让它停止运行并重新运行启动代码。要么您希望代码继续执行操作,在这种情况下,您有一个围绕希望遍历的代码的“超级循环”,要么您不想有效地停止执行任何操作,所以您在代码的末尾放置一个“什么都不做”循环。代码。
以上来自于百度翻译 以下为原文 Don't do it. Why let it go off and run the startup code again. Either you want your code to keep doing things, in which case you have a "super loop" surrounding the code you want to run over and over, or you want ot to effectively stop doing anything, so you put a "do nothing" loop at the end of your code. |
|
|
|
|
|
如果启动代码与旧C18编译器中的这个类似:启动无穷循环调用初始化,然后调用main。我敢肯定,您不想在每次主“结束”时都这样做……
以上来自于百度翻译 以下为原文 What if the startup code is like this one from the old C18 compiler: /* Copyright (c)1999 Microchip Technology */ /* MPLAB-C18 startup code */ /* external reference to __init() function */ extern void __init (void); /* external reference to the user's main routine */ extern void main (void); /* prototype for the startup function */ void _entry (void); void _startup (void); extern near char __FPFLAGS; #define RND 6 #pragma code _entry_scn=0x000000 void _entry (void) { _asm goto _startup _endasm } #pragma code _startup_scn void _startup (void) { _asm // Initialize the stack pointer lfsr 1, _stack lfsr 2, _stack clrf TBLPTRU, 0 // 1st silicon doesn't do this on POR bcf __FPFLAGS,RND,0 // Initalize rounding flag for floating point libs _endasm //################################################### //################################################### //################################################### loop: __init (); // If user defined __init is not found, the one in clib.lib will be used main (); // Call the user's main routine goto loop; //################################################### //################################################### //################################################### } /* end _startup() */ The startup endless loop calls the initialization and then the main. I'm pretty sure you do not want to do this every time main "ends"... |
|
|
|
|
|
主回路也做同样的无限循环,但它另外复位和启动(初始化)再次…而(1)或(;;;)循环意味着重复执行特定的任务,但是在这里启动(初始化)只发生一次。因此,为了避免重置和重复启动,我们进行无限循环…这就是我理解的……我说的对吗???????
以上来自于百度翻译 以下为原文 main loop also do the same like infinite loops but it additionally resets & startup (initialisation) again.... while(1) or for(;;) loops means do the particular task repeatedly , but here startup (initialisation) happens only once.. so, to avoid resets & repeated startups we go for infinite loops... This is what i understood... Am i Right????? |
|
|
|
|
|
我不懂代码。但是,我澄清了一件事,就是如果我不终止循环或者不放一个无限循环,初始化每次都会发生……所以,我不想每次循环重置时初始化。我说的对吗?
以上来自于百度翻译 以下为原文 i don't understand the code . But one thing i cleared is initialisation happens every time if i don't terminate the loop or don't put a infinite loop... So, i don't want initialise every time when the loop resets... Am i right? |
|
|
|
|
|
可能是;-)通常在一个uC程序中,在所有的初始化内容进入无尽的循环之后,运行直到有人拔掉插头。
以上来自于百度翻译 以下为原文 May be ;-) Usually in a uC program after all the initialization stuff an endless loop is entered that runs until someone pulls the plug. |
|
|
|
|
|
YESCHAR数组[8 ];int计数=0;char限制=10;无效主(){ BLAH BAH}:你认为变量init是从哪里来的?
以上来自于百度翻译 以下为原文 Yes Char array[8]; int Count = 0; Char Limit = 10; Void main() { blah blah } where do you think the variable init comes from? |
|
|
|
|
|
|
|
|
|
|
|
你叫它终止循环。我会叫它停止你的程序失控和重置。它没有终止循环。正是编写代码来做你想做的事情。不要在嵌入式系统上从主服务器返回。没有返回到的操作系统。
以上来自于百度翻译 以下为原文 You are calling it terminate the loop. I would call it stopping your program from running away crashing and resetting. It is not terminating a loop. It is writing code proper to do what you want. Don't return from main on an embedded system. There is no operating system to return to. |
|
|
|
|
|
正常的程序执行流程是重置向量分支到启动代码;启动代码执行所有的初始化,然后分支到main()函数。PIC设备从不停止执行代码指令,除非在RESET或SLEEP模式下。因此,在主体()中没有无限循环,当它到达主体()的末尾时,你认为它会在哪里?取决于编译器,离开main()的末尾可以分支到重置向量,分支到启动代码,或者分支回到main()的开始。也就是说,如果允许它结束,主()中的代码将明显重复。因此,嵌入代码中的主()函数应该总是有无限循环(或休眠和等待重置)。
以上来自于百度翻译 以下为原文 Normal program execution flow is reset vector branches to the startup code; the startup code does all the initialization, and then branches to the main() function. PIC devices never stop executing code instructions, except in RESET or SLEEP mode. So, without an infinite loop in main(), where do you think it will go when it reaches the end of main()? Dependent on the compiler, going off the end of main() may branch to the reset vector, branch to the startup code, or branch back to the beginning of main(). That is, the code in main() will evidently repeat if you allow it to go off the end. Hence, the main() function in an embedded code should always have an infinite loop (or sleep and wait for a reset). |
|
|
|
|
|
是的,先生。我想终止。如果我没有放无限循环,它会崩溃PIC单片机吗??????????我不明白。你的意思是终止循环或者放无限循环…但不允许重置吗?????
以上来自于百度翻译 以下为原文 yeah sir. I want to terminate. If i have not put infinite loop , will it crash pic mcu??????? I can't understand. You means terminate the loop or put infinite loop... but don't allow the reset ???? |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1123浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 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 01:13 , Processed in 1.085753 second(s), Total 103, Slave 84 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
242