//============================================================================================================================================== // Hier findet die Übertragung der Daten an das Funk-Modul statt // __monitor: Compileranweisung dass Interrupts während der Ausführung dieser Funktion gesperrt sind // Am Ende der Funktion wird der Interrupt-Enable-Zustand, der beim Aufruf der Funktion geherrscht hat, wieder hergestellt // Dies ist in sofern wichtig, dass sonst durch Sensor-IRQ's diese Funktion unterbrochen werden könnte, die dann selbst // diese SPI-Schnittstelle benutzen würden. Das würde zu einem Daten-Mix an der SPI-Schnittstelle führen. ... //============================================================================================================================================== __monitor void Radio_SendRecord(void* write_data, BYTE data_lenght) { uint8_t bReceiveBuffer[15]; uint8_t *pbReceiveBufferPointer = bReceiveBuffer; uint8_t *pbData = write_data; pbData++; // bDummy überspringen data_lenght--; // und deshalb auch das längen-Byte korrigieren _RadioCS_L(); // CS auf Low while (data_lenght) { *pbReceiveBufferPointer++ = RADIO_PUT_GET_BYTE( *pbData++ ); // Sende Daten an das Radio und speicher die Antwort in bReceiveBufer ab data_lenght--; // Decrement the Byte counter } _RadioCS_H(); // CS auf High switch (bReceiveBuffer[0]) { case SA_CONNECTED: _NOP(); // Conenction to the Gateway is establisched. The data can be send. break; case SA_DISCONNECTED: _NOP(); // Conenction to the Gateway is not establisched. The data can not be send. break; case RADIO_CMD_RECEIVE: // Rf Transceiver received a new data paket => Get_Frame request mbRadio_Has_Received_Data = true; default: break; } }
/*--------------------------------------------------------------------------- * Description of function. Optional verbose description. *-------------------------------------------------------------------------*/ unsigned char SWI2C_rxByte(bool ack) // Read 8 bits of I2C data { unsigned char bits, temp = 0; // I2C bit counter PxDIR &= ~SDA; // Set to input, SDA = 1 via pull-up bits = 0x08; // Load I2C bit counter while (bits > 0) // Loop until all bits are read { PxDIR &= ~SCL; // Set to input, SDL = 1 via pull-up _NOP(); // Quick delay temp = (temp << 1); // Shift bits 1 place to the left if (Px & SDA) // Check digital input temp = (temp + 1); // If input is 'H' store a '1' _NOP(); // Quick delay PxDIR |= SCL; // Set to output, data low [SCL = 0] _NOP(); // Quick delay bits = (bits - 1); // Decrement I2C bit counter } if (ack == TRUE) { SWI2C_ack(); // Send acknowledge } else { SWI2C_nack(); // Send not acknowledge } return (temp); // Return 8-bit data byte }
unsigned char read_data_12864(void) { #if _kkk_p_or_s==0 unsigned char da,i; delay_12864(100); CS_1_12864; write_byte_12864(0xfe); DataIn_12864; da=read_byte_12864(); i=read_byte_12864(); i>>=4; da|=i; CS_0_12864; DataOut_12864; return da; #else unsigned char da; E_0_12864; DataDir_12864=0x00; DataOut_12864=0xff; IsData_12864; IsRead_12864; _NOP(); E_1_12864; _NOP(); _NOP(); _NOP(); da=DataIn_12864; E_0_12864; DataDir_12864=0xff; return (da); #endif }
void LoadLcd(void) /* Загрузить данные в LCD индикатор */ { LCDEN_ONE; _NOP(); _NOP(); _NOP(); _NOP(); LCDEN_ZERO; }
/*--------------------------------------------------------------------------- * Description of function. Optional verbose description. *-------------------------------------------------------------------------*/ void SWI2C_recv_ack(void) { PxDIR &= ~SDA; // Set to input, SDA = 1 via pull-up PxDIR &= ~SCL; // Set to input, SCL = 1 via pull-up _NOP(); _NOP(); PxDIR |= SCL; // Set to output, clock low [SCL = 0] PxDIR |= SDA; // Set to output, clock low [SDA = 0] }
/*--------------------------------------------------------------------------- Delay function (resolution is ~1 us at 8MHz clock) Arguments: word microeconds (number of ms, max number is 0xFFFF) */ void delay_us(word microeconds) { do { _NOP(); _NOP(); } while (--microeconds > 0); }
void delay_30us() { unsigned char i,j=0; for(i=0;i<2;i++) { _NOP();_NOP(); } _NOP(); }
/*--------------------------------------------------------------------------- * Description of function. Optional verbose description. *-------------------------------------------------------------------------*/ void SWI2C_start(void) // Set up start condition for I2C { PxDIR &= ~SCL; // Set to input, SCL = 1 via pull-up _NOP(); // Quick delay _NOP(); // Quick delay PxDIR |= SDA; // Set to output, data low [SDA = 0] _NOP(); // Quick delay _NOP(); // Quick delay PxDIR |= SCL; // Set to output, data low [SCL = 0] }
/*--------------------------------------------------------------------------- * Description of function. Optional verbose description. *-------------------------------------------------------------------------*/ void SWI2C_stop(void) // Send I2C stop command { PxDIR |= SDA; // Set to output, data low [SDA = 0] _NOP(); // Quick delay _NOP(); // Quick delay PxDIR &= ~SCL; // Set to input, SCL = 1 via pull-up _NOP(); // Quick delay _NOP(); // Quick delay PxDIR &= ~SDA; // Set to input, SDA = 1 via pull-up }
/** * \internal * Put start condition on the bus. */ static void start(void) { P5DIR |= 0x0C; /* ensure: P52(SDA), P53(SCL) output */ SCL_LOW; _NOP(); _NOP(); SDA_HIGH; _NOP(); _NOP(); SCL_HIGH; _NOP(); _NOP(); SDA_LOW; _NOP(); _NOP(); SCL_LOW; _NOP(); _NOP(); }
void Delay (unsigned int a) { int k; for (k=0 ; k != a; ++k) { _NOP(); _NOP(); _NOP(); _NOP(); } }
void iic_send_nack(void) { SCL_0; _NOP(); SDA_1; _NOP(); SCL_1; _NOP(); _NOP(); SCL_0; }
/*--------------------------------------------------------------------------- * Description of function. Optional verbose description. *-------------------------------------------------------------------------*/ void SWI2C_nack(void) // Set up for I2C not acknowledge { PxDIR |= SCL; // Set to output, data low [SCL = 0] PxDIR &= ~SDA; // Set to input, SDA = 1 via pull-up PxDIR &= ~SCL; // Set to input, SCL = 1 via pull-up _NOP(); // delay to meet I2C spec _NOP(); // " " " PxDIR |= SCL; // Set to output, clock low [SCL = 0] PxDIR &= ~SDA; // Set to input, SDA = 1 via pull-up }
void LCD_envoyer_car(char caractere) // cette fonction envoie un caractere vers le LCD { PORTB = PORTB |(1<<RS); PORTB = PORTB &~(1<<RW); PORTB = PORTB |(1<<E); PORTA = caractere; _NOP(); PORTB = PORTB &~(1<<E); _NOP(); _delay_us(40); }
void LCD_function_set(char func) { PORTB = PORTB & ~(1<<RS); PORTB = PORTB &~(1<<RW); PORTB = PORTB |(1<<E); PORTA = func; _NOP(); PORTB = PORTB &~(1<<E); _NOP(); }
/** * \internal * Put stop condition on the bus. */ static void stop(void) { //P5DIR |= 0x0C; /* ensure: P52(SDA), P53(SCL) output */ SCL_LOW; _NOP(); _NOP(); SDA_LOW; _NOP(); _NOP(); SCL_HIGH; _NOP(); _NOP(); SDA_HIGH; _NOP(); _NOP(); SCL_LOW; _NOP(); _NOP(); P5DIR &= ~0x0C; }
void LCD_setup(void) { WDTCTL = WDTPW + WDTHOLD; __delay_cycles(3000); _NOP(); LCD_init(); LCD_backlightInit(); LCD_setAllPixels(0); LCD_clear(); _NOP(); }
/******************************************************************** 函数名称:mnack 功 能:完成I2C的主机无应答操作 参 数:无 返回值 :无 ********************************************************************/ void mnack(void) { SDA_H; _NOP(); _NOP(); SCL_H; delay_us(5); SCL_L; _NOP(); _NOP(); SDA_L; delay_us(5); }
void OLED_WR_Data(BYTE bDATA) { OLED_DATA_DIR = 0xFF; // Port auf Ausgabe schalten OLED_DATA_OUT = bDATA; OLED_SET_DATA_MODE; // DATA-Mode wählen OLED_WR_LOW; // WR auf low OLED_CS_LOW; // CS auf low _NOP(); OLED_WR_HIGH; // WR-Signal high setzen und damit die Datenübernahme an den SSD1309-Controller durchführen _NOP(); OLED_CS_HIGH; // CS-Signal high setzen und damit die Kommunikation abschließen }
int LCD_putschar(char caractere,FILE *stream) { PORTB = PORTB |(1<<RS); PORTB = PORTB &~(1<<RW); PORTB = PORTB |(1<<E); PORTA = caractere; _NOP(); PORTB = PORTB &~(1<<E); _NOP(); _delay_us(40); }
void sja1000_write(uint8_t address, uint8_t data) { // set address SET(SJA1000_ALE); PORT(SJA1000_DATA) = address; _NOP(); RESET(SJA1000_ALE); // write data PORT(SJA1000_DATA) = data; RESET(SJA1000_WR); _NOP(); SET(SJA1000_WR); }
uint8_t i2cm_rx(uint8_t * buf, const uint16_t length, const uint8_t options) { uint8_t data; volatile unsigned int i, j; if (options & I2C_SDA_WAIT) { delay_c; // wait until the data line is pulled low // this method is used by sensirion sensors while (I2C_MASTER_IN & I2C_MASTER_SDA) { _NOP(); } } for (j = 0; j < length; j++) { sda_high; data = 0; i = 0; for (; i < 8; ++i) { scl_high; if (!(I2C_MASTER_IN & I2C_MASTER_SCL)) { _NOP(); // wait if slave holds the clk low } data <<= 1; if (I2C_MASTER_IN & I2C_MASTER_SDA) data |= 0x01; scl_low; } *buf++ = data; if (j != length - 1) { sda_low; } if ((j == length - 1) && (options & I2C_LAST_NAK)) { // send nack sda_high; delay_c; scl_high; delay_c; scl_low; } else { // send ack scl_high; delay_c; scl_low; } } return 0; }
BYTE OLED_RD_Status(void) { BYTE bRetValue; OLED_DATA_DIR = 0x00; // Port auf Eingabe schalten OLED_SET_CMD_MODE; // CMD-Mode wählen OLED_RD_LOW; // RD auf low OLED_CS_LOW; // CS auf low _NOP(); bRetValue = OLED_DATA_IN; OLED_RD_HIGH; // WR-Signal high setzen und damit die Datenübernahme an den SSD1309-Controller durchführen _NOP(); OLED_CS_HIGH; // CS-Signal high setzen und damit die Kommunikation abschließen return bRetValue; }
__interrupt void Port_2(void) { if (RF_IRQ_PORT_IN & RF_IRQ0_PIN) { RF_IRQ0_IFG(); // Clear interrupt flag; IRQ0TXST - transmit start with IRQ0 bit _NOP(); } if (RF_IRQ_PORT_IN & RF_IRQ1_PIN) { RF_IRQ1_IFG(); // Clear interrupt flag; TXDONE _NOP(); } // Wake up from low power mode __bic_SR_register_on_exit(LPM0_bits); }
BYTE OLED_RD_Data(void) { BYTE bRetValue; OLED_DATA_DIR = 0x00; // Port auf Eingabe schalten OLED_SET_DATA_MODE; // Data-Mode wählen OLED_RD_LOW; // RD auf low OLED_CS_LOW; // CS auf low _NOP(); bRetValue = OLED_DATA_IN; // Daten des SSD1309-Controllers sollten nun stabil anliegen OLED_RD_HIGH; // RD-Signal high setzen _NOP(); OLED_CS_HIGH; // CS-Signal high setzen und damit die Kommunikation abschließen return bRetValue; }
uint8_t get_key() { // Statements used to help handling with long key pressing. #define LAST_STATE_IGNORE (0xFF) static uint8_t last_state_row = LAST_STATE_IGNORE; static uint8_t last_state_col = LAST_STATE_IGNORE; if(last_state_col != LAST_STATE_IGNORE) { DDRD |= (1 << (last_state_col)); // No operation to get into steady state (without it long keypad pressing will spoil the code entered). _NOP(); _NOP(); if(!(PINC & (1 << (last_state_row + 2)))) { // Key still pressed. DDRD &= ~((1<<PD0) | (1<<PD1) | (1<<PD2)); return NONE; } // Key not pressed. Continue checking. last_state_row = last_state_col = LAST_STATE_IGNORE; } for(uint8_t col = 0; col < 3; col++) { DDRD &= ~((1<<PD0) | (1<<PD1) | (1<<PD2)); DDRD |= (1 << col); for (uint8_t row = 0; row < 4; row ++) { if(!(PINC & (1 << (row + 2)))) { DDRD &= ~((1<<PD0) | (1<<PD1) | (1<<PD2)); last_state_col = col; last_state_row = row; switch(row) { case 3: switch(col) { case 0: return '*'; case 1: return '0'; case 2: return '#'; default: break; } break; default: return (row * 3 + col + 1) + 48; } } } } DDRD &= ~((1<<PD0) | (1<<PD1) | (1<<PD2)); return NONE; }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD BCSCTL1 |= DIVA_3; // ACLK= LFXT1CLK/8 Set_DCO(); // Set DCO ME1 |= UTXE0 + URXE0; // Enabled USART0 TXD/RXD UCTL0 |= CHAR; // 8-bit character, SWRST = 1 UTCTL0 |= SSEL1 + SSEL0 + URXSE; // UCLK = SMCLK, start edge detect UBR00 = 0xD0; // 9600 from 2Mhz UBR10 = 0x00; UMCTL0 = 0x00; // No modulation UCTL0 &= ~SWRST; // Initialize USART state machine IE1 |= URXIE0; // Enable USART0 RX interrupt for (;;) { while (!(UTCTL0 & TXEPT)); // Confirm no TXing before --> LPM3 _DINT(); // Disable interrupts for flag test _NOP(); if (!(UTCTL0 & SSEL0)) _BIS_SR(LPM0_bits + GIE); // RX'ing char, enter LPM0, int's active else _BIS_SR(LPM3_bits + GIE); // Enter LPM3, int's active } }
void main(void) { volatile unsigned int i; // Use volatile to prevent removal // by compiler optimization WDTCTL = WDTPW + WDTHOLD; // Stop WDT FLL_CTL0 |= XCAP14PF; // Configure load caps for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to // stabilize SD16CTL = SD16REFON+SD16SSEL0; // 1.2V ref, SMCLK SD16CCTL2 |= SD16SNGL+SD16IE ; // Single conv, enable interrupt SD16INCTL2 |= SD16INCH_6; // Select Channel A6 for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup while (1) { SD16CCTL2 |= SD16SC; // Set bit to start conversion __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts DegC = ((unsigned long)ADCresult * 909)/65536 - 727; // Calculate degrees Celcius DegF = ((unsigned long)ADCresult * 1636)/65536 - 1276; // Calculate degrees Farenheit _NOP(); //SET BREAKPOINT HERE } }
/// Timer B0 interrupt service routine ISR(TIMERB1, Timer_B1) { /*P2OUT = (P2OUT & 0xf7) | (8 - (P2OUT & 0x08));*/ if(ir_pos <= 25) { if(ir_pos % 2) { // odd position if(ir_temp && !(P1IN & 0x04)) { // 1 - 0 --> write 1 recvdatabuffer +=1; recvdatabuffer = recvdatabuffer << 1; } else if(!ir_temp && (P1IN & 0x04)) { // 0 - 1 --> write 0 recvdatabuffer = recvdatabuffer << 1; } else { setErrorBit(); if(P1IN & 0x04) { recvdatabuffer += 1; } recvdatabuffer = recvdatabuffer << 1; } } else { // even position ir_temp = P1IN & 0x04; } } if(ir_pos == 25) { // end reached recvdatabuffer = recvdatabuffer >> 1; if(!recir_getError() && ( (recvdatabuffer & 0x0FFF) != (recvdata & 0x0FFF) ) ){ recvdata = recvdatabuffer; setDataAvailableBit(); } else { _NOP(); } }
void Delay(unsigned int time) { unsigned int i,k ; for(i=0;i<255;i++) for(k=0;k<time;k++) _NOP() ; }