int main(void) { _U08 u8Config; ANCON0 = 0XFF; /*Desactivamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desactivamos las entradas analógicas*/ Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT); /*SCL2*/ Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT); /*SDA2*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/ (void)Uart_Init(UART_PORT1, 115200); /*velocidad a 115200 bauds*/ xdev_out(putChar); /*funcion Uart_PutChar como salida estandar*/ I2c_Init(I2C_PORT2, 100000); /*puerto I2C 2 a 100KHz de velocidad*/ I2c_Start(I2C_PORT2); /*generamos condicion start*/ (void)I2c_bTxByte(I2C_PORT2, ADDR_WRITE(0b1001101)); /*madamos direccion del sensor en modo escritura*/ (void)I2c_bTxByte(I2C_PORT2, 0x01); /*mandamos direccion a leer*/ I2c_RepeatedStart(I2C_PORT2); /*repetimos señal start*/ (void)I2c_bTxByte(I2C_PORT2, ADDR_READ(0b1001101)); /*madmaos direccion del sensor en modo lectura*/ u8Config = I2c_u8RxByte(I2C_PORT2, I2C_NACK); /*leemos dato leido y contestamos NACK*/ I2c_Stop(I2C_PORT2); /*indicamos fin de comunicacion*/ /*mostramos por serial el byte leido el cual tendra el valor de 0x40, indica sensor listo*/ xprintf("Registro config: 0x%X\r\n", (_U16)u8Config); while (1) { /*Escribe aqui tu aplicacion*/ } }
int main(void) { _U08 i; _U08 u8Array[] = {99,95,90,85,80,75,70,65,60,55,50,45}; ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ /*el modulo pwm1 no tiene los pines conectados asi que hay que asignarlos a los pines RPx que deseemos*/ System_PeripheralPinSelect(EnhancedPWMOutputChannel1B, 19); /*PWM1_B en el pin RP19 (D2)*/ Gpios_PinDirection(GPIOS_PORTD, 2, GPIOS_OUTPUT); /*pin RD2 como salida para PWM_1B*/ Pwm_Init(PWM_PORT1, 750); while (1) { for(i=0;i<sizeof(u8Array);i++) { Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_B, u8Array[i]); Delays_ms(300); } i--; for(;i<sizeof(u8Array);i--) { Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_B, u8Array[i]); Delays_ms(300); } Delays_ms(3000); } }
/**-----------------------------------------------------------------------------------------------*/ void _7segments_Init(void) { Gpios_WriteTris(_7SEGMENTS_PORT, 0x00); Gpios_PinDirection(_7SEGMENTS_DIGI0_P, _7SEGMENTS_DIGI0_B, GPIOS_OUTPUT); Gpios_WritePin(_7SEGMENTS_DIGI0_P, _7SEGMENTS_DIGI0_B, DIGI_OFF); #if _7SEGMENTS_DIGI_N > 1 Gpios_PinDirection(_7SEGMENTS_DIGI1_P, _7SEGMENTS_DIGI1_B, GPIOS_OUTPUT); Gpios_WritePin(_7SEGMENTS_DIGI1_P, _7SEGMENTS_DIGI1_B, DIGI_OFF); #endif #if _7SEGMENTS_DIGI_N > 2 Gpios_PinDirection(_7SEGMENTS_DIGI2_P, _7SEGMENTS_DIGI2_B, GPIOS_OUTPUT); Gpios_WritePin(_7SEGMENTS_DIGI2_P, _7SEGMENTS_DIGI2_B, DIGI_OFF); #endif #if _7SEGMENTS_DIGI_N > 3 Gpios_PinDirection(_7SEGMENTS_DIGI3_P, _7SEGMENTS_DIGI3_B, GPIOS_OUTPUT); Gpios_WritePin(_7SEGMENTS_DIGI3_P, _7SEGMENTS_DIGI3_B, DIGI_OFF); #endif }
int main(void) { ANCON0 = 0XFF; /*Desactivamos las entradas analogicas*/ ANCON1 = 0XFF; /*Desactivamos las entradas analogicas*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*pin de tx como salida*/ Gpios_PinDirection(GPIOS_PORTC, 7, GPIOS_INPUT); /*pin de rx como entrada*/ (void)Uart_Init(UART_PORT1, 9600); /*se iniclaiza el puerto serial a 9600 baudios*/ __ENABLE_INTERRUPTS(); /*habilitamos interrupciones globales*/ while (1) { if(gbFlag == 1) /*llego un caracter por teclado*/ { gbFlag = 0; /*limpiamos la bandera*/ Uart_PutChar(UART_PORT1, gu8RxData);/*lo enviamos de regreso para tener feedback visual*/ } } }
int main(void) { Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_OUTPUT); /*pin de tx como salida*/ (void)Uart_Init(UART_PORT0, 57600); /*se iniclaiza el puerto serial a 115200 baudios*/ while (1) { Uart_PutString(UART_PORT0, (const _U08*)"Hola mundo\n\r"); /*se manda mensaje por puerto serial*/ Delays_ms(1000); /*se cicla por 1 seg*/ } }
int main(void) { ANCON0 = 0XFF; /*Desativamos las salidas analogicas*/ ANCON1 = 0XFF; /*Desativamos las salidas analogicas*/ Timers_Init(); /*inicializamos el driver para genere una interrupcion cada 5ms*/ Timers_SetTime(0, 100/timers_ms); /*recargamos el canal 0 con un valor de 100ms*/ Timers_SetTime(1, 200/timers_ms); /*recargamos el canal 1 con un valor de 200ms*/ Timers_SetTime(2, 500/timers_ms); /*recargamos el canal 2 con un valor de 500ms*/ Gpios_PinDirection(GPIOS_PORTB, 7, GPIOS_OUTPUT); /*puerto RB7 como salida*/ Gpios_PinDirection(GPIOS_PORTB, 6, GPIOS_OUTPUT); /*puerto RB6 como salida*/ Gpios_PinDirection(GPIOS_PORTB, 5, GPIOS_OUTPUT); /*puerto RB5 como salida*/ __ENABLE_INTERRUPTS(); /*se habilitan las interrupciones globales con prioridad*/ while (1) { /*parpadeamos el primer led (Puerto B, Pin 7)*/ if(Timers_u16GetTime(0) == 0)/*preguntamos si la interrupcion decrmento hasta llegar a 0 el canal 0*/ { Timers_SetTime(0, 100/timers_ms);/*se cumplen los 100ms asi que volvemos a recargar el mismo canal */ Gpios_TogglePin(GPIOS_PORTB, 7); /*invierto el estado del led conectado al puerto B pin 7*/ } /*parpadeamos el segundo led (Puerto B, Pin 6)*/ if(Timers_u16GetTime(1) == 0)/*preguntamos si la interrupcion decrmento hasta llegar a 0 el canal 1*/ { Timers_SetTime(1, 200/timers_ms);/*se cumplen los 200ms asi que volvemos a recargar el mismo canal */ Gpios_TogglePin(GPIOS_PORTB, 6); /*invierto el estado del led conectado al puerto B pin 6*/ } /*parpadeamos el primer led (Puerto B, Pin 5)*/ if(Timers_u16GetTime(2) == 0)/*preguntamos si la interrupcion decrmento hasta llegar a 0 el canal 2*/ { Timers_SetTime(2, 500/timers_ms);/*se cumplen los 500ms asi que volvemos a recargar el mismo canal */ Gpios_TogglePin(GPIOS_PORTB, 5); /*invierto el estado del led conectado al puerto B pin 5*/ } } }
void main(void) { ANCON0 = 0XFF; /*Desativamos las salidas analogicas*/ ANCON1 = 0XFF; /*Desativamos las salidas analogicas*/ Gpios_PinDirection(GPIOS_PORTA, 1, GPIOS_OUTPUT); /*puerto RA1 como salida*/ while (1) { Delays_ms(100); /*retardo 100 ms para observar el estado del led*/ Gpios_TogglePin(GPIOS_PORTA, 1); /*invierto el estado del led conectado al puerto A pin 1*/ } }
int main(void) { _S08 i8Temp; ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ Gpios_PinDirection(GPIOS_PORTD, 0, GPIOS_INPUT); /*SCL2*/ Gpios_PinDirection(GPIOS_PORTD, 1, GPIOS_INPUT); /*SDA2*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*puerto de tx uart como salida*/ (void)Uart_Init(UART_PORT1, 115200); /*velocidad a 115200 bauds*/ xdev_out(putChar); /*funcion Uart_PutChar como salida estandar*/ I2c_Init(I2C_PORT2, 100000); /*puerto I2C 2 a 100KHz de velocidad*/ while (1) { i8Temp = Tc74ax_ReadTemp(TC74A5); /*mostramos por serial el byte leido el cual tendra el valor de la temp ambiental*/ xprintf("Temperatura ambiente: %d\r", (_S16)i8Temp); Delays_ms(1000); } }
void main(void) { ANCON0 = 0XFF; /*Desativamos las entradas analógicas*/ ANCON1 = 0XFF; /*Desativamos las entradas analógicas*/ /*el modulo pwm1 no tiene los pines conectados asi que hay que asignarlos a los pines RPx que deseemos*/ System_PeripheralPinSelect(CompareOrPWMOutputChannel1A, 2); /*PWM1_A en el pin RP2 (A5)*/ System_PeripheralPinSelect(CompareOrPWMOutputChannel2A, 19); /*PWM2_A en el pin RP19 (D2)*/ Gpios_PinDirection(GPIOS_PORTA, 5, GPIOS_OUTPUT); /*pin RA5 como salida para PWM_1A*/ Gpios_PinDirection(GPIOS_PORTD, 2, GPIOS_OUTPUT); /*pin RD2 como salida para PWM_2A*/ Pwm_Init(PWM_PORT1, 1000); Pwm_Init(PWM_PORT2, 1000); Pwm_DutyCycle(PWM_PORT1, PWM_CHANNEL_A, 40); Pwm_DutyCycle(PWM_PORT2, PWM_CHANNEL_A, 70); while (1) { /*Escribe aqui tu aplicacion*/ } }
int main(void) { System_EnablePLL(); /*micro a 48MHz, esto es obligatorio para el USB*/ UsbCDC_Init(9600); /*inicia emulacion serial a 9600 baudios*/ Gpios_PinDirection(GPIOS_PORTA, 1, GPIOS_OUTPUT);/*pin RA1 como salida*/ while(1) { if(UsbCDC_bEnumerated() == _TRUE) /*usb enumarado*/ { i = UsbCDC_u8RxData( &buffer[0], 1 );/*recivimos datos por usb serial*/ if((i > 0) && (buffer[0] == 't'))/*si se recivio un dato y este es la letra t*/ { Gpios_TogglePin(GPIOS_PORTA, 1);/*invierto estado del led*/ } } } }
int main(void) #endif { BYTE i, j; BYTE TxSynCount = 0; BOOL bReceivedMessage = FALSE; _U16 m; #define BAUDRG 77 /*******************************************************************/ // Initialize the system /*******************************************************************/ ANCON0 = 0XFF; /*desactiva entradas analogicas*/ ANCON1 = 0XFF; /*desactiva entradas analogicas*/ PPSUnLock(); PPSOutput(PPS_RP10, PPS_TX2CK2); // TX2 RP17/RC6 PPSInput(PPS_RX2DT2, PPS_RP9); // RX2 RP18/RC7 PPSOutput(PPS_RP23, PPS_SDO2); // SDO2 RP23/RD6 PPSInput(PPS_SDI2, PPS_RP24); // SDI2 RP24/RD7 PPSOutput(PPS_RP22, PPS_SCK2); // SCK2 RP22/RD5 PPSLock(); System_PeripheralPinSelect( ExternalInterrupt3, 19); /*external interrupt 3 B3*/ BoardInit(); ConsoleInit(); Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG); baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF); Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT); /*pin C0 como salida para SDI*/ Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/ Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/ Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/ Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/ //Spi_SetMode(SPI_PORT1, 1); //Spi_SetMode(SPI_PORT1, 1); LED_1 = 1; LED_2 = 1; Read_MAC_Address(); LED_1 = 0; LED_2 = 0; ConsolePutROMString((ROM char *)"\r\n<MAC Addr:"); PrintChar(myLongAddress[3]); PrintChar(myLongAddress[2]); PrintChar(myLongAddress[1]); PrintChar(myLongAddress[0]); ConsolePutROMString((ROM char *)"\r>"); Printf("\r\nStarting Testing Interface for MiWi(TM) PRO Stack ..."); #if defined(MRF24J40) Printf("\r\n RF Transceiver: MRF24J40"); #elif defined(MRF49XA) Printf("\r\n RF Transceiver: MRF49XA"); #elif defined(MRF89XA) Printf("\r\n RF Transceiver: MRF89XA"); #endif Printf("\r\n Demo Instruction:"); Printf("\r\n Press Enter to bring up the menu."); Printf("\r\n Type in hyper terminal to choose"); Printf("\r\n menu item. "); Printf("\r\n\r\n"); /*******************************************************************/ // Following block display demo information on LCD of Explore 16 or // PIC18 Explorer demo board. /*******************************************************************/ #if defined(MRF49XA) LCDDisplay((char *)"MiWi PRO Test Interface MRF49XA", 0, TRUE); #elif defined(MRF24J40) LCDDisplay((char *)"MiWi PRO Test Interface MRF24J40", 0, TRUE); #elif defined(MRF89XA) LCDDisplay((char *)"MiWi PRO Test Interface MRF89XA", 0, TRUE); #endif //if( (PUSH_BUTTON_1 == 0) || ( MiApp_ProtocolInit(TRUE) == FALSE ) ) if (PUSH_BUTTON_1 == 1) { MiApp_ProtocolInit(FALSE); LED_1 = 0; LED_2 = 0; #ifdef ENABLE_ACTIVE_SCAN myChannel = 0xFF; ConsolePutROMString((ROM char *)"\r\nStarting Active Scan..."); LCDDisplay((char *)"Active Scanning", 0, FALSE); /*******************************************************************/ // Function MiApp_SearchConnection will return the number of // existing connections in all channels. It will help to decide // which channel to operate on and which connection to add. // The return value is the number of connections. The connection // data are stored in global variable ActiveScanResults. // Maximum active scan result is defined as // ACTIVE_SCAN_RESULT_SIZE // The first parameter is the scan duration, which has the same // definition in Energy Scan. 10 is roughly 1 second. 9 is a // half second and 11 is 2 seconds. Maximum scan duration is 14, // or roughly 16 seconds. // The second parameter is the channel map. Bit 0 of the // double word parameter represents channel 0. For the 2.4GHz // frequency band, all possible channels are channel 11 to // channel 26. As the result, the bit map is 0x07FFF800. Stack // will filter out all invalid channels, so the application // only needs to pay attention to the channels that are not // preferred. /*******************************************************************/ i = MiApp_SearchConnection(10, 0x02000000); if( i > 0 ) { // now print out the scan result. Printf("\r\nActive Scan Results: \r\n"); for(j = 0; j < i; j++) { Printf("Channel: "); PrintDec(ActiveScanResults[j].Channel ); Printf(" RSSI: "); PrintChar(ActiveScanResults[j].RSSIValue); Printf("\r\n"); myChannel = ActiveScanResults[j].Channel; Printf("PeerInfo: "); PrintChar( ActiveScanResults[j].PeerInfo[0]); } } #endif /*******************************************************************/ // Function MiApp_ConnectionMode sets the connection mode for the // protocol stack. Possible connection modes are: // - ENABLE_ALL_CONN accept all connection request // - ENABLE_PREV_CONN accept only known device to connect // - ENABL_ACTIVE_SCAN_RSP do not accept connection request, but // allow response to active scan // - DISABLE_ALL_CONN disable all connection request, including // active scan request /*******************************************************************/ MiApp_ConnectionMode(ENABLE_ALL_CONN); if( i > 0 ) { /*******************************************************************/ // Function MiApp_EstablishConnection try to establish a new // connection with peer device. // The first parameter is the index to the active scan result, which // is acquired by discovery process (active scan). If the value // of the index is 0xFF, try to establish a connection with any // peer. // The second parameter is the mode to establish connection, either // direct or indirect. Direct mode means connection within the // radio range; Indirect mode means connection may or may not // in the radio range. /*******************************************************************/ if( MiApp_EstablishConnection(0, CONN_MODE_DIRECT) == 0xFF ) { Printf("\r\nJoin Fail"); } } else { /*******************************************************************/ // Function MiApp_StartConnection tries to start a new network // // The first parameter is the mode of start connection. There are // two valid connection modes: // - START_CONN_DIRECT start the connection on current // channel // - START_CONN_ENERGY_SCN perform an energy scan first, // before starting the connection on // the channel with least noise // - START_CONN_CS_SCN perform a carrier sense scan // first, before starting the // connection on the channel with // least carrier sense noise. Not // supported on currrent radios // // The second parameter is the scan duration, which has the same // definition in Energy Scan. 10 is roughly 1 second. 9 is a // half second and 11 is 2 seconds. Maximum scan duration is // 14, or roughly 16 seconds. // // The third parameter is the channel map. Bit 0 of the // double word parameter represents channel 0. For the 2.4GHz // frequency band, all possible channels are channel 11 to // channel 26. As the result, the bit map is 0x07FFF800. Stack // will filter out all invalid channels, so the application // only needs to pay attention to the channels that are not // preferred. /*******************************************************************/ #ifdef ENABLE_ED_SCAN //LCDDisplay((char *)"Active Scanning Energy Scanning", 0, FALSE); ConsolePutROMString((ROM char *)"\r\nActive Scanning Energy Scanning"); MiApp_StartConnection(START_CONN_ENERGY_SCN, 10, 0x02000000); #endif } // Turn on LED 1 to indicate ready to accept new connections LED_1 = 1; } else { //LCDDisplay((char *)" Network Freezer ENABLED", 0, TRUE); Printf("\r\nNetwork Freezer Feature is enabled. There will be no hand-shake process.\r\n"); LED_1 = 1; DumpConnection(0xFF); } LCDDisplay((char *)"Start Connection on Channel %d", currentChannel, TRUE); LCDDisplay((char *)"Testing Menu on Hyper Terminal", 0, FALSE); while(1) { /*******************************************************************/ // Function MiApp_MessageAvailable will return a boolean to indicate // if a message for application layer has been received by the // transceiver. If a message has been received, all information will // be stored in the rxMessage, structure of RECEIVED_MESSAGE. /*******************************************************************/ if( MiApp_MessageAvailable() ) { /*******************************************************************/ // If a packet has been received, following code prints out some of // the information available in rxFrame. /*******************************************************************/ if( rxMessage.flags.bits.secEn ) { ConsolePutROMString((ROM char *)"Secured "); } if( rxMessage.flags.bits.broadcast ) { ConsolePutROMString((ROM char *)"Broadcast Packet with RSSI "); } else { ConsolePutROMString((ROM char *)"Unicast Packet with RSSI "); } PrintChar(rxMessage.PacketRSSI); if( rxMessage.flags.bits.srcPrsnt ) { ConsolePutROMString((ROM char *)" from "); if( rxMessage.flags.bits.altSrcAddr ) { PrintChar(rxMessage.SourceAddress[1]); PrintChar(rxMessage.SourceAddress[0]); } else { for(i = 0; i < MY_ADDRESS_LENGTH; i++) { PrintChar(rxMessage.SourceAddress[MY_ADDRESS_LENGTH-1-i]); } } } ConsolePutROMString((ROM char *)": "); for(i = 0; i < rxMessage.PayloadSize; i++) { ConsolePut(rxMessage.Payload[i]); } // Toggle LED2 to indicate receiving a packet. LED_2 ^= 1; /*******************************************************************/ // Function MiApp_DiscardMessage is used to release the current // received message. After calling this function, the stack can // start to process the next received message. /*******************************************************************/ MiApp_DiscardMessage(); bReceivedMessage = TRUE; /*******************************************************************/ // Following block update the total received and transmitted messages // on the LCD of the demo board. /*******************************************************************/ LCDTRXCount(TxNum, ++RxNum); } else { ++m; if(m > 8000) { m=0; //LED_1 ^= 1; MiApp_FlushTx(); MiApp_WriteData('H'); MiApp_WriteData('o'); MiApp_WriteData('l'); MiApp_WriteData('a'); MiApp_WriteData('a'); MiApp_WriteData('a'); MiApp_WriteData(0x0D); MiApp_WriteData(0x0A); MiApp_BroadcastPacket(FALSE); } if ( ConsoleIsGetReady() ) { //ProcessMenu(); } } } }
void main(void) { #define BAUDRG 77 BYTE SecNum = 0; BOOL Tx_Success = FALSE; BYTE Tx_Trials = 0, scanresult = 0; /*******************************************************************/ // Initialize the system /*******************************************************************/ ANCON0 = 0XFF; /*desactiva entradas analogicas*/ ANCON1 = 0XFF; /*desactiva entradas analogicas*/ PPSUnLock(); PPSOutput(PPS_RP10, PPS_TX2CK2); // TX2 RP17/RC6 icsp PPSInput(PPS_RX2DT2, PPS_RP9); // RX2 RP18/RC7 PPSOutput(PPS_RP23, PPS_SDO2); // SDO2 RP23/RD6 PPSInput(PPS_SDI2, PPS_RP24); // SDI2 RP24/RD7 PPSOutput(PPS_RP22, PPS_SCK2); // SCK2 RP22/RD5 PPSLock(); System_PeripheralPinSelect( ExternalInterrupt3, 19); /*external interrupt 3 B3*/ BoardInit(); ConsoleInit(); Gpios_PinDirection(GPIOS_PORTC, 7, GPIOS_INPUT); /*pin C0 como salida para SDI*/ Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/ //Gpios_PinDirection(GPIOS_PORTD, 4, GPIOS_OUTPUT); /*pin D4 como salida */ Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG); baud1USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF); Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG); baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF); OpenTimer1( TIMER_INT_OFF &T1_16BIT_RW &T1_SOURCE_FOSC_4 & T1_PS_1_8 &T1_OSC1EN_OFF &T1_SYNC_EXT_OFF, TIMER_GATE_OFF & TIMER_GATE_INT_OFF); Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT); /*pin C0 como salida para SDI*/ Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/ Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/ Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/ Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/ //Adc_Init(ADC_10BITS); LED_1 = 1; LED_2 = 0; //RLY_1 = 0; RLY_2 = 0; ON_RADIO = 1; ON_MAC = 1; ON_TEMP = 1; StartWirelessConnection(); //myDevicesRequiredStatus[0] = 0x55; EEPROMRead(&myDevicesRequiredStatus, 0, 1); if(myDevicesRequiredStatus[0] == 0x55) { RLY_1 = 1; EEPROMCHG = 1; ConsolePutROMString((ROM char *)"RELAY ON "); } if(myDevicesRequiredStatus[0] == 0xAA) { RLY_1 = 0; EEPROMCHG = 0; ConsolePutROMString((ROM char *)"RELAY OFF "); } for(j=0;j<10;j++) { DelayMs(50); LED_1 ^= 1; LED_2 ^= 1; } LED_1 = 0; LED_2 = 0; //RLY_1 = 0; RLY_2 = 0; TickScaler = 4; EndDevStateMachine =0; /* while(!Tx_Success) { if(myChannel < 8) scanresult = MiApp_SearchConnection(10, (0x00000001 << myChannel)); else if(myChannel < 16) scanresult = MiApp_SearchConnection(10, (0x00000100 << (myChannel-8))); else if(myChannel < 24) scanresult = MiApp_SearchConnection(10, (0x00010000 << (myChannel-16))); else scanresult = MiApp_SearchConnection(10, (0x01000000 << (myChannel-24))); if(scanresult == 0) { Tx_Trials++; if(Tx_Trials > 2) break; } else Tx_Success = TRUE; } if(Tx_Success) { ConsolePutROMString((ROM char *)"RADIO OK "); } else { ConsolePutROMString((ROM char *)"RADIO FAIL "); } */ //.VBGOE = 0; //ANCON1bits.VBGEN = 1; // Enable Band gap reference voltage //DelayMs(10); //VBGResult = Adc_u16Read(15); //ANCON1bits.VBGEN = 0; // Disable Bandgap //Adc_Init(ADC_10BITS); ANCON0 = 0xFF; ANCON1 = 0x9F; ANCON1bits.VBGEN = 1; // Enable Band gap reference voltage ADCON0bits.VCFG = 0; // vreff VDD-VSS ADCON0bits.CHS = 0x0F; // VBG channel select ADCON1 = 0xBE; ADCON0bits.ADON = 1; //for(j=0;j<16;j++) //{ //myDevicesOutputStatus[j] = j; //} //EEPROMWRITE(myDevicesOutputStatus,0,16); //for(j=0;j<16;j++) //{ //myDevicesOutputStatus[j] = 0; //} //DelayMs(500); EEPROMRead(&myDevicesOutputStatus, 0, 16); ConsolePutROMString((ROM char *)"EEPROM READ: "); //PrintChar(TemperatureCalibrationValue); for(j=0;j<1;j++) { PrintChar(myDevicesOutputStatus[j]); } SwTimer3 = 0; SwTimer4 = 0; TRISB&=0xEF; //JL: Configuro el pin B4 como salida si modificar el estado de los demas pines while(1) { /* WirelessTxRx(); WirelesStatus(); Bypass(); */ //No se utilizaron //Menu(); //Timer1Tick(); //WirelessTxRxPANCOORD(); //TaskScheduler(); //JLEstas funciones deben habilitarse para trabajar como repetidora Timer1Tick(); Repeater(); } }