Esempio n. 1
0
uint16_t usr_measure(void)
{
    static bool led = true;
    volatile uint32_t result;
    //enable USR
    set_pin(USR_EN_PIN);
    if (led)
    {
        set_pin(BRD_LED_PIN);
        led = false;
    }
    else
    {
        clear_pin(BRD_LED_PIN);
        led = true;
    }
    
    //delay 20us
    nrf_delay_us(20);
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    NRF_ADC->EVENTS_END = 0;
    NRF_ADC->TASKS_START = 1;
    while (NRF_ADC->EVENTS_END == 0);
    //unenable USR
    clear_pin(USR_EN_PIN);
    result = NRF_ADC->RESULT;
    NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Disabled;
    return result;
}
Esempio n. 2
0
void ht1632_fill2(uns8 colour) {

uns16 count;
	ht1632_send_command(HT1632_CMD_LEDS_OFF);
	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	
	// send WR command

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);
	
	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send mem address of zero
	clear_pin(ht1632_data_port, ht1632_data_pin);
	
	// write mem addr, bits 6 -> 0
	for(count = 0 ; count < 7 ; count++) {
			
		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6));
		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift mem addr along

	}
	if (colour) {
		set_pin(ht1632_data_port, ht1632_data_pin);
	} else {
		clear_pin(ht1632_data_port, ht1632_data_pin);
	}
	// we need to toggle 384 times
	
	for(count = 0 ; count < 384 ; count++) {
		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift mem addr along

	}
	// reset CS

	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
	ht1632_send_command(HT1632_CMD_LEDS_ON);

	
}
Esempio n. 3
0
void ht1632_write(uns8 mem_addr, uns8 data) {

uns8 count;
	
	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	
	// send WR command

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);
	
	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// write mem addr, bits 6 -> 0
	for(count = 0 ; count < 7 ; count++) {
		if (test_bit(mem_addr, 6)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else { 
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}
	
		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6));
		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift mem addr along
		mem_addr = mem_addr << 1;
	}

	// write data, bits 0 -> 3 (different from mem addr format)
	for(count = 0 ; count < 4 ; count++) {
		change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(data, 0));
		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift mem addr along
		data = data >> 1;
	}
	// reset CS

