示例#1
0
void display_595() {
// toggle the parallel load bit of the output to display the byte(s) that have been sent.
	_delay(2);
	GPIO = GPIO | 1;
	_delay(2);
	GPIO = GPIO & 0b11111110;
}
int rotate(int CurrentStatus,int Step_)	//正轉,反轉皆可
{
	int k,Step;
	
	if (Step_>=0)
	{
		Step=Step_;
		for	(k=1;k<=Step;k++)
		{
			CurrentStatus=(CurrentStatus+k)%4;
			setMotorPin(CurrentStatus);
			_delay(delay_para*1000);
		}	
	}else
	{
		Step=-Step_;
		for	(k=1;k<=Step;k++)
		{
			CurrentStatus=(CurrentStatus-k)%4;
			setMotorPin(CurrentStatus);
			_delay(delay_para*1000);
		}	
	}
	
	return CurrentStatus; //回傳目前狀態
}
示例#3
0
文件: cpu.c 项目: glguida/mh
void cpu_wakeup_aps(void)
{
	int i;
	struct cpu_info *cpu;
	unsigned cpuid = cpu_number_from_lapic();

	cmos_write(0xf, 0xa);	// Shutdown causes warm reset.

	for (i = 0; i < number_cpus; i++) {
		if (i == cpuid)
			continue;
		cpu = cpuinfo_get(i);

		printf("Waking up CPU %02d...", i);

		/* Setup AP bootstrap page */
		memcpy((void *) (UKERNBASE + UKERN_APBOOT(i)), &_ap_start,
		       (size_t) & _ap_end - (size_t) & _ap_start);

		/* Setup Warm Reset Vector */
		*(volatile uint16_t *) (UKERNBASE + 0x467) = UKERN_APBOOT(i) & 0xf;
		*(volatile uint16_t *) (UKERNBASE + 0x469) = UKERN_APBOOT(i) >> 4;

		/* INIT-SIPI-SIPI sequence. */
		lapic_ipi(cpu->phys_id, APIC_DLVR_INIT, 0);
		_delay();
		lapic_ipi(cpu->phys_id, APIC_DLVR_START,
			  UKERN_APBOOT(i) >> 12);
		_delay();
		lapic_ipi(cpu->phys_id, APIC_DLVR_START,
			  UKERN_APBOOT(i) >> 12);
		_delay();
		printf(" done\n");
	}
}
void Init1638(void) {
    STB = 1;
    CLK = 1;
    _delay(4000);
	WriteCmd( 0x40 );
    WriteDisplayBuffer();
    _delay(400);       
}
示例#5
0
void buzz(int cycles){
	int i;

	for (i=0; i < cycles; i++){
                _delay(BUZZ_DELAY);
                SET_BUZZ();
		_delay(BUZZ_DELAY);
		CLEAR_BUZZ();
	}
}
void Write1638( unsigned char Data )	
{
	unsigned char i;
	for( i=0 ; i<8 ; i++ )	{
        DO = (Data & 0X01);
		CLK = 0;
		Data >>= 1;
        _delay(2);
		CLK = 1;
	}
    _delay(20);
}
示例#7
0
void test_payload()
{
	PCA9548A_Init(PCA9548A_ADDR);
    PCA9548A_SetChannel(2);

    Payload_Init();
    while(1) {
		Payload_Light_Off();
		_delay();
		Payload_Light_On();
		_delay();
    }
}
示例#8
0
unsigned char read_keypad(void){

        //Reset all keypad port to inputs
        TRIS_KEYPAD = 0xFF;
    
	//Set the current vertical pin as output
	TRIS_KEYPAD = ~Vert_0;
	//Pull it to ground
	PORT_KEYPAD = ~Vert_0;
	_delay(10);
	//Input pins have pull up, so high is no-press, low is pressed
	if ( ~PORT_KEYPAD & Horiz_0)
		return 0x01;
	if ( ~PORT_KEYPAD & Horiz_1)
		return 0x02;
	if ( ~PORT_KEYPAD & Horiz_2)
		return 0x03;

	TRIS_KEYPAD = ~Vert_1;
	PORT_KEYPAD = ~Vert_1;
	_delay(10);
	if ( ~PORT_KEYPAD & Horiz_0)
		return 0x04;
	if ( ~PORT_KEYPAD & Horiz_1)
		return 0x05;
	if ( ~PORT_KEYPAD & Horiz_2)
		return 0x06;

	TRIS_KEYPAD = ~Vert_2;
	PORT_KEYPAD = ~Vert_2;
	_delay(10);
	if ( ~PORT_KEYPAD & Horiz_0)
		return 0x07;
	if ( ~PORT_KEYPAD & Horiz_1)
		return 0x08;
	if ( ~PORT_KEYPAD & Horiz_2)
		return 0x09;

	TRIS_KEYPAD = ~Vert_3;
	PORT_KEYPAD = ~Vert_3;
	_delay(10);
	if ( ~PORT_KEYPAD & Horiz_0)
		return 0xA0;
	if ( ~PORT_KEYPAD & Horiz_1)
		return 0x00;
	if ( ~PORT_KEYPAD & Horiz_2)
		return 0xA1;

	return 0xFF;
}
示例#9
0
int
delay_output(int ms)
{
	extern	int	_outchar(char);

	return (_delay(ms * 10, _outchar));
}
示例#10
0
文件: lcd.c 项目: wheelerz/ento
unsigned char 
lcd_read_cmd_nowait(void)
{
	unsigned char c, readc;

	LCD_DATA_TRIS	 |=  ~OUTPUT_DATA;	// Set data lines to input

	LCD_RW = 1; // Read LCD
	_delay(2); // short propagation delay

	if (fourbit) {
		LCD_STROBE_READ(readc); // Read high nibble
		// Move 4 bits to high nibble while zeroing low nibble
		c = ( ( readc << 4 ) & 0xF0 ); 
		LCD_STROBE_READ(readc); // Read low nibble
    		c |= ( readc & 0x0F ); // Or in 4 more bits to low nibble
	} else {
		LCD_STROBE_READ(readc); 
		c = readc;
	}
	LCD_RW = 0; // Return to default mode of writing LCD
	LCD_DATA_TRIS &= OUTPUT_DATA; // Return to default mode of writing LCD

	return(c);
}
示例#11
0
main()
{
   int i,j,k ;
   for (i=0; i < 2; i++) {
      for (j=0; j <2; j++)
         for (k=0; k < 6; k++) {
            _sound(597) ;
            _delay(55) ;
            _sound(745) ;
            _delay(55) ;
         }
      _nosound() ;
      _delay(1800) ;
   }
            
}
示例#12
0
void delay_us(volatile unsigned long us)
{
    while (us-- > 0)
    {
        _delay(5);
    }
}
示例#13
0
void main()
{

TRISB = 0b00000011;
TRISA = 0b00101111;
TRISC = 0b00000000;
TRISD = 0b00000010;
TRISE = 0b00000111;

while (1){
	RC2 = 1;
	_delay(100000);
	RC2 = 0;
	_delay(100000);
}

}
/*!
* This method reads and empties the input buffer of `_dataStream`.
* It continues until it finds the specified prompt or until
* the specified amount of time has elapsed.
* The source data is converted from HEX and copied to the
* buffer supplied.
* The first letter of the prompt cannot be a valid Hex char.
* It attempts to output the data it reads to `_diagStream`.
* @param buffer The buffer to copy the data into.
* @param size The size of `buffer`.
* @param bytesStored The number of bytes copied is written to this parameter.
* @param prompt The prompt to read until.
* @param timeMS The time limit in milliseconds.
* @return `true` if it found the specified prompt within the time
* limit, otherwise `false`.
*/
bool Sodaq_WifiBee::readHexTillPrompt(uint8_t* buffer, const size_t size,
  size_t& bytesStored, const char* prompt, const uint32_t timeMS)
{
  if (!_dataStream) {
    return false;
  }

  bool result = false;

  uint32_t startTS = millis();
  size_t promptIndex = 0;
  size_t promptLen = strlen(prompt);

  size_t bufferIndex = 0;
  size_t streamCount = 0;
  bool even = false;

  while (!timedOut32(startTS, timeMS)) {
    if (available()) {
      startTS = millis();
      char c = read();
      diagPrint(c);

      streamCount++;

      if (bufferIndex < size) {
        buffer[bufferIndex] = c;
        bufferIndex++;
      }

      if (c == prompt[promptIndex]) {
        promptIndex++;

        if (promptIndex == promptLen) {
          result = true;
          bufferIndex = ((size - 1) < ((streamCount - promptLen) / 2)) ? (size - 1) : (streamCount - promptLen) / 2;
          break;
        }
      }
      else {
        promptIndex = 0;

        if (even) {
          _buffer[bufferIndex - 2] = HEX2BYTE(_buffer[bufferIndex - 2], _buffer[bufferIndex - 1]);
          bufferIndex--;
        }
      }
      even = !even;
    }
    else {
      _delay(10);
    }
  }

  bytesStored = bufferIndex;

  return result;
}
示例#15
0
void delays(int n) {
    int i = 10 * n; // (n* CYC_FREQ) /CYC_DELAY;
    //int k= (CYC_DELAY * 1000) / CYC_FREQ;

    int j;
    for (j = 0; j < i; j++) {
        _delay(CYC_DELAY);
    }
}
示例#16
0
文件: serdos.c 项目: haision/GitHub_C
static void flush_send_buffer(struct port *p)
{
    while (!queue_empty(p->send)) {
	enable_thre_int(p->baseaddr);
	_delay();
    }

    disable_thre_int(p->baseaddr);
}
示例#17
0
文件: gamecube.c 项目: zzattack/munia
void ngc_tasks() {
    if (pollNeeded && (in_menu || (config.input_ngc && config.output_mode != output_ngc))) {
        USBDeviceTasks();
        di();
        ngc_poll();
        // waste some more instructions before sampling
        _delay(40);
        asm("lfsr 0, _sample_buff+25"); // setup FSR0
        ngc_sample();
        asm("movff FSR0L, _sample_w+0"); // update sample_w
    }
    
    if (packets.ngc_test) {
        if (!in_menu && config.output_mode == output_ngc && !config.input_ngc) {
            ngc_fakeout_test();
            WRITETIMER3(65000); // schedule next fake poll soon
        }
        else ngc_handle_packet();
        packets.ngc_test = false;
    }
    
    INTCONbits.IOCIF = 0; // don't bother with stuff that happened in the meantime
    ei();

    if (packets.ngc_avail) {
        // see if this packet is equal to the last transmitted one, and if so, discard it
        // also when in menu, menu_tasks will clear bit
        if (in_menu) return;
        else if (memcmp(&joydata_ngc_raw, &joydata_ngc_last_raw, sizeof(ngc_packet_t))) {
            // dbgs("new packets.ngc_avail\n");
            // new, changed packet available; unpack if faking and send over usb
            
            if (config.input_sources & input_ngc && config.output_mode == output_n64) {
                // dbgs("ngc_create_n64_fake()\n");
                ngc_to_n64();
                fake_unpack((uint8_t*)&joydata_n64_raw, sizeof(n64_packet_t));
            }
        
            else if (config.input_sources & input_ngc && config.output_mode == output_snes) {
                // dbgs("ngc_create_snes_fake()\n");
                ngc_to_snes();
                fake_unpack((uint8_t*)&joydata_snes_raw, sizeof(snes_packet_t));
            }
            
            if (USB_READY && !HIDTxHandleBusy(USBInHandleNGC)) {
                // dbgs("ngc_joydata_createhid()\n");
                ngc_joydata_createhid();
                USBInHandleNGC = HIDTxPacket(HID_EP_NGC, (uint8_t*)&joydata_ngc_usb, sizeof(ngc_packet_t));
            }
            
            // save last packet
            memcpy(&joydata_ngc_last_raw, &joydata_ngc_raw, sizeof(ngc_packet_t));
        }
        packets.ngc_avail = false; // now consumed
    }    
}
void loop()
	{
	float result;
	int key=resist();
	if(key==15)
		{
		//LCM CLEAR
		wlcmd_4('c',0x01);
		_delay(1600);
		//student num
		student_num();
		//parameter reset
		aa=0;bb=0;_status0=0;
		lcm_num[0]=0;
		lcm_num[1]=0;
		lcm_num[2]=0;
		lcm_num[3]=0;
		lcm_num[4]=0;
		lcm_num[5]=0;
		lcm_num[6]=0;
		return;
		}
	if((key>=0)&&(key<=9)&&(_status0!=4))
		{
			wlcmd_4('d',key);
			if(_status0==0)
			{
				aa=aa*10+key;
			}
			if(_status0==2)
			{
				bb=bb*10+key;
			}
		return;	
		}
	if((key>=10)&&(key<=13)&&(_status0!=4))
		{
			if(_status0==0)
			{
				wlcmd_4('d',key);
				operand=key;
				_status0=2;
				return;
			}
		}
	if((key==14)&&(_status0!=4))	
		{
			wlcmd_4('d',key);
			result=com(aa,bb,operand);
			divide(result);
			_status0=4;
			return;	
		}
	return;
	}
