Ejemplo n.º 1
0
void main(void) 
{

    OSCTUNEbits.PLLEN = 1;
    LCDInit();
    LCDClear();
    InitPins();
    ConfigPeriph();
    ConfigInterrupts();

    while (1) {
	    received = ReadSerial();
	    LCDClear();
            switch(received) {
                case 'a':
                         received2 = ReadSerial();  
                         sprintf(output,"Received char:%c",received2); 
			/*
			 *  FIXME : PIC18 doesn't transmit back to RPi
			 *  python script hangs on serial.read(1)
			 *  Same behavior with cat -A /dev/ttyACM0 
			 *
			 * 
			 * _delay(2); // 2 cycle delay
			 *while(!PIR1bits.TX1IF);
			 *sprintf(output,"TRANSMIT");
			 *LCDWriteLine(output,0);
			 *TXREG1=received2;
                         *
			 */
			 break ;
                case 'b':
                         potentiometer = ReadPot();
                         sprintf(output,"Pot value: %d", potentiometer);
                         LATD =~ LATD;
                         break;
                  
                case 'c':
			   received2=ReadSerial();
			   sprintf(output,"Set LED to 0x%X",received2);
                           LATD = received2;
                           break;
                default:
                    sprintf(output, ">>UNKNOWN %c",received);
                    break;
             
            }
        LCDWriteLine(output,0);
	
	
    }
}
Ejemplo n.º 2
0
int32_t main(void)
{
    int compileErr;
    int executionErr;
    volatile int value;

    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);
    ConfigInterrupts(true);

    platform_init();

    // Initialise the Lua state
    lua_State *L = luaL_newstate();

    // Load the Lua libraries
    luaL_openlibs(L);

    lua_pushcfunction(L, cCall);
    lua_setglobal(L, "cCall");

    // Use strlen(script) when using uncompiled scripts.
    //compileErr = luaL_loadbuffer(L, script, strlen(script), "Script");
    // Use section size from linker file when using byte code scripts.
    compileErr = luaL_loadbuffer(L, script, 0x01000, "Script");
	executionErr = lua_pcall(L, 0, 0, 0);

    if(!compileErr && !executionErr)
    {
        for(;;)
        {
            lua_getglobal(L, "HeapUsage");
            executionErr = lua_pcall(L, 0, 1, 0);
            if(!executionErr)
            {
                value = (int)lua_tonumber(L, -1);
                lua_pop(L, 1);
            }
            
            lua_getglobal(L, "CallToC");
            lua_pushnumber(L, 11);
            lua_pushnumber(L, 22);
            
            executionErr = lua_pcall(L, 2, 0, 0);
            if(!executionErr)
            {
                value = (int)lua_tonumber(L, -1);
            }
        }
    }
    return (0);
}