繁体   English   中英

PIC12,MPLAB和UART的嵌入式应用无输出

[英]No output for Embedded application with PIC12, MPLAB and UART

我正在研究RGB LED项目,它由PIC12F1572控制。 我使用的软件是带有HiTech C编译器的MPLAB IDE。 计划是使用串行通信将LED RGB组合数据命令发送到PIC,以存储在一个变量中,使其执行LED闪烁和发光我已经能够建立UART通信。每个功能或步骤I代码都是正确的如果我编译,则通过语法和linux命令行终端工作..如果我尝试在MPLAB中使用寄存器注入进行模拟,它会失败。我也想在模拟中运行它(任何人都知道寄存器注入在MPLAB中是如何工作的?)问题当我尝试调试时,我一起面对。 它编译但不起作用是我的代码:任何关于这个问题的想法或暗示都将受到高度赞赏。 我个人付费,放置代码[分层方式]可能是错的谢谢!

#include <xc.h>
#include "mcc.h"
#include "LED.h"
#include "tmr0.h"
#include "interrupt_manager.h"

void SetLedColor(uint16_t R_color, uint16_t G_color, uint16_t B_color);

void main(void)
{
    uint8_t data, i, j;

    uint16_t R_value, G_value, B_value;
    uint8_t value;
    uint8_t RX_Buffer[FRAMESIZE] ,RGB_data[6] ,HEX_data[6];

    // initialize the device
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();           // Enable the Global Interrupts
    INTERRUPT_PeripheralInterruptEnable();   // Enable the Peripheral Interrupts

    while (1)
    {
        // EUSART_Write(0x61);
        while (!RCIF)
        {
            data = EUSART_Read();                     // Read received character
            for (i = 0; i < FRAMESIZE; i++)
            {
                RX_Buffer[i] = data;
            }

            EUSART_Write(data);
        }

        //check if any data is received

        for (j = 0; j = 5; j++)       // get the RGB value in the separate array
        {
            RGB_data[j] = RX_Buffer[j + 3];
            HEX_data[value] = RGB_data[j] / 16;
        }

        if (RX_Buffer[0] == 'R' && RX_Buffer[FRAMESIZE - 1] == '\n')
        {
            //ASCII to HEX separate values

            // uint32_t number = (uint32_t)strtol(HEX_data, NULL, 16);
            // R_value = number >>16;
            // G_value = (number & 0xffff) >> 8;
            // B_value = (number & 0x0000FF);

            R_value = (uint16_t) atoh(HEX_data[0], HEX_data[1]);
            G_value = (uint16_t) atoh(HEX_data[2], HEX_data[3]);
            B_value = (uint16_t) atoh(HEX_data[4], HEX_data[5]);

        }

        SetLedColor(R_value, G_value, B_value);
    }

}

void SetLedColor(uint16_t R_color, uint16_t G_color, uint16_t B_color)
{
    if (R_color == 0xFF)
    {
        LATAbits.LATA2 = 1;
    }
    else
    {
        LATAbits.LATA2 = 0;
    }

    if (G_color == 0xFF)
    {

        LATAbits.LATA4 = 1;
    }
    else
    {
        LATAbits.LATA4 = 0;
    }
    if (B_color == 0xFF)
    {

        LATAbits.LATA5 = 1;
    }
    else
    {
        LATAbits.LATA5 = 0;
    }
}

因此,直到接收UART帧并回显并从存储数据使LED闪烁,我能够成功,这是我想通过分层方式在这里的主要步骤

#include "mcc_generated_files/mcc.h"
#include <stdlib.h>
#include <stdio.h>
#include "atoh.h"
#include "LED.h"
#define _XTAL_FREQ 16000000
#define FRAMESIZE 19

void main(void)
{
   uint8_t data,i,j,got_char;

   uint8_t R_value, G_value ,B_value;
   uint8_t value;
   uint8_t RX_Buffer[FRAMESIZE];
   uint8_t RGB_data[6] ,HEX_data[6];

    // initialize the device
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();                       // Enable the Global Interrupts
    INTERRUPT_PeripheralInterruptEnable();                   // Enable the Peripheral Interrupts

  while (1)
 {

        if (EUSART_DataReady)
        {
            for (i = 0; i<FRAMESIZE; i++)
            {
                RX_Buffer[i] = EUSART_Read();
                if (RX_Buffer[i] == '\n')
                   break;
            }

            RX_Buffer[i] = '\n';                        //append '\n' at the end of stoaring array for detection of frame
            RX_Buffer[i+1] = '\0';                      // End of an array
            EUSART_WriteAnArrayOfBytes(RX_Buffer);


        if(RX_Buffer[0]=='R' && RX_Buffer[FRAMESIZE-2] == '\n')   //check for correct frame
          {

            LATAbits.LATA2 = 1;
            __delay_ms(2000);
            LATAbits.LATA2 = 0;
            __delay_ms(1000);
          }
        }

  }       

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM