完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
所有的,IM新的PIC发展,但不是C。我已经和它战斗了一段时间,好像我错过了一些愚蠢的事情…我试图把一个简单的“AT rn”发送到一个连接的SIM800 L中,然后返回一个“OK”。因为我只有一个UART,所以我试图在缓冲器上做一个监视,停止执行,看看调制解调器中的“OK”是否在缓冲器中。(我对其他的想法开放调试)编译器XC8这里是我的代码…IVE尽可能地把它拆了……Greenie McGreen。
以上来自于百度翻译 以下为原文 All, Im new to PIC Development, but not C... I've been fighting with this for awhile and it seems i'm missing something stupid... Im trying to send in a simple "ATrn" into a connected SIM800L and get back an "OK". Since i only have the one UART i'm trying to do a watch on a buffer, stop execution and see if "OK" is in the buffer from the modem. (i'm open to other ideas to debug this) Compiler XC8 Here is my code... Ive stripped it down as much as possible... #define _XTAL_FREQ 10000000 //#define USE_AND_MASKS #if defined(__XC) #include #elif defined(HI_TECH_C) #include #elif defined(__18CXX) #include #endif #include #include #include #include #include #include #include #include "system.h" /* System funct/params, like osc/peripheral config */ #include "user.h" /* User funct/params, such as InitApp */ /******************************************************************************/ /* User Global Variable Declaration */ /******************************************************************************/ void delay_100ms(int value); char UART_Init(const long int baudrate); char UART_TX_Empty(); char UART_Data_Ready(); char UART_Read(); void UART_Read_Text(unsigned int length); void UART_Write(char data); void UART_Write_Text(char *text); char *Output[20]; int d; int i_delay; void main(void) { ConfigureOscillator(); InitApp(); TRISBbits.TRISB6 = 0; //TX pin set as output TRISBbits.TRISB7 = 1; //RX pin set as input TRISBbits.TRISB5 = 0; INTCONbits.GIE = FALSE; UART_Init(9600); delay_100ms(2); //200ms delay UART_Write_Text("ATrn"); delay_100ms(10); //200ms delay UART_Read_Text(5); for(;;) { // flash an LED so i can see the loop is running... PORTBbits.RB5 = 1; delay_100ms(10); // 1 Second Delay PORTBbits.RB5 = 0; delay_100ms(10); // 1 Second Delay } } void delay_100ms(int value) { d = value*10; i_delay = 0; while( i_delay < d ) { __delay_ms(10); i_delay++; } } char UART_Init(const long int baudrate) { unsigned int x; x = (_XTAL_FREQ - baudrate*64)/(baudrate*64); if(x>255) { x = (_XTAL_FREQ - baudrate*16)/(baudrate*16); BRGH = 1; } if(x<256) { SPBRG = x; SYNC = 0; SPEN = 1; CREN = 1; TXEN = 1; TX9 = 0; RX9 = 0; return 1; } return 0; } char UART_TX_Empty() { return TRMT; } char UART_Data_Ready() { return RCIF; } char UART_Read() { if(OERR) // check for Error { CREN = 0; //If error -> Reset CREN = 1; //If error -> Reset } while(!RCIF){ return RCREG; } } void UART_Read_Text(unsigned int length) { for( int i=0;i } void UART_Write(char data) { while(!TRMT) { TXREG = data; } } void UART_Write_Text(char *text) { while( *text ) { UART_Write(*text++); } } The config stuff #pragma config OSC = HS // Oscillator Selection bits (HS Oscillator) #pragma config FSCM = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode disabled) // CONFIG2L #pragma config PWRT = ON // Power-up Timer Enable bit (PWRT enabled) #pragma config BOR = ON // Brown-out Reset Enable bit (Brown-out Reset enabled) #pragma config BORV = 27 // Brown-out Reset Voltage bits (VBOR set to 2.7V) // CONFIG2H #pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit)) #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768) // CONFIG3H #pragma config MCLRE = ON // MCLR Pin Enable bit (RA5 input pin enabled, MCLR disabled) // CONFIG4L #pragma config STVR = OFF // Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset) #pragma config LVP = OFF // Low-Voltage ICSP Enable bit (Low-Voltage ICSP disabled) // CONFIG5L #pragma config CP0 = OFF // Code Protection bit (Block 0 (00200-0007FFh) code-protected) #pragma config CP1 = OFF // Code Protection bit (Block 1 (000800-000FFFh) code-protected) // CONFIG5H #pragma config CPB = OFF // Boot Block Code Protection bit (Boot Block (000000-0001FFh) code-protected) #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected) // CONFIG6L #pragma config WRT0 = OFF // Write Protection bit (Block 0 (00200-0007FFh) not write-protected) #pragma config WRT1 = OFF // Write Protection bit (Block 1 (000800-000FFFh) not write-protected) // CONFIG6H #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected) #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write-protected) #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected) // CONFIG7L #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (00200-0007FFh) not protected from table reads executed in other blocks) #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (000800-000FFFh) not protected from table reads executed in other blocks) // CONFIG7H #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from table reads executed in other blocks) #pragma config DEBUG = ON Thanks Mr Greenie McGreen... |
|
相关推荐
1个回答
|
|
|
如果你知道你正在使用XC8,那么用JuSube替换所有这一切,去掉这一行,你的代码根本不应该触碰到这一点。XC8是哪一个版本?您似乎在部分地使用外围库,因为在UARTHAREAD函数中,自从版本1.34以来还没有包含XC8,这个代码应该是BEI。E.返回不应该在里面。您尝试过先连接到PC吗?有效调试的秘诀是一次解决一个问题。尝试同时发送和接收意味着你不知道哪一个不能工作。试着先发送到PC,这样你就可以知道波特率是否正确。
以上来自于百度翻译 以下为原文 If you know you are using XC8, then replace all this #if defined(__XC) #include #elif defined(HI_TECH_C) #include #elif defined(__18CXX) #include #endif with just #include Also, get rid of this line #pragma config DEBUG = ON Your code should NOT touch that bit at all. Which version of XC8 is it? You appear to be partly iusing the peripheral libraries, which haven't been included with XC8 since version 1.34. In your UART_read function, this code: while(!RCIF){ return RCREG; } should be while(!RCIF){} return RCREG; i.e. the return should not be inside the while. Have you tried connecting to a PC first? The secret to efficient debugging is to fix one problem at a time. Trying to test send and receive at the same time means you don't know which one isn't working. Try sending to a PC first, which lets you see if your baud rate is correct. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
454 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3529 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1094浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
460浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 17:14 , Processed in 1.531634 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1280