Skip to content

Doesn't work with PIC18F27K40 #2

Description

@monemahmed

Hi I have tried to use your library with PIC18F27K40. But it doesn't work. The library worked in Proteus simulation with PIC18LF46K80. But same code doesn't work with PIC18F27K40 hardware. it toggle six times. that means JSON_DECODER_fromString() doesn't return JSON_DECODER_OK. Please Help.

Here is my code:
#include "mcc_generated_files/mcc.h"
#include "json_decoder.h"
#include<stdlib.h>
#include<string.h>
#define LED "{"blink":1,"setHigh":2,"setLow":0}"

/*
Main application
*/
jsonNode_t *root;
int blink, setHigh, setLow;
char str[64];
jsonDecoderStatus_t ret;

void toggle_times(int n) {
int i;
for (i = 0; i < n; i++) {
LED_RED_Toggle();
LED_GREEN_Toggle();
LED_BLUE_Toggle();
__delay_ms(1000);
}
}

void set_all_low() {

LED_RED_SetLow();
LED_GREEN_SetLow();
LED_BLUE_SetLow();

}

void set_all_high() {

LED_RED_SetHigh();
LED_GREEN_SetHigh();
LED_BLUE_SetHigh();

}

void main(void) {
// Initialize the device
SYSTEM_Initialize();
memcpy(str, LED, sizeof (LED));
ret = JSON_DECODER_fromString(str);
if (JSON_DECODER_OK != ret) {
toggle_times(6);
set_all_high();
}

JSON_DECODER_getRoot(&root);
JSON_DECODER_getNumber(root, "setHigh", &setHigh);

JSON_DECODER_getNumber(root, "blink", &blink);

JSON_DECODER_getNumber(root, "setLow", &setLow);

switch (setHigh) {
    case 0:
        LED_RED_SetHigh();
        break;
    case 1:
        LED_GREEN_SetHigh();
        break;
    case 2:
        LED_BLUE_SetHigh();
        break;
}
switch (setLow) {
    case 0:
        LED_RED_SetLow();
        break;
    case 1:
        LED_GREEN_SetLow();
        break;
    case 2:
        LED_BLUE_SetLow();
        break;
}



while (1) {
    switch (blink) {
        case 0:
            LED_RED_Toggle();
            break;
        case 1:
            LED_GREEN_Toggle();
            break;
        case 2:
            LED_BLUE_Toggle();
            break;
    }
    __delay_ms(1000);
    // Add your application code
}

}
/**
End of File
*/_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions