Пример #1
1
void loop(void)
{
digitalwrite(0,HIGH);
Delayms(500);
digitalwrite(0,LOW);
Delayms(500);
}
Пример #2
0
/** Positive pulse on E */
void _lcd_pulseEnable(void)
{
	//digitalwrite(_enable_pin, LOW);
	//Delayus(1);    
	digitalwrite(_enable_pin, HIGH);
	//Delayus(1);    // enable pulse must be >450ns
	digitalwrite(_enable_pin, LOW);
	//Delayus(100);   // commands need > 37us to settle
}
Пример #3
0
// Returns the keykode of the pressed key, or NO_KEY if no key is pressed
char Keypad_getKey(){
    
    char key = NO_KEY; // Assume that no key is pressed, this is the default return for getKey()
    unsigned char c,r;    

	


    for (c=0; c<keypad_columns; c++){
		digitalwrite(columnPins[c],LOW);	// Activate the current column.
		for (r=0; r<keypad_rows; r++){	// Scan all the rows for a key press.
			//  The user pressed a button for more then debounceTime microseconds.
			if (currentKey == userKeymap[c+(r*keypad_columns)]){
				// Button hold
				if (((millis()-lastUpdate) >= holdTime) && digitalread(rowPins[r]) == LOW){
					Keypad_transitionTo(HOLD);
				}
				// Button release
				if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == HIGH){
					Keypad_transitionTo(RELEASED);
					currentKey = NO_KEY;
				}
			} 
			// Button pressed event.  The user pressed a button.
			else if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == LOW){
				digitalwrite(columnPins[c],HIGH);	// De-activate the current column.
				key = userKeymap[c+(r*keypad_columns)];
				lastUpdate = millis();
				goto EVALUATE_KEY; 			// Save resources and do not attempt to parse two keys at a time
			} 
		}
		digitalwrite(columnPins[c],HIGH);	// De-activate the current column.
	}
	
	EVALUATE_KEY:
 	//if (key != NO_KEY && key != currentKey ){ //Error: keeps repeating keys in the same column

	if (key != NO_KEY && key != currentKey && state!=PRESSED){ //Correction for simultaneous pressed keys on the same row

		
		// if(state ==HOLD && key != currentKey) //try to disable several keys pressed at the same time
		// 	return NO_KEY;
		 

	
		currentKey = key;
		Keypad_transitionTo(PRESSED);
		
		
		
		return currentKey;
	} 
	
	else{
		return NO_KEY;
	}
}
void blinkled_32(int pin, int repeat, unsigned int delay_on, unsigned int delay_off)
{
    int i;
    for (i=0; i<repeat; i++){
        digitalwrite(pin, 1);
        Delayms(delay_on);
        digitalwrite(pin, 0);
        Delayms(delay_off);
    }
}
Пример #5
0
void loop()
{
if (serial_available())
	{
	digitalwrite(0,HIGH);
	caractere=serial_read();
	serial_write("test");
	if (caractere=='A') digitalwrite(1,digitalread(1)^1);
	}
}
Пример #6
0
// a        LBA of sector requested
// p        pointer to sector buffer
// returns  TRUE if successful
int writeSECTOR(LBA a, char *p)
{
	unsigned r, i;

	// 0. check Write Protect
	if (getWP())
		return FAIL;

	// 1. send WRITE command
	r = sendSDCmd(WRITE_SINGLE, (a << 9));
	if (r == 0)    // check if command was accepted
	{
		// 2. send data
		writeSPI(DATA_START);

		// send 512 bytes of data
		for(i=0; i<512; i++)
		writeSPI(*p++);

		// 3. send dummy CRC
		clockSPI();
		clockSPI();

		// 4. check if data accepted
		r = readSPI();
		if ((r & 0xf) == DATA_ACCEPT)
		{
			#ifdef WRITE_LED
			digitalwrite(WRITE_LED, 0);
			#endif

			// 5. wait for write completion
			for(i=0; i<W_TIMEOUT; i++)
			{
				r = readSPI();
				if (r != 0 )
					break;
			}
			#ifdef WRITE_LED
			digitalwrite(WRITE_LED, 1);
			#endif
		} // accepted
		else
		{
			r = FAIL;
		}
	} // command accepted

	// 6. disable the card
	disableSD();

	return (r);      // return TRUE if successful
} // writeSECTOR
Пример #7
0
void lb_process() {
	if(lb_state == LB_S_WAIT_HIGH && check_timer(&lb_timer)) {
		// Waiting to go high, and timer is up
		digitalwrite(LB_LED_PIN, HIGH);
		start_ms_timer(&lb_timer, 1000);
		lb_state = LB_S_WAIT_LOW;
	}
	if(lb_state == LB_S_WAIT_LOW && check_timer(&lb_timer)) {
		// Waiting to go high, and timer is up
		digitalwrite(LB_LED_PIN, LOW);
		start_ms_timer(&lb_timer, 500);
		lb_state = LB_S_WAIT_HIGH;
	}
}
Пример #8
0
//private function
void Keypad_initializePins(){

	unsigned char c,r;

	for (r=0; r<keypad_rows; r++){
        for (c=0; c<keypad_columns; c++){
			pinmode(columnPins[c],OUTPUT);
			digitalwrite(columnPins[c],HIGH);
        }
		//configure row pin modes and states
		pinmode(rowPins[r],INPUT);
		digitalwrite(rowPins[r],HIGH);
    }
}
Пример #9
0
void touch_initTouch(unsigned char orient_tation){
    orient_t = orient_tation;

    pinmode(T_CLK,  OUTPUT);
    pinmode(T_CS,   OUTPUT);
    pinmode(T_DIN,  OUTPUT);
    pinmode(T_DOUT, INPUT);
    pinmode(T_IRQ,  INPUT);

    digitalwrite(T_CS,  HIGH);
    digitalwrite(T_CLK, HIGH);
    digitalwrite(T_DIN, HIGH);
    digitalwrite(T_CLK, HIGH);
}
Пример #10
0
int TM1638_getButtons(void)
{
  int i;
  int keys = 0;

  digitalwrite(TM16XX_strobePin, LOW);
  TM16XX_send(0x42);
  for (i = 0; i < 4; i++) {
    keys |= TM16XX_receive() << i;
  }
  digitalwrite(TM16XX_strobePin, HIGH);
  if (keys < -64) keys = 128;
  else keys = keys * -1;
  
  return keys;
}
Пример #11
0
unsigned int touch_readData(){
    unsigned char nop;
    unsigned int data = 0;
    unsigned char count;
    
    for(count=0; count<12; count++) {
	data <<= 1;
	digitalwrite(T_CLK, HIGH);	          
	nop++;
	digitalwrite(T_CLK, LOW);	
	nop++;
	if (digitalread(T_DOUT))
	    data++;
    }
    return(data);
}
Пример #12
0
void LedControl_init(u8 dataPin, u8 clkPin, u8 csPin, u8 numDevices)
{
    u8 i;
    
    LEDCONTROL_SPI_MOSI = dataPin;
    LEDCONTROL_SPI_CLK  = clkPin;
    LEDCONTROL_SPI_CS   = csPin;
    if(numDevices<=0 || numDevices>8 )
        numDevices=8;
    maxDevices=numDevices;
    pinmode(LEDCONTROL_SPI_MOSI,OUTPUT);
    pinmode(LEDCONTROL_SPI_CLK,OUTPUT);
    pinmode(LEDCONTROL_SPI_CS,OUTPUT);
    digitalwrite(LEDCONTROL_SPI_CS,HIGH);
    LEDCONTROL_SPI_MOSI=dataPin;
    for(i=0;i<64;i++) 
        status[i]=0x00;
    for(i=0;i<maxDevices;i++)
    {
        LedControl_spiTransfer(i,OP_DISPLAYTEST,0);
        //scanlimit is set to max on startup
        LedControl_setScanLimit(i,7);
        //decode is done in source
        LedControl_spiTransfer(i,OP_DECODEMODE,0);
        LedControl_clearDisplay(i);
        //we go into shutdown-mode on startup
        LedControl_shutdown(i,true);
    }
}
Пример #13
0
void setup()
{
for (i=0;i<8;i++) 	{
				pinmode(i,OUTPUT);
				digitalwrite(i,LOW);
				}
serial_begin(9600);
}
Пример #14
0
void shiftOut(u8 dataPin, u8 clockPin, u8 bitOrder, u8 val)
{
    u8 i;
    u8 bitMask;

    for (i = 0; i < 8; i++)
    {
        if (bitOrder == LSBFIRST)
            bitMask = (1 << i);
        else
            bitMask = (1 << (7 - i));

        digitalwrite(dataPin, (val & bitMask) ? HIGH : LOW);
        digitalwrite(clockPin, HIGH);
        digitalwrite(clockPin, LOW);            
    }
}
Пример #15
0
void initSD(void)
{
	digitalwrite(SDCS, HIGH);	// initially keep the SD card disabled
	pinmode(SDCS, OUTPUT);		// make Card select an output pin

	// init the spi module for a slow (safe) clock speed first
	SPI2CON = 0x8120;   // ON (0x8000), CKE=1 (0x100), CKP=0, Master mode (0x20)
	SPI2BRG = (GetPeripheralClock() / (2 * 250000)) - 1;
}   // initSD
Пример #16
0
u8 SPI_write(u8 module, u8 data_out)
{
    u8 i;
    u8 bitMask;

    switch(module)
    {
        case SPISW:
            for (i = 0; i < 8; i++)
            {
                // MSB first
                if (SPI[module].bitorder == SPI_MSBFIRST)
                    bitMask = 0x80 >> i;

                // LSB first
                else
                    bitMask = 1 << i;

                // Send bit
                digitalwrite(SPI[module].sda, (data_out & bitMask) ? 1 : 0);

                // pulse
                high(SPI[module].sck);
                low(SPI[module].sck);
            }
            return data_out;

        #if !defined(__32MX440F256H__)

        case SPI1:
            SPI1BUF = data_out;             // write to buffer for TX
            while (!SPI1STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI1BUF;

        #endif

        case SPI2:
            SPI2BUF = data_out;             // write to buffer for TX
            while (!SPI2STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI2BUF;

        #if defined(__32MX795F512L__) || \
            defined(__32MX795F512H__)

        case SPI3:
            SPI3BUF = data_out;             // write to buffer for TX
            while (!SPI3STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI3BUF;

        case SPI4:
            SPI4BUF = data_out;             // write to buffer for TX
            while (!SPI4STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI4BUF;

        #endif
    }
Пример #17
0
void LedControl_spiTransfer(u8 matrix, volatile u8 opcode, volatile u8 data)
{
    //Create an array with the data to shift out
    u8 offset=matrix*2;
    u8 maxbytes=maxDevices*2;
    u8 i;
    
    for(i=0;i<maxbytes;i++)
        spidata[i]=(u8)0;
    //put our device data into the array
    spidata[offset+1]=opcode;
    spidata[offset]=data;
    //enable the line 
    digitalwrite(LEDCONTROL_SPI_CS,LOW);
    //Now shift out the data 
    for(i=maxbytes;i>0;i--)
        shiftOut(LEDCONTROL_SPI_MOSI,LEDCONTROL_SPI_CLK,MSBFIRST,spidata[i-1]);
    //latch the data onto the display
    digitalwrite(LEDCONTROL_SPI_CS,HIGH);
}    
Пример #18
0
void touch_writeData(unsigned char data){
    unsigned char temp;
    unsigned char nop;
    unsigned char count;

    temp=data;
    digitalwrite(T_CLK,LOW);
    
    for(count=0; count<8; count++) {
	if(temp & 0x80)
		digitalwrite(T_DIN, HIGH);
	else
		digitalwrite(T_DIN, LOW);
	
	temp = temp << 1; 
	digitalwrite(T_CLK, LOW);	
	nop++;
	digitalwrite(T_CLK, HIGH);	
	nop++;
    }
}
Пример #19
0
void loop() {
  int thisPin;
//
  if (serial1available() > 0) {
    int inByte = serial1read();
//
//
//
//
//

    switch (inByte) {
    case 'a':    
      digitalwrite(2, HIGH);
      break;
    case 'b':    
      digitalwrite(3, HIGH);
      break;
    case 'c':    
      digitalwrite(4, HIGH);
      break;
    case 'd':    
      digitalwrite(5, HIGH);
      break;
    case 'e':    
      digitalwrite(6, HIGH);
      break;
    default:
//
      for (thisPin = 2; thisPin < 7; thisPin++) {
        digitalwrite(thisPin, LOW);
      }
    } 
  }
}
Пример #20
0
void loop(){
	
//
//
//
	x+=2;
	DrawCircle(x, 45, 10, BLACK);
	
	
	digitalwrite(LED, LOW);
	Delayms(10);	
	
	
	if (x > 115){
		DrawCircle(x, 20, 10, WHITE);
		x = 10;
	}
	ClearScreen(WHITE);
	
	digitalwrite(LED, HIGH);
	Delayms(10);
}
Пример #21
0
/** Send data to LCD 8 or 4 bits */
void _lcd_send(u8 value, u8 mode)
{
	digitalwrite(_rs_pin, mode);
  
	if (_displayfunction & LCD_8BITMODE)
	{
		_lcd_write8bits(value); 
	}
	else
	{
		_lcd_write4bits(value >> 4);	// Upper 4 bits first
		_lcd_write4bits(value);		    // Lower 4 bits second
	}
}
Пример #22
0
void lwn_setup() {
	  // LED_Blinker setup
	  pinmode(LWN_DATA_PIN,OUTPUT);
	  pinmode(LWN_CLK_PIN, OUTPUT);
	  digitalwrite(LWN_CLK_PIN, LOW);

	  lwn_state = LWN_S_WAIT_FOR_DATA_SET;
	  lwn_sub_state = LWN_SS_WRITE_ZEROS;

	  lwn_us_delay = 0;
	  lwn_bitmask = 0x80;
	  context->zeroCounter = ZEROS_NEEDED;
	  context->pixelIndex = 0;
	  lwn_timer.timer_delay = 1;	// needs to be 1 to prevent overflow and wait forever
	  reset_us_timer(&lwn_timer, lwn_us_delay);
}
Пример #23
0
}
void loop() 
{
i=1000;
if (usbavailable())
	{
	caractere=usbread();
	if (caractere=='W') if (usbavailable())
		{
		caractere1=usbread();
		caractere2=usbread();
		digitalwrite(caractere1,caractere2);
		if ((caractere1==0) && (caractere2==1))
			usbsendint(i);
		}
	}
Пример #24
0
// a        LBA of sector requested
// p        pointer to sector buffer
// returns  TRUE if successful
int readSECTOR(LBA a, char *p)
{
	int r, i;

	#ifdef READ_LED
	digitalwrite(READ_LED, 0);
	#endif

	// 1. send READ command
	r = sendSDCmd(READ_SINGLE, (a << 9));
	if (r == 0)    // check if command was accepted
	{
	// 2. wait for a response
	for(i=0; i<R_TIMEOUT; i++)
	{
	r = readSPI();
	if (r == DATA_START)
	break;
	}

	// 3. if it did not timeout, read 512 byte of data
	if (i != R_TIMEOUT)
	{
		i = 512;
		do{
			*p++ = readSPI();
		} while (--i>0);

		// 4. ignore CRC
		readSPI();
		readSPI();

	} // data arrived

	} // command accepted

	// 5. remember to disable the card
	disableSD();

	#ifdef READLED
	digital(READ_LED, 1);
	#endif

	return (r == DATA_START);    // return TRUE if successful
} // readSECTOR
Пример #25
0
void touch_read() {
    unsigned long tx=0;
    unsigned long ty=0;
    int i;
    
    digitalwrite(T_CS,LOW);
                  
    for (i=0; i<prec; i++){
	touch_writeData(0x90);        
	digitalwrite(T_CLK,HIGH);
	digitalwrite(T_CLK,LOW);	
	ty+=touch_readData();
	touch_writeData(0xD0);      
	digitalwrite(T_CLK,HIGH);	
	digitalwrite(T_CLK,LOW);
	tx+=touch_readData();
    }

    digitalwrite(T_CS,HIGH);
    
    TP_X=tx/prec;
    TP_Y=ty/prec;
}
Пример #26
0
void lwn_process() {
	u8 byteToSend;

//	if(lwn_state == LWN_S_WAIT_FOR_DATA_SET && check_timer(&lwn_timer)) {
	if(lwn_state == LWN_S_WAIT_FOR_DATA_SET) {
		if(lwn_sub_state == LWN_SS_WRITE_PIXEL) {
			byteToSend = (0x80 | lw_buffer[context->pixelIndex]);
			//CDCprintf("WRITE pixel idx: %u byte:%u mask: %u\n", lwn_pixelIndex, byteToSend, lwn_bitmask);
		} else {
			byteToSend = 0x00;
			//CDCprintf("WRITE zero count: %u mask: %u\n", lwn_zeroCounter, lwn_bitmask);
		}

		// Set data
		digitalwrite(LWN_DATA_PIN,  (byteToSend & lwn_bitmask) ? HIGH : LOW);

		// Set timer for next step
		lwn_timer.timer_delay = 1;	// needs to be 1 to prevent overflow and wait forever
		reset_us_timer(&lwn_timer, lwn_us_delay);
		lwn_state = LWN_S_WAIT_FOR_CLOCK_HIGH;

		// data preparation
		lwn_bitmask = lwn_bitmask >> 1;
		if(lwn_bitmask == 0) {
			// reset bitmask
			lwn_bitmask = 0x80;

			// byte done - what's gone be the next byte?
			if(lwn_sub_state == LWN_SS_WRITE_PIXEL) {
				// we're writing pixels, next pixel
				context->pixelIndex++;

				if(context->pixelIndex == (LEDS * 3)) {
					// all pixels sent
					lwn_sub_state = LWN_SS_WRITE_ZEROS;
					context->zeroCounter = ZEROS_NEEDED;
				}
			} else {
				// we're writing zeros
				context->zeroCounter--;
				if(context->zeroCounter == 0) {
					// all zeros sent
					lwn_sub_state = LWN_SS_WRITE_PIXEL;
					context->pixelIndex = 0;
				}
			}
		}
	}

//	if(lwn_state == LWN_S_WAIT_FOR_CLOCK_HIGH && check_timer(&lwn_timer)) {
	if(lwn_state == LWN_S_WAIT_FOR_CLOCK_HIGH) {
		//CDCprintf("SET CLK HIGH\n");
		// Set clock low
		digitalwrite(LWN_CLK_PIN, HIGH);

		// Set timer for next step
		lwn_timer.timer_delay = 1;	// needs to be 1 to prevent overflow and wait forever
		reset_us_timer(&lwn_timer, lwn_us_delay * 2); // for a symetric clock (might be omitted for optimization)
		lwn_state = LWN_S_WAIT_FOR_CLOCK_LOW;
	}

//	if(lwn_state == LWN_S_WAIT_FOR_CLOCK_LOW && check_timer(&lwn_timer)) {
	if(lwn_state == LWN_S_WAIT_FOR_CLOCK_LOW) {
		//CDCprintf("SET CLK LOW\n");
		// Set clock low
		digitalwrite(LWN_CLK_PIN, LOW);

		// Set timer for next step
		lwn_timer.timer_delay = 1;	// needs to be 1 to prevent overflow and wait forever
		reset_us_timer(&lwn_timer, lwn_us_delay);
		lwn_state = LWN_S_WAIT_FOR_DATA_SET;
	}
}
Пример #27
0
void loop() 
{
	digitalwrite(0,HIGH);
	digitalwrite(1,HIGH);
	digitalwrite(2,HIGH);
	digitalwrite(3,HIGH);
	digitalwrite(4,HIGH);
	digitalwrite(5,HIGH);
	digitalwrite(6,HIGH);
	digitalwrite(7,HIGH);
	digitalwrite(8,HIGH);
	digitalwrite(9,HIGH);
	digitalwrite(10,HIGH);
	digitalwrite(11,HIGH);
	digitalwrite(12,HIGH);
}	
Пример #28
0
/*	-----------------------------------------------------------------------
---------- KS_DHTRead()
-----------------------------------------------------------------------
* Description:	reads the dht22 device via 1-wire bus 
* Arguments:	
dhpin = pin number where one wire bus is connected.
dh = data record
return errorcode or 0
--------------------------------------------------------------------*/
u8 KS_DHTRead(u8 dhpin,KS_DHT_Data * dh)
{
u16 timeout;
double h,t;
u8 DHTDAT[5]={0};
u8 DHTCHECKSUM;
u8 i,j;
u8 dhtbyte=0;

h=0;
t=0;
if (digitalread(dhpin)==LOW) {return 1;}	 // Bus not free
pinmode(dhpin,OUTPUT); 
digitalwrite(dhpin,LOW);	 // MCU start signal (>=500us) 
Delayms(1);
//Request Data
pinmode(dhpin,INPUT);
timeout = wt; 
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 2;}}	 // Wait for DHT’s response (20-40us)
timeout = wt;
while(!digitalread(dhpin)) {timeout--;if (timeout==0) {return 3;}}	 // Response signal (80us)
timeout = wt;	
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 4;}}	 // Preparation for sending data (80us)
//Read Data
for(i=0;i<5;i++)
{
for(j=1;j<=8;j++)
{
timeout = wt;
while(digitalread(dhpin)==LOW) {timeout--;if (timeout==0) {return 5;}}	 // Start to transmit 1-Bit (50 us)
Delayus(30);
dhtbyte <<= 1;
if (digitalread(dhpin))	 // Hi > 30us (70 us) -> Bit=1	
{
dhtbyte |= 1;
timeout = wt;
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 6;}}	
}	 // Hi < 30us (26-28 us) -> Bit=0	
}
DHTDAT[i] = dhtbyte;
}

