完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,来自社区的人,我再次在这里寻求帮助,因为我正处于一个我想知道你的想法的情况。我有一个3,PIC18F27 K42和一个PIC18F45 K22。我找到了一个例子,用PU18F450使用UART向终端发送字符串。我用PIC18F45 K22测试了这个代码,它是一个成功的测试。它工作得很好。问题是当我调整这个代码与我的PIC18F27 K42一起工作时。该代码不发送任何数据到我的终端(在我的情况下,ARDUINO IDE串行终端监视器),我有一个简单闪烁的LED连接到MCU只是作为一个“生命状态”的微控制器在测试过程中。我想分享我的代码,看看是否有人可以看到是否有什么不对我的当前设置,可能是寄存器设置错误或者别的什么。我在MPLAB X IDE中看到,PICIT 3似乎有一个beta版本来支持这个微控制器(PIC18F27 K42),因为当我选择编译器时,颜色是黄色的,但是列表中的任何编译器都具有相同的颜色统计。这是非常奇怪的,所以我假设在我的测试过程中可能会导致失败。但是,我闪烁的LED工作得很好。你知道出了什么问题吗?我将分享我的代码来展示它的全部内容。谢谢你们的时间,我希望能得到你们的帮助。这是PIC18F45 K22的代码:这是PIC18F27 K42: 以上来自于百度翻译 以下为原文 Hello people from the community I'm here again looking for some help because I'm in a situation that I want to know your thoughts about it. I have a Pickit 3, PIC18F27K42 and a PIC18F45K22. I found an example to send strings to a terminal using UART with PIC18F4550. I tested this code with the PIC18F45K22 and it was a successful test. It worked perfectly. The problem is when I'm adapting this code to work with my PIC18F27K42. The code is not sending any data to my terminal (in my case, Arduino IDE Serial terminal monitor) I have a simple blinking LED attach to the MCU just as a "life status" of the microcontroller during test. I want to share my code and see if any one can see if is something wrong with my current setup, maybe is something wrong with the registers setup or something else. I saw that in MPLAB X IDE it seems that Pickit 3 has a beta version to support this microcontroller (PIC18F27K42) because the colour is YELLOW when I'm selecting the compiler, but any compiler from the list has the same colour status and it's very weird, so I assume that maybe is causing a failure during my tests. However, my blinking led is working perfectly. Do you know what's going wrong? I would share my code to show what it is all about. Thank you for time and I hope to get some help from you guys. This is the code for PIC18F45K22: #include #include #include #include "config.h" char UART_Init(const long int baudrate) { // Setting up UART registers RCSTAbits.SPEN = 0; // Serial port disabled unsigned int x; x = (_XTAL_FREQ - baudrate * 64) / (baudrate * 64); //SPBRG for Low Baud Rate if (x > 255) //If High Baud Rage Required { x = (_XTAL_FREQ - baudrate * 16) / (baudrate * 16); //SPBRG for High Baud Rate TXSTAbits.BRGH = 1; //Setting High Baud Rate } if (x < 256) { SPBRG = x; //Writing SPBRG Register TXSTAbits.SYNC = 0; //Setting Asynchronous Mode, ie UART RCSTAbits.SPEN = 1; //Enables Serial Port //TRISCbits.RC7 = 1; //As Prescribed in Datasheet TRISCbits.RC6 = 0; //As Prescribed in Datasheet //RCSTAbits.CREN = 1; //Enables Continuous Reception TXSTAbits.TXEN = 1; //Enables Transmission TXIE = 1; // Enable tx interrupts //RCIE = 1; // Enable rx interrupts } } void initPIC(void) { OSCTUNEbits.PLLEN = 1; // enable PLL (4 times) OSCCON2bits.MFIOSEL = 0; // 111: 16 MHz < OSCCONbits.IRCF2 = 1; // 110: 8 MHz OSCCONbits.IRCF1 = 1; // 101: 4 MHz OSCCONbits.IRCF0 = 1; // 100: 2 MHz ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x00; TRISAbits.TRISA0 = 0; // PIN RA0 as OUTPUT UART_Init(9600); LATAbits.LATA0 = 0x00; } char UART_TX_Busy() { return (char) !TXSTAbits.TRMT; } void UART_Write(char info[]) { //while(!U1FIFObits.TXBF); //U1TXB = data; //while(U1FIFObits.TXBF); // wait until all bytes are transmitted int i; for (i = 0; info != ' |