完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,很难找出为什么我的PIC16F503是拖延(冻结,崩溃?)在MimcPy语句上。我没有调试头,所以我不得不依赖基本的调试和模拟器。我通过把一个LATA写在一个LED上,直到它不再工作,把它缩小到这个语句上。在模拟器里,我没有看到任何问题,它运行良好,完全符合我的期望。这发生在我的init函数中,这是第一个主要的东西,所以应该有。在这之前没有任何事情发生。想知道你们这里的专家是否能给我一些关于它停止的想法。我想可能是一个中断,但即使是GIE残疾人,也无法通过这个声明。谢谢!
以上来自于百度翻译 以下为原文 Hello all, Having a hard time figuring out why my PIC16F1503 is stalling (freezing, crashing?) on a memcpy statement. I don't have a debug header, so I'm forced to rely on basic debugging and the simulator. I narrowed it down to this statement by moving a LATA write around that turns on an LED until it no longer worked. In the simulator I'm not seeing any issues, it runs fine and does exactly what I expect it to. This happens within my Init function, which is the very first thing in main so there shouldn't be anything executing before this. Wondering if any of you experts here could give me some ideas on what could be causing it to stop. I thought maybe an interrupt, but even with GIE disabled it fails to get past that statement. Thank you! #include #include #include extern volatile char lcd_buffer[21]; void Init(void){ // Set Processor Frequency // OSCCON - Oscillator Control Register OSCCON = 0b01101000; // Set Data Port Input/Output ANSELA = 0x00; // Turn off Analog Input functionality LATA = 0x00; // Set default Port A output values TRISA = 0x23; // Set bits 2 and 4 as output ANSELC = 0x00; // Turn off Analog Input functionality TRISC = 0xFF; // Set all of Port C as input // Configure I2C Registers // SSP1STAT - SSP Status Register SSP1CON1 = 0x28; // SSP1CON2 - SSP Control Register 2 SSP1CON3 = 60; // SSP1ADD - MSSP Address and Baud Rate Register SSP1ADD = 0x09; // Enable MSSP (I2C) Interrupts PIE1bits.SSP1IE = 1; // Enable Global Interrupts INTCONbits.GIE = 1; INTCONbits.PEIE = 1; // Initialize the LCD const uint8_t lcd_init1[] = {0x00,0x38,0x39,0x14,0x78,0x5E,0x6D}; memcpy(lcd_buffer,lcd_init1,7); // More code follows, but this is where the LATA command fails to execute } |
|
相关推荐
8个回答
|
|
好的,你有一个声明LCDYBuff:但是这个变量的定义在哪里?基本上,声明(任何时候使用Extn都是声明)不分配内存,只有定义才这样做。你需要的地方:
以上来自于百度翻译 以下为原文 OK you have a declaration for lcd_buffer: extern volatile char lcd_buffer[21]; but where is the definition of this variable? Basically, declarations (anytime you use extern it is a declaration) DO NOT allocate memory only the definition does that. Somewhere you need: volatile char lcd_buffer[21]; |
|
|
|
LCDY缓冲区定义在哪里?我不希望你的代码链接到它的当前状态。
以上来自于百度翻译 以下为原文 Where is lcd_buffer defined? I wouldn't expect your code to link in its current state. |
|
|
|
init函数在它自己的C文件中。LCDAL缓冲区在main中定义,以及ISR使用的其他全局变量。这里是主文件。
以上来自于百度翻译 以下为原文 The init function is in it's own c file. lcd_buffer is defined in main, along with some other global variables used by the ISR. Here is the main file. // Include PIC16F1503 CONFIG register settings // These control clock selection, watchdog disable, etc #include "pic16f1503config.h" // Compiler include file #include // C Standard Includes #include #include // Project Specific Includes #include "Init.h" #include "lcd_funcs.h" #include "AlarmClock.h" // Global Variables volatile l_state lcd_state; volatile uint8_t msg_length; volatile unsigned char *lcd_msg; uint8_t i2c_addr; volatile char lcd_buffer[21]; void main(void) { // Initialization of MCU & peripherals Init(); while(1){ // The main loop of the program runs forever lcd_buffer[0]=0x40; const char testmsg[] = "This is a test"; memcpy(lcd_buffer+1,testmsg,14); send2lcd(lcd_buffer,15,lcd_w); while(1){ // Basically stop for test } } return; } void interrupt pic16_int (void) { if(SSP1IF == 1){ // If MSSP module generated the interrupt, clear the flag and process LATA = 0x10; SSP1IF = 0; switch(lcd_state) { case lcd_idle: // Do Nothing break; case lcd_start: // Start Condition Completed, send address SSP1BUF = i2c_addr; // Then go to next state if(i2c_addr & 0x01){ // LSB '1' = TX lcd_state = lcd_rx; } else { // LSB '0' = RX lcd_state = lcd_tx; } break; case lcd_tx: // Loading buffer starts transmission SSP1BUF = *lcd_msg; lcd_msg++; msg_length--; if(msg_length == 0){ lcd_state = lcd_stop; } break; case lcd_rx: // Grab received byte break; case lcd_stop: // Set Stop Bit SSP1CON2bits.PEN = 1; lcd_state = lcd_finish; break; case lcd_finish: // I2C Transaction is completed, go to idle lcd_state = lcd_idle; } } return; } |
|
|
|
|
|
|
|
我不希望“const”会影响在那个上下文中生成的代码,但是在没有“const”的情况下尝试它。
以上来自于百度翻译 以下为原文 I wouldn't expect "const" to affect the generated code in that context, but try it without "const". |
|
|
|
const是告诉编译器把它放到程序存储器和RAM中的东西。由于PIC16F503只有128个字节的RAM,所以我希望避免在可能的时候使用它。不管怎样,我试着移除它,但仍然会粘在MimcPy线上。
以上来自于百度翻译 以下为原文 const is what tells the compiler to put it into program memory vs RAM. Since the PIC16F1503 only has 128 bytes of RAM I'd like to avoid using it when possible. Regardless, I tried removing it but still gets stuck on that memcpy line. |
|
|
|
我很惊讶XC8允许你在那里定义变量。它是一个“C89”编译器,其中变量定义只能出现在块的开始之前,在任何可执行代码之前。
以上来自于百度翻译 以下为原文 I'm surprised XC8 allowed you to define the variable there. It is a "C89" compiler, where variable definitions can only occur at the start of a block, before any executable code. Have you looked at the LST file output to see what assembler has been generated there? |
|
|
|
我没有立即看到任何东西,但我并不熟悉PIC指令集(我来自HC08的)。
以上来自于百度翻译 以下为原文 I don't see anything immediately, but I'm not all that familiar with the PIC instruction set (I came from HC08's). 831 ;Init.c: 76: const uint8_t lcd_init1[] = {0x00,0x38,0x39,0x14,0x78,0x5E,0x6D}; 832 ;Init.c: 77: __builtin_memcpy(lcd_buffer,lcd_init1,7); 833 006B 3020 movlw low (_lcd_buffer| 0) 834 006C 0086 movwf 6 835 006D 0187 clrf 7 836 006E 3015 movlw low (Init@lcd_init1| (0+32768)) 837 006F 0084 movwf 4 838 0070 3081 movlw high (Init@lcd_init1| (0+32768)) 839 0071 0085 movwf 5 840 0072 3007 movlw 7 841 0073 00F6 movwf ??_Init 842 0074 0876 movf ??_Init,w 843 0075 1903 skipnz 844 0076 287B goto l635 845 0077 u10m0: 846 0077 0012 moviw fsr0++ 847 0078 001E movwi fsr1++ 848 0079 0BF6 decfsz ??_Init,f 849 007A 2877 goto u10m0 850 007B l635: 851 852 ;Init.c: 78: send2lcd(lcd_buffer,7,0x78); And the constant is here: 507 psect stringtext2 508 0115 __pstringtext2: 509 0115 Init@lcd_init1: 510 0115 3400 retlw 0 511 0116 3438 retlw 56 512 0117 3439 retlw 57 513 0118 3414 retlw 20 514 0119 3478 retlw 120 515 011A 345E retlw 94 516 011B 346D retlw 109 517 011C __end_ofInit@lcd_init1: |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
729浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
628浏览 0评论
526浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 12:58 , Processed in 1.254803 second(s), Total 91, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号