示例#1
0
	void Blink( uint32 count, uint32 time ) {
		
		// Loop 'count' times.
		for( ; count > 0; count-- ) {
			// Turn on the light.
			SetGPIO( 16, true );
			// Wait
			Wait( time );
			// Turn the light off.
			SetGPIO( 16, false );
			// Wait
			Wait( time );
		}
		
	}
示例#2
0
int LCD_Display(uint16_t num)
{
	//convertToASCII
	uint8_t displayChar = ConvertToASCII(num);
	
	//place the ASCII character on the D0-D7 lines
	uint8_t i = 0;
	uint8_t result;
	uint8_t andBit = 1;
	while (i < 8){												//for each bit in the ascii character
		result = displayChar & andBit;			//check if that bit is 1
		if(result){ 												//if bit is 1, set the resulting GPIO pin
			SetGPIO(i);
		}else{
			ResetGPIO(i); 										//otherwise, reset the resulting GPIO pin
		}i++;																//increment bit number
		andBit = andBit << 1;								//multiply number used for and-ing by 2
	}
	
	//register Select = 1 to send characters
	GPIO_SetBits(GPIOB, GPIO_Pin_1);
	//Enable pulse (set high - delay - set low)
	GPIO_SetBits(GPIOE, GPIO_Pin_9);
	//delay
	GPIO_ResetBits(GPIOE, GPIO_Pin_9);
	//delay to give LCD the time neeeded to display the character
}
示例#3
0
/*****************************************************************************

 * filename	: wrgpio
 * function	: print version info
 * author	version		date		note
 * feller	1.0		20160101	create         
 ******************************************************************************/
 int wrgpio(  const int iGPIOnumber, const char cvalue  )
 {
	SetGPIO( iGPIOnumber, cvalue );
	return LENA_OK;
 }