//	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
//	delay_ms(1);
//	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
	
	
}
Esempio n. 4
0
void sure_2416_send_command(uns8 command) {

uns8 count;
	
	clear_pin(sure_2416_cs1_port, sure_2416_cs1_pin);
	
	// send  command
	// send 1
	set_pin  (sure_2416_data_port, sure_2416_data_pin);
	// pulse wr
	clear_pin(sure_2416_wr_port, sure_2416_wr_pin);
	set_pin  (sure_2416_wr_port, sure_2416_wr_pin);
	
	// send 0
	clear_pin  (sure_2416_data_port, sure_2416_data_pin);
	// pulse wr
	clear_pin(sure_2416_wr_port, sure_2416_wr_pin);
	set_pin  (sure_2416_wr_port, sure_2416_wr_pin);

	// send 0
	clear_pin  (sure_2416_data_port, sure_2416_data_pin);
	// pulse wr
	clear_pin(sure_2416_wr_port, sure_2416_wr_pin);
	set_pin  (sure_2416_wr_port, sure_2416_wr_pin);

	// command bits 7 - 0
	for(count = 0 ; count < 8 ; count++) {

		if (test_bit(command, 7)) {
			set_pin(sure_2416_data_port, sure_2416_data_pin);
		} else {
			clear_pin(sure_2416_data_port, sure_2416_data_pin);
		}
		//change_pin_var(sure_2416_data_port, sure_2416_data_pin, test_bit(command, 7));
		// pulse wr
		clear_pin(sure_2416_wr_port, sure_2416_wr_pin);
		set_pin  (sure_2416_wr_port, sure_2416_wr_pin);
		// shift mem addr along
		command = command << 1;
	}

	// the don't care pulse
	
		clear_pin(sure_2416_wr_port, sure_2416_wr_pin);
		set_pin  (sure_2416_wr_port, sure_2416_wr_pin);

	// reset CS??

// don't think we need this
//	set_pin(sure_2416_cs1_port, sure_2416_cs1_pin);
//	delay_ms(1);
//	clear_pin(sure_2416_cs1_port, sure_2416_cs1_pin);

	set_pin(sure_2416_cs1_port, sure_2416_cs1_pin);
}
Esempio n. 5
0
uint8_t rf01_rxstart(void) {

	if(RF01_status.New)
		return(1);			//bufor jeszcze nie pusty

	if(RF01_status.Rx)
		return(3);			//trwa odbieranie


	rf01_trans(0xC0C1|((sgain&3)<<4)|((sdrssi&7)<<1));	// RX on
		rf01_trans(0xCE88);			// set FIFO mode
		rf01_trans(0xCE8B);			// enable FIFO


	clear_pin(RF_PORT, SDI);


	//cbi(RF_PORT, SDO); //SDI input

	RF01_Index = 0;
	RF01_status.Rx = 1;



	return(0);				//wszystko w porz¹dku
}
Esempio n. 6
0
uns8 mrf24j40_long_addr_read(uns16 addr){

	uns8 result;
        #ifndef __PIC32MX__	
	        clear_pin(mrf24j40_cs_port, mrf24j40_cs_pin);

	        addr = addr & 0b0000001111111111; 	// <9:0> bits
	        addr = addr << 5;
	        set_bit(addr, 15);	// long addresss
	        spi_hw_transmit(addr >> 8);
	        spi_hw_transmit(addr & 0x00ff);
	        result = spi_hw_receive();	

	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif
        #ifdef __PIC32MX__
			ZIGCS=0;
			addr=((addr<<1)&0x7FE)|0x800;
			addr<<=4;
			SPI_write(addr>>8);
			SPI_write(addr);
			result=SPI_read();
			ZIGCS=1;        
        #endif
	return result;
}	
Esempio n. 7
0
void mrf24j40_long_addr_write(uns16 addr, uns8 data){

        #ifndef __PIC32MX__
	        clear_pin(mrf24j40_cs_port, mrf24j40_cs_pin);

	        addr = addr & 0b0000001111111111; 	// <9:0> bits
	        addr = addr << 5;

	        set_bit(addr, 15);	// long addresss
	        set_bit(addr, 4);	// set for write

	        spi_hw_transmit(addr >> 8 );
	        spi_hw_transmit(addr & 0x00ff);
	        spi_hw_transmit(data);
	
	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif
        #ifdef __PIC32MX__
			ZIGCS=0;
			addr=((addr<<1)&0x7FF)|0x801;
			addr<<=4;
			SPI_write(addr>>8);
			SPI_write(addr);
			SPI_write(data);
			ZIGCS=1;     
		#endif   	        
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
  int pin;
  if(argc < 2)
    {
      printf("USAGE: setlp0pin pin#\n");
      exit(1);
    }
  pin = atoi(argv[1]);
  if (pin_init_user(LPT1) < 0)
    exit(0);
  pin_output_mode(LP_DATA_PINS | LP_SWITCHABLE_PINS);

  if(pin < 0)  // clear requested
    {
      pin = pin * -1;
      clear_pin(LP_PIN[pin]);
      printf("pin# %d cleared\n", pin);
    }
  else
    {

      set_pin(LP_PIN[pin]);
      printf("pin# %d set.  Run \"setlp0pin -%d\" to clear pin# %d\n", pin, pin, pin);
    }
  return 0;
}
Esempio n. 9
0
int main (void)
{
    unsigned int ret, i, j, k;
    tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
    
    printf("\nINFO: Starting %s example.\r\n", "pru_gpio");
    /* Initialize the PRU */
    prussdrv_init ();		

    //NOTE : The PRU code does not export the PIN so this must be
    //done for any pin that used.
    LOCAL_export_pin(32 + 16,"out"); //GPIO1_16
    LOCAL_export_pin(32 + 13,"in");  //GPIO1_13

    /* Open PRU Interrupt */
    ret = prussdrv_open(PRU_EVTOUT_0);
    if (ret)
    {
        printf("prussdrv_open open failed\n");
        return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Initialize example */
    printf("\tINFO: Initializing example.\r\n");
    LOCAL_exampleInit();

    //Start th emain loop
    pruDataMem_byte[CMD_VALUE] = CMD_NO_OP;
    
    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./pru_gpio.bin");

    //The PRU is just configured to use GPIO1 for now.  This can be changed easily in the assembly.
    set_pin(16); //GPIO1_16
    clear_pin(16);
    int value = read_pin(13); //GPIO1_13

    printf("PIN value is %d\n",value); 

    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    LOCAL_unexport_pin(38);

    return(0);

}
Esempio n. 10
0
void usr_init(uint32_t pin)
{
    gpio_pin_out_init(USR_EN_PIN);
    clear_pin(USR_EN_PIN);
    // Sets up PIN as an analogue input
    NRF_ADC->CONFIG = ((ADC_CONFIG_RES_8bit                             << ADC_CONFIG_RES_Pos) | \
                       (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) | \
                       (ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling      << ADC_CONFIG_REFSEL_Pos) | \
                       (ADC_CONFIG_PSEL_AnalogInput6                    << ADC_CONFIG_PSEL_Pos) | \
                       (ADC_CONFIG_EXTREFSEL_None                       << ADC_CONFIG_EXTREFSEL_Pos));
}
Esempio n. 11
0
void rf01_trans(unsigned short val)
{	unsigned char i;

	clear_pin(RF_PORT, CS);
	for (i=0; i<16; i++)
	{	if (val&32768)
			set_pin(RF_PORT, SDI);
		else
			clear_pin(RF_PORT, SDI);
		set_pin(RF_PORT, SCK);
		val<<=1;


		//delay_us(1);
		delay_200ns();

		clear_pin(RF_PORT, SCK);
	}
	set_pin(RF_PORT, CS);
}
Esempio n. 12
0
void main(int argc, char * argv[]) 
{
	//Set up gpio to be pointer to chunk of memory that includes I/O.
	//gets around virtual memory issues too.
	gpio=init_memmap();
	
	set_dir(38,OUT);
	while(1)
	{
		set_pin(38);
		clear_pin(38);
	}
}
Esempio n. 13
0
void pwm(void *arg){
 	double duty_cycle=0,Ton=0;
	long current_period=0;
	int DIR;

	current_period=gs->period*1000;
	rt_task_set_periodic(NULL, TM_NOW,current_period);
	while (running) {
		rt_task_wait_period(NULL);
		
		DEBUG("Hi guys %ld, %4.2f!\n",current_period,Ton);

		duty_cycle=io.input_result[0].matrix[0][0];

		//saturate
		if(duty_cycle<-100)
			duty_cycle=-100;
		if(duty_cycle>100)
			duty_cycle=100;

		//Motor specific.
		if(duty_cycle<0){
			DIR=1;
			duty_cycle=100+duty_cycle;
		}
		else{
			DIR=0;
		}
		Ton=duty_cycle*0.01*current_period;

		lpt_lock();
		fakeWave=1;
		set_pin(PWM);
                change_pin(DIRE,DIR?LP_SET:LP_CLEAR);
		lpt_unlock();

		rt_task_sleep(Ton);

		lpt_lock();
		fakeWave=0;
		clear_pin(PWM);
		lpt_unlock();
		
		if(current_period==0)
			break;
		if(current_period!=gs->period*1000){
			current_period=gs->period*1000;
			rt_task_set_periodic(NULL, TM_NOW,current_period);
		}
	}
}
Esempio n. 14
0
void rf01_rxdata(unsigned char *data, unsigned char number)
{	unsigned char i,j,c;

	rf01_trans(0xC0C1|((sgain&3)<<4)|((sdrssi&7)<<1));	// RX on
	rf01_trans(0xCE89);			// set FIFO mode
	rf01_trans(0xCE8B);			// enable FIFO
	clear_pin(RF_PORT, SDI); //SDI = LOW
	for (i=0; i<number; i++){
		clear_pin(RF_PORT, CS);
		//while (!(RF_PIN&(1<<SDO))); // wait until data in FIFO
		while (!(GPIO_ReadInputDataBit(RF_PORT,SDO))); // wait until data in FIFO
		for (j=0; j<16; j++)	// read and discard status register
		{	set_pin(RF_PORT, SCK);
			asm("nop");
			clear_pin(RF_PORT, SCK);
		}
		c=0;
		for (j=0; j<8; j++)
		{	c<<=1;
			//if (RF_PIN&(1<<SDO))
		if(GPIO_ReadInputDataBit(RF_PORT,SDO))
				c|=1;
			set_pin(RF_PORT, SCK);

			//delay_us(1);
			delay_200ns();



			clear_pin(RF_PORT, SCK);
		}
		*data++=c;
		set_pin(RF_PORT, CS);
	}
	//blinkLED();
	rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1));	// RX off
}
Esempio n. 15
0
uns8 mrf24j40_short_addr_read(uns8 addr)
{
        #ifndef __PIC32MX__
	        clear_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
	        addr = addr & 0b00111111;	// <5:0> bits
	        addr = addr << 1;	// LSB = 0, means read
	        spi_hw_transmit(addr);
	        uns8 result = spi_hw_receive();
	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif
        #ifdef __PIC32MX__
	        addr = (addr << 1) & 0x7E;
	        ZIGCS=0; // CS must be held low while communicationg with MRF24J40
	        SPI_write(addr);
	        u8 result = SPI_read();
	        ZIGCS=1; // end of communication
        #endif	                	        
	return result;
}	
Esempio n. 16
0
void mrf24j40_short_addr_write(uns8 addr, uns8 data) {
        #ifndef __PIC32MX__
	        clear_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
	        addr = addr & 0b00111111;	// <5:0> bits
	        addr = addr << 1;	// LSB = 0, means read
	        set_bit(addr, 0);	// write

	        spi_hw_transmit(addr);
	        spi_hw_transmit(data);

	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif
        #ifdef __PIC32MX__
        	addr=((addr<<1)&0x7F)|1;
			ZIGCS=0;
			SPI_write(addr);
			SPI_write(data);
			ZIGCS=1;
		#endif	
}	
Esempio n. 17
0
static void ISR_timer0_a1() {
    _BIC_SR(GIE);

    switch(TAIV)
    {
        case 0x02:
            clear_pin(PWM_PINS[current_servo]);

            if(current_servo == 0)
            {
                TA0CCR0 = last_period;
            } else {
                TA0CCR0 = norm_period;
            }
            break;

        default:

            break;
    }

    _BIS_SR_IRQ(GIE);
}
Esempio n. 18
0
static void
stage1_prepare_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
{
	NMDevice *device = NM_DEVICE (user_data);
	GError *error = NULL;

	dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID);
	if (!error)
		nm_device_activate_schedule_stage2_device_config (device);
	else {
		const char *required_secret = NULL;
		gboolean retry_secret = FALSE;

		if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_PIN))
			required_secret = NM_SETTING_GSM_PIN;
		else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_WRONG)) {
			clear_pin (device);
			required_secret = NM_SETTING_GSM_PIN;
			retry_secret = TRUE;
		} else
			nm_warning ("GSM modem connection failed: %s", error->message);

		if (required_secret) {
			nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
			nm_act_request_get_secrets (nm_device_get_act_request (device),
			                            NM_SETTING_GSM_SETTING_NAME,
			                            retry_secret,
			                            SECRETS_CALLER_GSM,
			                            required_secret,
			                            NULL);
		} else
			nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, translate_mm_error (error));

		g_error_free (error);
	}
}
Esempio n. 19
0
void ht1632_send_command(uns8 command) {

uns8 count;
	
	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	clear_pin(ht1632_cs2_port, ht1632_cs2_pin);
	clear_pin(ht1632_cs3_port, ht1632_cs3_pin);
	clear_pin(ht1632_cs4_port, ht1632_cs4_pin);
	
	// send  command
	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);
	
	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// command bits 7 - 0
	for(count = 0 ; count < 8 ; count++) {

		if (test_bit(command, 7)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else {
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}

		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift mem addr along
		command = command << 1;
	}

	// the don't care pulse
	
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);


	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
	set_pin(ht1632_cs2_port, ht1632_cs2_pin);
	set_pin(ht1632_cs3_port, ht1632_cs3_pin);
	set_pin(ht1632_cs4_port, ht1632_cs4_pin);
}
Esempio n. 20
0
int main(int argc, char *argv[]){
    if (pin_init_user(LPT_PCI) < 0) {
        return -1;
    }
    pin_output_mode(LP_DATA_PINS | LP_SWITCHABLE_PINS);

    if (argc == 1) {
        show_help(argv[0]);
        return -1;
    }

    int c = 0;
    int i = -1;
    long int to_set_pin = -1;
    long int to_unset_pin = -1;
    long int sleep = -1;
    char *port_conv_end = NULL;

    while ((c = getopt(argc, argv, "hcs:u:z:")) != -1) {
        switch (c) {
            case 'h':
                show_help(argv[0]);
                break;
            case 'c':
                fprintf(stderr, "unset all\n");
                for (i = PIN_MIN; i <= PIN_MAX; ++i) {
                    clear_pin(LP_PIN[i]);
                }
                break;
            case 's':
                to_set_pin = strtol(optarg, &port_conv_end, 10);
                if (PIN_MIN <= to_set_pin && to_set_pin <= PIN_MAX) {
                    fprintf(stderr, "set pin %ld\n", to_set_pin);
                    set_pin(LP_PIN[to_set_pin]);
                }
                else {
                    fprintf(stderr, OUT_OF_RANGE);
                    return -1;
                }
                break;
            case 'u':
                to_unset_pin = strtol(optarg, &port_conv_end, 10);
                if (PIN_MIN <= to_unset_pin && to_unset_pin <= PIN_MAX) {
                    fprintf(stdout, "unset pin %ld\n", to_unset_pin);
                    clear_pin(LP_PIN[to_unset_pin]);
                }
                else {
                    fprintf(stderr, OUT_OF_RANGE);
                    return -1;
                }
                break;
            case 'z':
                sleep = strtol(optarg, &port_conv_end, 10);
                if (0 < sleep) {
                    fprintf(stderr, "sleeping for %ldms\n", sleep);
                    sleep = sleep * 1000; /* to milliseconds */
                    usleep(sleep);
                }
                else {
                    fprintf(stderr, "invalid sleep value");
                    return -1;
                }
                break;
            default:
                show_help(argv[0]);
                return -1;
        }
    }

    return 0;
}
Esempio n. 21
0
void EXTI0_IRQHandler(void) {
	unsigned char i,j,c;

  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
    /* Toggle LED1 */

	  GPIO_SetBits(GPIOD,GPIO_Pin_12);

	  if(RF01_Index < RF01_DataLength){
	//for (i=0; i<RF01_DataLength; i++){
	  clear_pin(RF_PORT, CS);
	  while (!(GPIO_ReadInputDataBit(RF_PORT,SDO))); // wait until data in FIFO


    		for (j=0; j<16; j++)	// read and discard status register
    		{	set_pin(RF_PORT, SCK);
    			asm("nop");
    			asm("nop");
    			clear_pin(RF_PORT, SCK);
    		}
    		c=0;
    		for (j=0; j<8; j++)
    		{	c<<=1;
    			//if (RF_PIN&(1<<SDO))


    		if(GPIO_ReadInputDataBit(RF_PORT,SDO))
    				c|=1;
    			set_pin(RF_PORT, SCK);

    			//delay_us(1);
    			delay_200ns();



    			clear_pin(RF_PORT, SCK);
    		}
    		RF01_Data[RF01_Index++]=c;
    		set_pin(RF_PORT, CS);

	  //}
	  } else {

		rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1));	// RX off

		RF01_status.Rx = 0;
		RF01_status.New = 1;
		return; 				// na pewno bêdzie b³êdna ramka
	  }

	  if(RF01_Index >= 12) {

		//rf12_trans(0x8208); //idle mode
		rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1));	// RX off

		RF01_status.Rx = 0;
		RF01_status.New = 1;	// poprawnie zakoñczona ramka
	}

	  //while (!(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)));


    /* Clear the EXTI line 0 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line0);
  }

}
Esempio n. 22
0
void ht1632_set_pixel(uns8 x, uns8 y, uns8 colour) {

uns8 common, panel, led_in_panel, inverted_x, out, mem_addr, bit_in_mem_addr, count, data;

	// first calculate memory address
	
	// y location on panels is top left based
	
	common = 15 - y;
	
/* Previous calculations:
	panel = x / 8;	// which panel of the three is it that we need to change?
	led_in_panel = x - (panel * 8); 
	inverted_x = 7 - led_in_panel;
	out = panel * 8 + led_in_panel; //inverted_x;
	mem_addr = out * 4 + common / 4;
*/
	bit_in_mem_addr = common & 0b00000011;
	

	mem_addr = x * 4 + common / 4;


	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);

	// send WR command

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);
	
	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// write mem addr, bits 6 -> 0
	for(count = 0 ; count < 7 ; count++) {
		if (test_bit(mem_addr, 6)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else { 
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}

		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6));
		// pulse rd
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);

		// shift mem addr along
		mem_addr = mem_addr << 1;
	}

	// Retrieve 4 bits
	// read clocked out on falling edge of RD
	
	make_input(ht1632_data_port, ht1632_data_pin);

	for(count = 0 ; count < 4 ; count++) {
		// pulse rd
		clear_pin(ht1632_rd_port, ht1632_rd_pin);

		data = data >> 1;
		data.3 = test_pin(ht1632_data_port, ht1632_data_pin);

		set_pin  (ht1632_rd_port, ht1632_rd_pin);

	}

	make_output(ht1632_data_port, ht1632_data_pin);

	// now we have the data, we need to change the bit
	if (colour) {
		set_bit(data, bit_in_mem_addr);
	} else {
		clear_bit(data, bit_in_mem_addr);
	}	
	
	// Now write it back out again
	
	// write data, bits 0 -> 3 (different from mem addr format)
	for(count = 0 ; count < 4 ; count++) {
		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(data, 0));
		if (test_bit(data, 0)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else { 
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}

		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift data along
		data = data >> 1;
	}
	
	
	// reset CS
	// don't think this is necessary
//	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
//	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	set_pin  (ht1632_cs1_port, ht1632_cs1_pin);
	
	
}