DHTCHECKSUM = DHTDAT[0]+DHTDAT[1]+DHTDAT[2]+DHTDAT[3];
if (DHTCHECKSUM != DHTDAT[4]) // Checksum	
{
return 7;	
}	
dh->sign = 0; 

if (DHTDAT[2] & 0b11111000)	// test if sign is set, i.e. negative
{	
dh->sign = 1;
DHTDAT[2] = (DHTDAT[2] ^ 0xFFFF) + 1;	// 2's complement conversion
}

h=(DHTDAT[0]<<8)+DHTDAT[1];
t=(DHTDAT[2]<<8)+DHTDAT[3];
dh->hum=h/10;
dh->temp=t/10;
return 0;
}
Пример #29
0
/** Initial Display settings! */
void _lcd_begin(u8 lines, u8 dotsize)
{
	if (lines > 1)
		_displayfunction |= LCD_2LINE;

	_numlines = lines;
	_currline = 0;

	// Some one line displays can select 10 pixel high font
	if ((dotsize != 0) && (lines == 1))
		_displayfunction |= LCD_5x10DOTS;

	Delayms(15); //Pinguino needs it? long delay on startup time!

	// Now we pull both RS and R/W low to begin commands
	digitalwrite(_rs_pin, LOW);
	digitalwrite(_enable_pin, LOW);

	//put the LCD into 4 bit mode
	if (! (_displayfunction & LCD_8BITMODE) )
	{
		// this is according to the hitachi HD44780 datasheet p46, figure 24

		// we start in 8bit mode, try to set 4 bit mode
		_lcd_write4bits(0x03);
		Delayms(5); // wait min 4.1ms
		// second try
		_lcd_write4bits(0x03);
		Delayus(150); // wait min 4.1ms
		// third go!
		_lcd_write4bits(0x03); 
		Delayus(150);
		// finally, set to 8-bit interface
		_lcd_write4bits(0x02); 
	}
	//put the LCD into 8 bit mode
	else
	{
		// this is according to the hitachi HD44780 datasheet p45, figure 23

		// Send function set command sequence
		_lcd_command(LCD_FUNCTIONSET | _displayfunction);
		Delayus(4500);  // wait more than 4.1ms

		// second try
		_lcd_command(LCD_FUNCTIONSET | _displayfunction);
		Delayus(150);

		// third go
		_lcd_command(LCD_FUNCTIONSET | _displayfunction);
	}

	// finally, set # lines, font size, etc.
	_lcd_command(LCD_FUNCTIONSET | _displayfunction);  

	// turn the display on with no cursor or blinking default
	_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
	_lcd_display();

	// clear it off
	_lcd_clear();

	// Initialize to default text direction (for romance languages)
	_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
	// set the entry mode
	_lcd_command(LCD_ENTRYMODESET | _displaymode);
}
Пример #30
0
void Timer3Interrupt()
{
    if (IntGetFlag(INT_TIMER3)) // Timer3 interrupt ?
    {
        irdata = digitalread(irparams.recvpin);

        irparams.timer++; // One more 50us tick
        
        // Buffer overflow ?
        if (irparams.rawlen >= RAWBUF)
            irparams.rcvstate = STATE_STOP;

        switch(irparams.rcvstate)
        {
            // In the middle of a gap
            case STATE_IDLE:
                if (irdata == MARK)
                {
                    // Not big enough to be a gap.
                    if (irparams.timer < GAP_TICKS)
                        irparams.timer = 0;

                    // gap just ended, record duration and start recording transmission
                    else
                    {
                        irparams.rawlen = 0;
                        irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                        irparams.timer = 0;
                        irparams.rcvstate = STATE_MARK;
                    }
                }
                break;

            // timing MARK
            case STATE_MARK:

                // MARK ended, record time
                if (irdata == SPACE)
                {
                  irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                  irparams.timer = 0;
                  irparams.rcvstate = STATE_SPACE;
                }
                break;

            // timing SPACE
            case STATE_SPACE:

                // SPACE just ended, record it
                if (irdata == MARK)
                {
                    irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                    irparams.timer = 0;
                    irparams.rcvstate = STATE_MARK;
                } 

                // SPACE
                else
                {
                    // big SPACE, indicates gap between codes
                    // Mark current code as ready for processing
                    // Switch to STOP
                    // Don't reset timer; keep counting space width
                    if (irparams.timer > GAP_TICKS)
                        irparams.rcvstate = STATE_STOP;
                }
                break;

            // waiting, measuring gap
            case STATE_STOP:

                // reset gap timer
                if (irdata == MARK)
                    irparams.timer = 0;
                break;
        }

        if (irparams.blinkflag)
        {
            if (irdata == MARK)
                digitalwrite(USERLED, 1);  // turn USERLED on
            else
                digitalwrite(USERLED, 0);  // turn USERLED off
        }

        // Timer3 flag reset
        IntClearFlag(INT_TIMER3);
    }
}