uint8_t MOTEapp_GetDataRateSetting(void)
{
    uint8_t readData;
    readData = DATAEE_ReadByte(0x10);
    moteApp_delayms(20);
        
    return readData;
}
Exemple #2
0
void setup()
{
    // load last used offset from eeprom
    preloadOffsetH = DATAEE_ReadByte(0);
    preloadOffsetL = DATAEE_ReadByte(1);
    preloadOffset = (preloadOffsetH << 8) 
                                    + preloadOffsetL;
    
    // call system setup
    SYSTEM_Initialize();
    
    preloadOffset = 0;
            
    // Enable interrupts!!
    INTCONbits.PEIE = 1;
    INTCONbits.GIE  = 1;
    
    toggle = true;
}
Exemple #3
0
void ComputeStorageData(void) {
    for (int i = 0; i < NUMOFBYTES; i++) {
        data[i] = DATAEE_ReadByte(i);
    }
    Currentcomp[0] = ((data[0] << 8) | data[1]);
    Currentcomp[1] = ((data[2] << 8) | data[3]);
    Currentcomp[2] = ((data[4] << 8) | data[5]);
    Currentcomp[3] = ((data[6] << 8) | data[7]);
    Currentcomp[4] = ((data[8] << 8) | data[9]);
    Currentcomp[5] = ((data[10] << 8) | data[11]);

}
Exemple #4
0
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();
    EUSART_Initialize();
    EPWM1_Initialize();

    uint16_t dutyValue;
    uint16_t angle;
    uint8_t c;
    uint8_t buf[32] = {'\0'};
    uint8_t cnt = 0;
    
    // read angle from EEPROM
    angle = (uint16_t)DATAEE_ReadByte(0);
    // printf("read angle from EEPROM: %d\n", angle);
    dutyValue = calc_duty(angle);
    EPWM1_LoadDutyValue(dutyValue);
            
    while (1)
    {
        __delay_ms(500);
        LATCbits.LATC4 ^= 1;

        do {
            c = EUSART_Read();
            if (c == '\n') {
                buf[cnt] = '\0';
                cnt = 0;
                if (strcmp(buf, "w") == 0) {
                    DATAEE_WriteByte(0, (uint8_t)angle);
                    // printf("write the last angle onto EEPROM: %d\n", angle);
                } else {
                    angle = atoi(buf);
                    dutyValue = calc_duty(angle);
                    EPWM1_LoadDutyValue(dutyValue);
                }
            } else {
                buf[cnt++] = c;
            }
        } while (EUSART_DataReady);

        CLRWDT();
    } 
}
Exemple #5
0
// Application Start
void main(void)
{
    // Prepare Application; MCC generated code
    SYSTEM_Initialize();
    // Custom Initializations
    
    
    
    /*   
     *   watchdog timer 
     *   configured for 131s timeout
     * 
     */
    //WDTCONbits.SWDTEN = 1; // enable watchdog
    //ClrWdt();
    
    
    
    oled_init();         // Dispaly
    USBDeviceInit();	// usb_device.c.  Initializes USB module SFRs and firmware
                        // variables to known states.
    
    
    
    
    USBDeviceAttach();
    // Interrupts Enabled
    PEIE = 1;
    GIE = 1;
    
    // Test Hardware
    moteApp_delayms(300);    
    modemResync();
    moteApp_delayms(300);
//    moteApp_clearCommand();
//    moteApp_delayms(100);   
    
    powerOnStatus = DATAEE_ReadByte(0x00);
#if 0
    if ( powerOnStatus != 0x55)
    {
        test_powerup();
        DATAEE_WriteByte(0x00, 0x55);
    }
#endif

    // Default to USB
    operationType = USB;   // Mode State
    USBapp_handlerState(USB_STARTUP);
    
    
    
    // Initial Display Print
    oled_clear();
    oled_putString("Scriptr IoT-X",0,0);
    oled_putString(" Dev: S1 ",0,1);
    oled_putString("   build 006   ",0,3);
    moteApp_delayms(700);
   
    // Application Loop
    while(1)
    {
        // Handle USB or Solo Mode
        switch (operationType)
        {
            default:        // Invalid
                while(1);   // Hold For Error;
            break;
            case USB:
                USBapp_Handler();   // It is held in here.
                // USB escaped; Cable is unplugged; Change OPERATION mode.
                operationType = MOTE;
                MOTEapp_handlerState(MOTE_STARTUP);   // Initial state for startup
            break;
            case MOTE:
                if (moteHandler() == MOTE_SWAP)
                {
                    // Return to USB Operation
                    operationType = USB;   // Mode State
                    USBapp_handlerState(USB_STARTUP);
                }
            break;
        }
    }
}
Exemple #6
0
void main(void)
{
	receive0_cpt_ticks = 0xFF;
	receive1_cpt_ticks = 0xFF;
	receive2_cpt_ticks = 0xFF;
	fifo0wr=0;
	fifo0rd=0;
	fifo1wr=0;
	fifo1rd=0;
	fifo2wr=0;
	fifo2rd=0;
	send_channel = 0;
	cpt_led = 0;
	sending = 0;
	state = 0;
	timer_ini = DATAEE_ReadByte(0x00);
	if (timer_ini==0xff) {
		timer_ini=TIMER_INI_DEFAULT;
		DATAEE_WriteByte(0x00,timer_ini);
	}

	wait = DATAEE_ReadByte(0x01);
	if (wait==0xff) {
		wait=WAIT_DEFAULT;
		DATAEE_WriteByte(0x01,wait);
	}
	send_wait_next_byte = wait;

	Init();

	LED0 = 0;

	while(1)
	{
		/* flash de 600us toutes les 3.4 secondes */

		if (VALID==0)
		{
			LED0 = 0;
			asm("sleep");
			asm("nop");
		}

		if (cpt_led<LED_OFF)
		{
			LED0 = 1;
		}
		else
		{
			LED0 = 0;
		}
		if (RCIF==1)
		{
			received_data = RCREG;
			RCIF=0;
			switch(state)
			{
				case 1 :
					send(received_data);
					switch(received_data)
					{
						case 'v' : // display current timer value
							send(ValueToAsciiHex(timer_ini/16));
							send(ValueToAsciiHex(timer_ini%16));
							send(0x0d);
							send(0x0a);
							state=0;
						break;
						case 'w' : // write timer value to EEPROM
							DATAEE_WriteByte(0x00,timer_ini);
							sendline("Ok.");
							state=0;
						break;
						case 'r' : // read timer value from EEPROM
							timer_ini = DATAEE_ReadByte(0x00);
							send(ValueToAsciiHex(timer_ini/16));
							send(ValueToAsciiHex(timer_ini%16));
							send(0x0d);
							send(0x0a);
							state=0;
						break;
						case 'd' : // define timer value, need 2 extra bytes
							send('=');
							state=2;
						break;
						default :
							sendline("??? command aborted.");
							state=0;
						break;
					}
					break;

				case 2 :
					send(received_data);
					if (isxdigit(received_data))
					{
						par_hi = received_data;
						state = 3;
					}
					else
					{
						sendline("??? command aborted.");
						state = 0;
					}
					received_data=' ';
					break;
				
				case 3 :
					send(received_data);
					if (isxdigit(received_data))
					{
						timer_ini = TwoAsciiHexToValue(par_hi,received_data);
						sendline(" Ok.");
						state = 0;
					}
					else
					{
						sendline("??? command aborted.");
						state = 0;
					}
					received_data=' ';
					break;

				case 11 :
					send(received_data);
					switch(received_data)
					{
						case 'v' : // display current wait value
							send(ValueToAsciiHex(wait/16));
							send(ValueToAsciiHex(wait%16));
							send(0x0d);
							send(0x0a);
							state=0;
						break;
						case 'w' : // write wait value to EEPROM
							DATAEE_WriteByte(0x01,wait);
							sendline("Ok.");
							state=0;
						break;
						case 'r' : // read wait value from EEPROM
							wait = DATAEE_ReadByte(0x01);
							send(ValueToAsciiHex(wait/16));
							send(ValueToAsciiHex(wait%16));
							send(0x0d);
							send(0x0a);
							state=0;
						break;
						case 'd' : // define wait value, need 2 extra bytes
							send('=');
							state=12;
						break;
						default :
							sendline("??? command aborted.");
							state=0;
						break;
					}
					break;

				case 12 :
					send(received_data);
					if (isxdigit(received_data))
					{
						par_hi = received_data;
						state = 13;
					}
					else
					{
						sendline("??? command aborted.");
						state = 0;
					}
					received_data=' ';
					break;
				
				case 13 :
					send(received_data);
					if (isxdigit(received_data))
					{
						wait = TwoAsciiHexToValue(par_hi,received_data);
						sendline(" Ok.");
						state = 0;
					}
					else
					{
						sendline("??? command aborted.");
						state = 0;
					}
					received_data=' ';
					break;

				default :
					switch (received_data)
					{
						case 'V' :
						case 'v' :
							sendline("1.1");
						break;

						case 'P' :
						case 'p' :
							sendline("00168A");
						break;

						case 'S' :
						case 's' :
							sendline("0005");
						break;

						case 'B' :
						case 'b' :
							ADCON0 = 0x9D;	// power on
							somme = 0;
							for (i=0; i<100; i++)
							{
								ADCON0 = 0x9F;	// go
								do
								{
									etat = (ADCON0 & 0x02);
								}
								while (etat==0x02);
								wval= ADRESH;
								wval = wval << 8;
								wval = wval + ADRESL;
								somme += wval;
							}
							wval = somme / 39;
							if (wval<=325)
							{
								wval=0;
							}
							else
							if (wval>=416)
							{
								wval=100;
							}
							else
							{
								wval=wval -316;
							}
							send((wval/100)+0x30);
							send(((wval/10)%10)+0x30);
							send(((wval % 10)+0x30));
							sendline ("%");
							ADCON0 = 0x9C;	// power off
						break;

						case 'T' :
						case 't' :
							send(received_data);
							state = 1;
						break;

						case 'W' :
						case 'w' :
							send(received_data);
							state = 11;
						break;

						default :
							sendline ("");
							sendline ("------ RS232 Mux (c)Metraware 2007 ------");
							sendline ("List of supported commands :");
							sendline ("H    : This help");
							sendline ("V    : Software version");
							sendline ("P    : Part number");
							sendline ("S    : Serial number");
							sendline ("B    : Battery (0-100%)");
							sendline ("Tdhh : Define value for baud rate generator. From 00 to FF. Default 1D (decimal 29)");
							sendline ("Tv   : Current value of T");
							sendline ("Tw   : Save T value in EEPROM");
							sendline ("Tr   : Read T value from EEPROM");
							sendline ("Wdhh : Define value for timeout at end of line. From 00 to FF. Default C8 (decimal 200)");
							sendline ("Wv   : Current value of timeout");
							sendline ("Ww   : Save timeout value in EEPROM");
							sendline ("Wr   : Read timeout value from EEPROM");
							sendline ("?    : This help");
							sendline ("");
							sendline ("Configuration : 3 channels, FIFO_SIZE bytes fifo.");
							sendline ("-------------------------------------------");
							sendline ("");
						break;
					}
				break;
			}
		}

	}
}