/* * prints out a character to the lcd display */ void lcdChar(unsigned char letter) { setGPIO(GPIOA_ADDRESS, 0x80); // RS=1, we going to send data to be displayed Delay10TCYx(0); // let things settle down setGPIO(GPIOB_ADDRESS, letter); // send display character // Now we need to toggle the enable pin (EN) for the display to take effect setGPIO(GPIOA_ADDRESS, 0xc0); // RS=1, EN=1 Delay10TCYx(0); // let things settle down, this time just needs to be long enough for the chip to detect it as high setGPIO(GPIOA_ADDRESS, 0x00); // RS=0, EN=0 // this completes the enable pin toggle Delay10TCYx(0); }
/* * used to send commands and settings information */ void lcdCommand(char command) { setGPIO(GPIOA_ADDRESS, 0x00); // E=0 Delay10TCYx(0); setGPIO(GPIOB_ADDRESS, command); // send data Delay10TCYx(0); setGPIO(GPIOA_ADDRESS, 0x40); // E=1 Delay10TCYx(0); setGPIO(GPIOA_ADDRESS, 0x00); // E=0 Delay10TCYx(0); }
void TICC1100::initDevice() { try { openDevice(); if(!_fileDescriptor || _fileDescriptor->descriptor == -1) return; initChip(); _out.printDebug("Debug: CC1100: Setting GPIO direction"); setGPIODirection(1, GPIODirection::IN); _out.printDebug("Debug: CC1100: Setting GPIO edge"); setGPIOEdge(1, GPIOEdge::BOTH); openGPIO(1, true); if(!_gpioDescriptors[1] || _gpioDescriptors[1]->descriptor == -1) throw(BaseLib::Exception("Couldn't listen to rf device, because the gpio pointer is not valid: " + _settings->device)); if(gpioDefined(2)) //Enable high gain mode { openGPIO(2, false); if(!getGPIO(2)) setGPIO(2, true); closeGPIO(2); } } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
void COC::startListening() { try { _socket = GD::bl->serialDeviceManager.get(_settings->device); if(!_socket) _socket = GD::bl->serialDeviceManager.create(_settings->device, 38400, O_RDWR | O_NOCTTY | O_NDELAY, true, 45); if(!_socket) return; _socket->addEventHandler(this); _socket->openDevice(); if(gpioDefined(2)) { openGPIO(2, false); if(!getGPIO(2)) setGPIO(2, true); closeGPIO(2); } if(gpioDefined(1)) { openGPIO(1, false); if(!getGPIO(1)) { setGPIO(1, false); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); setGPIO(1, true); std::this_thread::sleep_for(std::chrono::milliseconds(2000)); } closeGPIO(1); } writeToDevice(stackPrefix + "X21\n" + stackPrefix + "Zr\n"); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); IPhysicalInterface::startListening(); } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
static void setGPIOallLow(void) { int i, j; for (j = 1; j < 4; ++j) { for (i = 0; i < 32; ++i) { setGPIO(j, i, 0); } } }
int main(void) { uint8_t src_packet[128] = {0x05, 0x30, 0x00, 0x00, 0x0A}; uint8_t rcvd_msg[128] = {0}; uint8_t rcvd_payload[128] = {0}; uint8_t rcvd_length; uint8_t rcvd_payloadLength; uint8_t rcvd_rssi; uint8_t Type; uint16_t Addr; uint8_t radio_channel; uint16_t radio_panID; Type = Type_Light; Addr = 0x0001; radio_channel = 18; radio_panID = 0x00AA; Initial(Addr, Type, radio_channel, radio_panID); setTimer(1,RETRANSMIT_PERIOD,UNIT_MS); while(1){ // Periodically send the msg if(checkTimer(1)){ RF_Tx(0xFFFF,src_packet,5); } // When received some packet if(RF_Rx(rcvd_msg, &rcvd_length, &rcvd_rssi)){ getPayloadLength(&rcvd_payloadLength, rcvd_msg); getPayload(rcvd_payload, rcvd_msg, rcvd_payloadLength); // Check 1)header, 2)sequence number, 3)isACK field if(rcvd_payload[0]==0x05 && rcvd_payload[1]==0x30 && rcvd_payload[2]==src_packet[2] && rcvd_payload[3]==1){ src_packet[2]++; // Change the payload here } } if(src_packet[2]==0x14) break; } while(1){ if(checkTimer(1)){ setGPIO(1,1); } } }
int main(int argc, char **argv) { printf("myGPIP main called!\n"); int err = local_init(); if (!err) { // init GPIO 17 as output initGPIO(gpio_direction_output, 17); // ...and start toggling while(1) { setGPIO(17, 1); sleep(1); setGPIO(17, 0); sleep(1); } } return 0; }
void main(void) { char packet[] = {'T', 'e', 's', 't'}; unsigned char i = 0; unsigned char packet_size = sizeof (packet) / sizeof (packet[0]); unsigned char cArray[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; // temporary local array unsigned char writtenArray[10]; // local variables for all test cases and their initialisation unsigned char chData; unsigned char *pReadArray; unsigned char *pWriteArray; unsigned char j = 0; unsigned char i = 0; pReadArray = pWriteArray = writtenArray; /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); // LCD test TRISAbits.RA2 = 0; // our chip select pin needs to be an output so that we can toggle it CS = 1; // set CS pin to high, meaning we are sending any information to the MCP23S17 chip // configure SPI: the MCP23S17 chip's max frequency is 10MHz, let's use 10MHz/64 (Note FOSC=10Mhz, our external oscillator) OpenSPI1(SPI_FOSC_64, MODE_10, SMPEND); // frequency, master-slave mode, sampling type // set LCD pins DB0-DB7 as outputs setIODIR(IODIRB_ADDRESS, 0x00); // set RS and E LCD pins as outputs setIODIR(IODIRA_ADDRESS, 0x00); // RS=0, E=0 setGPIO(IODIRA_ADDRESS, 0x00); // Function set: 8 bit, 2 lines, 5x8 lcdCommand(0b00111111); // Cursor or Display Shift lcdCommand(0b00001111); // clear display lcdCommand(0b00000001); // entry mode lcdCommand(0b00000110); // send characters lcdWriteString((unsigned char *) "Waiting..."); // using the string function lcdGoTo(0x40); // go to line two /*lcdChar('S'); // using the single character function lcdChar('P'); lcdChar('I'); lcdChar(' '); lcdChar('L'); lcdChar('i'); lcdChar('b'); lcdChar('r'); lcdChar('a'); lcdChar('r'); lcdChar('y'); */ /////////////////////////////////////////////////// /* TODO <INSERT USER APPLICATION CODE HERE> */ /* while(1) { i = 0; do { UARTIntPutChar(packet[i++]); } while (i < packet_size); while (!vUARTIntStatus.UARTIntTxBufferEmpty); Delay10KTCYx(1000); } */ TRISD = 0; PORTD = 0; while (1) { /* for (j = 0; j < 100; j++) { i = 0; do { if (vUARTIntStatus.UARTIntTxBufferEmpty) UARTIntPutChar(cArray[i++]); } while (i < 10); } */ if (!(vUARTIntStatus.UARTIntRxError) && !(vUARTIntStatus.UARTIntRxOverFlow) && !(vUARTIntStatus.UARTIntRxBufferEmpty)) { if (UARTIntGetChar(&chData)) { PORTD = chData; lcdChar(chData); } } } }