示例#4
0
static ICACHE_RAM_ATTR void timer1Interrupt() {
  uint32_t nextEventCycles;
  #if F_CPU == 160000000
  uint8_t cnt = 20;
  #else
  uint8_t cnt = 10;
  #endif

  do {
    nextEventCycles = MicrosecondsToCycles(MAXIRQUS);
    for (size_t i = 0; i < countof(waveform); i++) {
      Waveform *wave = &waveform[i];
      uint32_t now;

      // If it's not on, ignore!
      if (!wave->enabled) {
        continue;
      }

      // Check for toggles
      now = GetCycleCount();
      int32_t cyclesToGo = wave->nextServiceCycle - now;
      if (cyclesToGo < 0) {
        wave->state = !wave->state;
        if (wave->state) {
          SetGPIO(wave->gpioMask);
          if (wave->gpio16Mask) {
            GP16O |= wave->gpio16Mask; // GPIO16 write slow as it's RMW
          }
          wave->nextServiceCycle = now + wave->nextTimeHighCycles;
          nextEventCycles = min_u32(nextEventCycles, wave->nextTimeHighCycles);
        } else {
          ClearGPIO(wave->gpioMask);
          if (wave->gpio16Mask) {
            GP16O &= ~wave->gpio16Mask;
          }
          wave->nextServiceCycle = now + wave->nextTimeLowCycles;
          nextEventCycles = min_u32(nextEventCycles, wave->nextTimeLowCycles);
        }
      } else {
        uint32_t deltaCycles = wave->nextServiceCycle - now;
        nextEventCycles = min_u32(nextEventCycles, deltaCycles);
      }
    }
  } while (--cnt && (nextEventCycles < MicrosecondsToCycles(4)));

  uint32_t curCycleCount = GetCycleCount();
  uint32_t deltaCycles = curCycleCount - lastCycleCount;
  lastCycleCount = curCycleCount;

  // Check for timed-out waveforms out of the high-frequency toggle loop
  for (size_t i = 0; i < countof(waveform); i++) {
    Waveform *wave = &waveform[i];
    if (wave->timeLeftCycles) {
      // Check for unsigned underflow with new > old
      if (deltaCycles >= wave->timeLeftCycles) {
        // Done, remove!
        wave->enabled = false;
        ClearGPIO(wave->gpioMask);
        GP16O &= ~wave->gpio16Mask;
      } else {
        uint32_t newTimeLeftCycles = wave->timeLeftCycles - deltaCycles;
        wave->timeLeftCycles = newTimeLeftCycles;
      }
    }
  }

  if (timer1CB) {
    nextEventCycles = min_u32(nextEventCycles, timer1CB());
  }

  #if F_CPU == 160000000
  if (nextEventCycles <= 5 * MicrosecondsToCycles(1)) {
    nextEventCycles = MicrosecondsToCycles(1) / 2;
  } else {
    nextEventCycles -= 5 * MicrosecondsToCycles(1);
  }
  nextEventCycles = nextEventCycles >> 1;
  #else
  if (nextEventCycles <= 6 * MicrosecondsToCycles(1)) {
    nextEventCycles = MicrosecondsToCycles(1) / 2;
  } else {
    nextEventCycles -= 6 * MicrosecondsToCycles(1);
  }
  #endif

  ReloadTimer(nextEventCycles);
}
示例#5
0
文件: IO2.c 项目: 1ntroVert/OLINUXINO
int main(int argc, char **argv){
	
// Set I2C bus 	
	DEVICE = 2; // /dev/i2c-2 Olinuxino A20 micro, change if other board or i2c port used
	
	/* Read  program options */
	while(1){
		static struct option long_options[]=
		{
			{"verbose", no_argument,	&_DEBUG,	1},
			{"debug",	no_argument,	&_DEBUG,	1},
			
			
			{"relays?",	no_argument,0,'r'},
			{"adc",		required_argument,0,'a'},
			{"id",		no_argument,0,'i'},
			{"getport",		no_argument,0,'g'},
			{"getlat", no_argument,0,'G'},
			{"setrelays",	required_argument,0,'S'},
			{"setoutputs",	required_argument,0,'o'},
			{"settris",	required_argument,0,'t'},
			{"setpullups",	required_argument,0,'p'},
			{"switchon",	required_argument,0,'s'},
			{"switchoff",	required_argument,0,'n'},
			{"firmware",no_argument,0,'f'},
			{"help",	no_argument,0,'h'},
			{"busscan",	no_argument,0,'F'},
			{"setaddress", required_argument,0,'x'},
			{"setfactory",	no_argument,0,'X'},
			{0,		0, 			0,		0}
		};
		int option_index = 0;
		int c = getopt_long(argc, argv, "s:t:a:igGrp:o:S:n:fhx:bX?", long_options, &option_index);
		unsigned int value; 
		if (c == -1)
		{
			break;
		}
		
		switch(c)
		{
			case 'v':
				_DEBUG = 1;
				break;
			case 'h':
				Print_Help();
				break;
				
			case 'S':
				value = atoi(optarg);
				Relay(value);
				break;
			case 's':
				value = atoi(optarg);
				RelayOn(value);
				break;					
			case 'o':
				value = atoi(optarg);
				SetGPIO(value);
				break;	
			case 'n':
				value = atoi(optarg);
				RelayOff(value);
				break;				
			case 'b':
				DEVICE = atoi(optarg);
				break;					
			case 'a':
				value = atoi(optarg);
				ReadADC(value);
				break;
			case 'g':
				
				ReadGPIO();
				break;	
			case 'G':
				
				ReadLAT();
				break;	
			case 'F':
				BusScan();
				break;						
			case 'i':
				
				ReadID();
				break;	
			case 'X':
				Set_Factory();
				break;			
			case 'r':
				ReadRelays();
				break;
			case 't':
				value = atoi(optarg);
				Set_TRIS(value);
				break;
			case 'x':
				value = atoi(optarg);
				Set_Address(value);
				break;						
			case 'p':
				value = atoi(optarg);
				Set_PU(value);
				break;	
			case 'f':
			ReadSV();			
				break;
				
			default:
			
		//	Print_Help();
				break;
		}
	
	}
	
	
		
	return 0;
}