示例#19
0
文件: serdos.c 项目: haision/GitHub_C
static int detect_uart(unsigned int baseaddr)
{
    int x, olddata, temp;

    /* check if a UART is present */
    olddata = inportb(baseaddr + MCR);

    /* enable loopback mode, set RTS & DTR to 1 */
    outportb(baseaddr + MCR, 0x1f);
    _delay();

    /* Read the state of RTS and DTR. 
     * Do this twice, so that lower 4 bits are clear. 
     * OS/2 returns 0xB0 after this, instead of 0xff if no port is there.
     */
    disable();
    temp = inportb(baseaddr + MSR);
    temp = inportb(baseaddr + MSR);
    enable();

    if ((temp & 0x3f) != 0x30)
	return 0;

    /* restore RTS & DTR */
    outportb(baseaddr + MCR, olddata);
    _delay();

    /* next thing to do is look for the scratch register */
    olddata = inportb(baseaddr + SCR);

    outportb(baseaddr + SCR, 0x55);
    _delay();
    if (inportb(baseaddr + SCR) != 0x55)
	return UART_8250;

    outportb(baseaddr + SCR, 0xAA);
    _delay();
    if (inportb(baseaddr + SCR) != 0xAA)
	return UART_8250;

    /* restore it if it's there */
    outportb(baseaddr + SCR, olddata);
    _delay();

    /* check if there's a FIFO */
    outportb(baseaddr + IIR, 1);
    _delay();
    x = inportb(baseaddr + IIR);

    /* some old-fashioned software relies on this! */
    outportb(baseaddr + IIR, 0x0);
    _delay();

    if ((x & 0x80) == 0) return UART_16450;
    if ((x & 0x40) == 0) return UART_16550;
    return UART_16550A;
}
示例#20
0
void send_byte_to_595(char a) {
// Sends the byte a, LSB first, to the 74'595 shift register
	int i;	
	char b;

	b = a;
	for (i=0; i<8; i++) {
		if ((b & 0x01) == 0x01) {
			GPIO = GPIO | 0b00000010; // data is high...
			_delay(2);
		} else {
			GPIO = GPIO & 0b11111000; // data is low
			_delay(2);
		}
		GPIO = GPIO | 0b00000100; // clock  high
		_delay(2);
		GPIO = GPIO & 0b11111000;  // clear the bits
		b = b >>  1; // shift it right
	}
}
void main()
{
	//初始化
    int CurrentStatus,k;
    CurrentStatus=0;
	initializer();

	loop:
	
	CurrentStatus=rotate(CurrentStatus,100); //正轉100Steps
	for (k=0;k<1000;k++) //延遲一秒
	{_delay(1000);}
	
	CurrentStatus=rotate(CurrentStatus,-100); //反轉100Steps
	for (k=0;k<1000;k++) //延遲一秒
	{_delay(1000);}
	
	goto loop;
    return;
}
int	resist()
{
	unsigned short key;
	do //¨¾¼u¸õ¶}©l
	{
		key=ScanKey();
		_delay(3000);
	}while(key==16);
	while(ScanKey()!=16); //¨¾¼u¸õµ²§ô	
	return key;
}
示例#23
0
void LCDinit(void)
{
   PORTA = 00;         // Clear Control port
   LATA = 00;         // and its corresponding Latch
   TRISA = 0x01;         // Make PORTA as output port
   ADCON1 = 0x0E;     // Make PORTA as digitital I/O
   // This is done here assuming application code may be using PORTA of Analog application.

   _delay(4);         //
   _delay(4);          //
   _delay(4);         //~15 ms delay


   WriteNibble(0x30);  // #1 control byte
   _delay(4);

   WriteNibble(0x30);  // #2 control byte

   _delay_100us();


   WriteNibble(0x30);  // #3 control byte
   _delay_100us();

   WriteNibble(0x20);  // #4 control sets 4 bit mode
   _delay_100us();

   Check_LCDBusy();    // Check whther LCD is free to continue operation

   FunctionSet(0x28);   // #5 control byte Function set

   DisplayON (0x0D);    // Turn on Display

   DisplayClr (0x01);    // Clear Display (clears junk if any)

   EntryMode(0x06);   // Entry mode selection

   DDRAMadrs(0x80);   // Initialise DDRAM address to 80h.

}                  // LCD Init ends
int main()
{
    TRISA = 0x0; //these are likely RISC/MIPS instructions (35 of them in total)
    
    while (1)
    {
        _delay(25000);
        LATA = 0x6F; //Latch A --corresponds to a set of pins
        _delay(25000);
        LATA = 0x0C; //we set the hex value in binary and such
        _delay(25000);
        LATA = 0x5B;
        _delay(25000);
        LATA = 0x5D;
        _delay(25000);
        LATA = 0x3C;
        _delay(25000);
        LATA = 0x75;
        _delay(25000);
        LATA = 0x77;
        _delay(25000);
        LATA = 0x4C;
        _delay(25000);
        LATA = 0x7F;
        _delay(25000);
        LATA = 0x7D;
    }
    
    //Code for servo motor control
    //Principles are to use the delay to selectively give voltage to the motor, thus simulating a PWM (pulse width modulation)
    
    while (1)
    {
        //_delay for a while with the voltage on -- this will cause the servo motor to change angular position 
        
        
    }
    
    return 0;
}
示例#25
0
void Blinky(void)
{
    unsigned long TimeTick = 0xFFFFF;

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    while (1)
    {
        //
        // Turn On Led
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 1<<3);
        _delay(TimeTick);

        //
        // Turn Off Led
        //
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0<<3);
        _delay(TimeTick);
    }
}
void student_num() //Åã¥Ü¾Ç¸¹+´«¦æ(0C0H)
{
wlcmd_4('c',0x1);
_delay(1600); 
wlcmd_4('d','S');
wlcmd_4('d',0x00);
wlcmd_4('d',0x01);
wlcmd_4('d',0x05);	
wlcmd_4('d',0x02);
wlcmd_4('d',0x00);
wlcmd_4('d',0x00);
wlcmd_4('d',0x06);
wlcmd_4('c',0x0c0);
return;
}
void init_lcm() //lcmªì©l¤Æ
{
lcm_en=0;
lcm_rw=0;
lcm_rs=0;
lcm_enc=0;
lcm_rwc=0;
lcm_rsc=0;
wlcmd_4('c',0x28);
wlcmd_4('c',0x0c);
wlcmd_4('c',0x06);
wlcmd_4('c',0x01);
_delay(2000); //Clear Display»Ý­n1.53ms½w½Ä
return;
}
示例#28
0
/*** Blink LED ***/
void RGB::blink(int numberOfTimes, int Delay_OnTime, int Delay_OffTime)
{
	int i = 0;
	int rgb[] = {red, green, blue};
	//for loop for blinking
	for(i=0; i<numberOfTimes; i++)
	{
		setRGB(0,0,0);
		_delay(Delay_OnTime);
		setRGB(rgb[0],rgb[1],rgb[2]);
		_delay(int Delay_OffTime);
	}
	
	// bring back to previous state
	setRGB(rgb[0],rgb[1],rgb[2]);
}
示例#29
0
static void waitNotBusy(void) {
    TRISD=0xFF;
    uint8_t res=0;
    RS=0;
    RW=1;
    do {
        E=1;
        _delay(2);
        if (PORTDbits.RD7 == 0) {
            res=1;
        }
        E=0;
    } while (res == 0);
    TRISD=0;
    return;
}
示例#30
0
文件: gamecube.c 项目: zzattack/munia
void ngc_poll() {
    portc_mask = 0b00000001;
    LATC &= ~portc_mask; // pull down - always call this before CLR() calls
    CLR(); // set data pin to output, making the pin low
    // send 01000000
    //      00000011    
    //      00000010
    LOW(); HIGH(); LOW(); LOW(); LOW(); LOW(); LOW(); LOW(); 
    LOW(); LOW(); LOW(); LOW(); LOW(); LOW(); HIGH(); HIGH(); 
    LOW(); LOW(); LOW(); LOW(); LOW(); LOW(); LOW(); LOW(); 
    
    // stop bit, 2 us
    CLR(); 
    _delay(22);
    SET();// back set to open collector input with pull up
    LATC |= portc_mask; // reset pull up
}