示例#1
0
文件: lcd.c 项目: liulvcong/EE445L
// Initialize LCD
// Inputs: none
// Outputs: none
void LCD_Init(void){ 
  SYSCTL_RCGC2_R |= 0x00000003;  // 1) activate clock for Ports A and B
  while((SYSCTL_PRGPIO_R&0x03) != 0x03){};// ready?
  GPIO_PORTB_AMSEL_R &= ~0xFF;   // 3) disable analog function on PB7-0
  GPIO_PORTA_AMSEL_R &= ~0xC0;   //    disable analog function on PA7-6              
  GPIO_PORTB_PCTL_R = 0x00000000;   // 4) configure PB7-0 as GPIO   
  GPIO_PORTA_PCTL_R &= ~0xFF000000; //    configure PA7-6 as GPIO
  GPIO_PORTB_DIR_R = 0xFF;       // 5) set direction register
  GPIO_PORTA_DIR_R |= 0xC0;
  GPIO_PORTB_AFSEL_R = 0x00;     // 6) regular port function
  GPIO_PORTA_AFSEL_R &= ~0xC0;
  GPIO_PORTB_DEN_R = 0xFF;       // 7) enable digital port
  GPIO_PORTA_DEN_R |= 0xC0;
  GPIO_PORTB_DR8R_R = 0xFF;      // enable 8 mA drive
  GPIO_PORTA_DR8R_R |= 0xC0;
  SysTick_Init();       // Volume 1 Program 4.7, Volume 2 Program 2.10
  LCDCMD = 0;           // E=0, R/W=0, RS=0
  SysTick_Wait(T15ms);  // Wait >15 ms after power is applied
  OutCmd(0x30);         // command 0x30 = Wake up
  SysTick_Wait(T5ms);   // must wait 5ms, busy flag not available
  OutCmd(0x30);         // command 0x30 = Wake up #2
  SysTick_Wait(T160us); // must wait 160us, busy flag not available
  OutCmd(0x30);         // command 0x30 = Wake up #3
  SysTick_Wait(T160us); // must wait 160us, busy flag not available
  OutCmd(0x38);         // Function set: 8-bit/2-line
  OutCmd(0x10);         // Set cursor
  OutCmd(0x0C);         // Display ON; Cursor ON
  OutCmd(0x06);         // Entry mode set
}
示例#2
0
/**
 * @brief Switches the Reset pin PC3 for the OLED display.
 * @retval None
 */
void OLED_Reset(void) {
  GPIOC->ODR &= ~(1<<3);
  //TODO: insert timer wait 200ms
  SysTick_Wait(20);
  GPIOC->ODR |= (1<<3);
  SysTick_Wait(20);
}
示例#3
0
//------------Switch_Debounce------------
// wait for the switch to be touched 
// Input: none
// Output: none
// debounces switch
void Switch_WaitForTouch(void){
// wait for release
  while(Switch_Input()){};
  SysTick_Wait(DELAY10MS); // 10ms
// wait for touch
  while(Switch_Input()==0){};
  SysTick_Wait(800000); // 10ms
}
示例#4
0
文件: lcd.c 项目: liulvcong/EE445L
// Output a character to the LCD
// Inputs: letter is ASCII character, 0 to 0x7F
// Outputs: none
void LCD_OutChar(char letter){
  LCDDATA = letter;
  LCDCMD = RS;          // E=0, R/W=0, RS=1
  SysTick_Wait(T6us);   // wait 6us
  LCDCMD = E+RS;        // E=1, R/W=0, RS=1
  SysTick_Wait(T6us);   // wait 6us
  LCDCMD = RS;          // E=0, R/W=0, RS=1
  SysTick_Wait(T40us);  // wait 40us
}
示例#5
0
文件: lcd.c 项目: liulvcong/EE445L
void static OutCmd(unsigned char command){
  LCDDATA = command;
  LCDCMD = 0;           // E=0, R/W=0, RS=0
  SysTick_Wait(T6us);   // wait 6us
  LCDCMD = E;           // E=1, R/W=0, RS=0
  SysTick_Wait(T6us);   // wait 6us
  LCDCMD = 0;           // E=0, R/W=0, RS=0
  SysTick_Wait(T40us);  // wait 40us
}
示例#6
0
/**
 * @brief Prints out the configuration options of the XBee.
 * @retval XBEE_OK if successfull, XBEE_INIT_FAIL on failure.
 */
XBEE_STATUS Blox_XBee_Print(void) {
  uint8_t garbage;
  
  Blox_VUSART_TryReceive(XBEE_VUSART_ID, &garbage);   //clear VUSART buffer before send/receive
  Blox_VUSART_Send(XBEE_VUSART_ID, 'X');           // Junk character to before init
  SysTick_Wait(1100);
  Blox_VUSART_SendData(XBEE_VUSART_ID, "+++", 3) ; //Enter Command Mode
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(1100);
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATMY\r", 5) ; //Read source address
  Blox_DebugStr("ATMY:");
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c\r\n", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage); //\r
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATDL\r", 5) ; //Read source address
  Blox_DebugStr("ATDL:");
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c\r\n", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage); //\r
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATDH\r", 5) ; //Read source address
  Blox_DebugStr("ATDH:");
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c\r\n", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage); //\r
 
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATAP\r", 5) ; //Read source address
  Blox_DebugStr("ATAP:");
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage);
  Blox_DebugPat("%c\r\n", garbage);
  Blox_VUSART_Receive(XBEE_VUSART_ID, &garbage); //\r
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATCN\r", 5) ; //Exit command mode
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  return XBEE_OK;
}
// Time delay using busy wait.
// This assumes 50 MHz system clock.
void SysTick_10ms_wait(unsigned long delay){
  unsigned long i;
	SysTick_Init(500000);
  for(i=0; i<delay; i++){
    SysTick_Wait(500000);  // wait 10ms (assumes 50 MHz clock)
  }
}
示例#8
0
//Blinks the south LED
void role_2(void) {
  Blox_LED_Init();
  SysTick_Init(); 
  while(1) {
    Blox_LED_Toggle(LED2);
    SysTick_Wait(1000);
  }
}
示例#9
0
//Blinks the east LED
void role_1(void) {
  Blox_LED_Init();
  SysTick_Init();			     
  while(1) {
    SysTick_Wait(500);
    Blox_LED_Toggle(LED1);
  }
}
void SysTick_Wait_10ms(unsigned long delay) {
	
	unsigned long i;
	for(i = 0; i < delay; i++) {
		
		SysTick_Wait(800000);
		
	}
	
}
示例#11
0
/**
 * @brief Initializes the OLED display.
 * @retval None
 */
void Blox_OLED_Init(void) {
  uint8_t garbage;
  OLED_RCC_Configuration();
  OLED_GPIO_Configuration();
  SysTick_Init();
  Blox_VUSART_Init(OLED_USART_ID);

  OLED_Reset();
  SysTick_Wait(2000);
  Blox_VUSART_TryReceive(2, &garbage);  //receive any garbage data
  Blox_OLED_Send(OLED_AUTOBAUD); 
  Blox_OLED_Receive();
}
示例#12
0
/**
 * @brief Initializes the XBees sleep and reset pins, and then resets the XBee.
 * @retval None
 */
XBEE_STATUS Blox_XBee_Init(void) {
  uint8_t garbage;
  XBee_RCC_Configuration();
  XBee_GPIO_Configuration();

  Blox_System_Init();
  SysTick_Init();

  XBEE_SLEEP_GPIO->ODR &= ~(XBEE_SLEEP_PIN);
  XBEE_RESET_GPIO->ODR |= XBEE_RESET_PIN;
  SysTick_Wait(1);
  XBEE_RESET_GPIO->ODR &= ~(XBEE_RESET_PIN);
  SysTick_Wait(1);
  XBEE_RESET_GPIO->ODR |= XBEE_RESET_PIN;
  SysTick_Wait(300);

  Blox_VUSART_Init(XBEE_VUSART_ID);
  Blox_VUSART_TryReceive(XBEE_VUSART_ID, &garbage);   //clear VUSART buffer before send/receive
  Blox_VUSART_Disable_RXNE_IRQ(XBEE_VUSART_ID);
  Blox_VUSART_Register_RXNE_IRQ(XBEE_VUSART_ID, &Blox_XBee_VUSART_RXNE_IRQ);
  Blox_VUSART_Enable_RXNE_IRQ(XBEE_VUSART_ID);

  return XBEE_OK;
}
示例#13
0
//------------Switch_Debounce------------
// Read and return the status of the switch 
// Input: none
// Output: 0x02 if PB1 is high
//         0x00 if PB1 is low
// debounces switch
uint32_t Switch_Debounce(void){
uint32_t in,old,time; 
  time = 1000; // 10 ms
  old = Switch_Input();
  while(time){
    SysTick_Wait(DELAY10US); // 10us
    in = Switch_Input();
    if(in == old){
      time--; // same value 
    }else{
      time = 1000;  // different
      old = in;
    }
  }
  return old;
}
示例#14
0
/**
 * @brief Sends a XBeeTxFrame.
 * @param frame: the frame to be sent.
 * @retval XBEE_OK if successful, XBEE_INIT_FAIL on failure.
 */
XBEE_STATUS XBee_SendTxFrame (XBeeTxFrame *frame) {
  uint8_t i;
  uint8_t len = frame->length-5;
  
  XBee_TxStatus_Flag = XBEE_TXSTATUS_NORMAL;

  Blox_VUSART_Send(XBEE_VUSART_ID, frame->start);
	Blox_VUSART_Send(XBEE_VUSART_ID, (uint8_t)(frame->length >> 8));
	Blox_VUSART_Send(XBEE_VUSART_ID, (uint8_t)frame->length);
	Blox_VUSART_Send(XBEE_VUSART_ID, frame->api);
	Blox_VUSART_Send(XBEE_VUSART_ID, frame->id);
	Blox_VUSART_Send(XBEE_VUSART_ID, (uint8_t)(frame->dest_addr >> 8));
	Blox_VUSART_Send(XBEE_VUSART_ID, (uint8_t)frame->dest_addr);
	Blox_VUSART_Send(XBEE_VUSART_ID, frame->options);
	for (i = 0; i < len; i++)
	  Blox_VUSART_Send(XBEE_VUSART_ID, ((uint8_t *)&(frame->blox_frame))[i]);
	Blox_VUSART_Send(XBEE_VUSART_ID, frame->checksum);
  
  SysTick_Wait(1); //Give it a chance to send.
  if(XBee_TxStatus_Flag == XBEE_TXSTATUS_SUCCESS)
    return XBEE_OK;

  return XBEE_TX_FAIL;
}
示例#15
0
// Time delay using busy wait.
// 10000us equals 10ms
void SysTick_Wait10ms(unsigned long delay){
  unsigned long i;
  for(i=0; i<delay; i++){
    SysTick_Wait(60000);  // wait 10ms (assumes 6 MHz clock)
  }
}
示例#16
0
/**
 * @brief Configures the XBee and writes the configuration to non-volatile mem.
 * @retval XBEE_OK if successfull, XBEE_INIT_FAIL on failure.
 */
XBEE_STATUS Blox_XBee_Config(void) {
  char buffer[10];
  uint8_t garbage;
  SysVar sys;
  XBee_RCC_Configuration();
  XBee_GPIO_Configuration();
  
  Blox_VUSART_Init(XBEE_VUSART_ID);
  SysTick_Init();
  Blox_System_Init();
  Blox_System_GetVars(&sys);
  
  XBEE_SLEEP_GPIO->ODR &= ~(XBEE_SLEEP_PIN);
  XBEE_RESET_GPIO->ODR |= XBEE_RESET_PIN;
  SysTick_Wait(1);
  XBEE_RESET_GPIO->ODR &= ~(XBEE_RESET_PIN);
  SysTick_Wait(1);
  XBEE_RESET_GPIO->ODR |= XBEE_RESET_PIN;
  SysTick_Wait(1100);

  Blox_VUSART_TryReceive(XBEE_VUSART_ID, &garbage);   //clear VUSART buffer before send/receive
  Blox_VUSART_Send(XBEE_VUSART_ID, 'X');           // Junk character to before init
  SysTick_Wait(1100);
  Blox_VUSART_SendData(XBEE_VUSART_ID, "+++", 3) ; //Enter Command Mode
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(1100);
  
  sprintf(buffer, "ATMY%d\r", sys.id);
  Blox_VUSART_SendData(XBEE_VUSART_ID, (uint8_t *)buffer, strlen(buffer)) ; //Enter Command Mode
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);  
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATDLFFFF\r", 9) ; //Set broadcast dest ID
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);    
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATDH0\r", 6) ; //Set high of dest ID
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATAP1\r", 6) ; //API Mode 1 (no escapes)
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATRN1\r", 6) ; //API Mode 1 (no escapes)
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATWR\r", 9) ; //Write to non-volatile memory
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  Blox_VUSART_SendData(XBEE_VUSART_ID, "ATCN\r", 5) ; //Exit command mode
  if (XBee_CheckOkResponse() == FALSE)
    return XBEE_INIT_FAIL;
  SysTick_Wait(20);
  
  return XBEE_OK;
}
示例#17
0
// Time in ms
void ghettoDelay(int time)
{
	SysTick_Wait(time*250000);
}
示例#18
0
文件: lcd.c 项目: liulvcong/EE445L
// Clear the LCD
// Inputs: none
// Outputs: none
void LCD_Clear(void){
  OutCmd(0x01);          // Clear Display
  SysTick_Wait(T1600us); // wait 1.6ms
  OutCmd(0x02);          // Cursor to home
  SysTick_Wait(T1600us); // wait 1.6ms
}
示例#19
0
// Time delay using busy wait.
// This assumes 50 MHz system clock.
void SysTick_Wait10ms(uint32_t delay){
  uint32_t i;
  for(i=0; i<delay; i++){
    SysTick_Wait(500000);  // wait 10ms (assumes 50 MHz clock)
  }
}
示例#20
0
void SysTick_Wait10ms(uint32_t delay) {
  for (uint32_t i = 0; i < delay; ++i) {
    SysTick_Wait(800000); // 800000 * 12.5 ns = 10 ms
  }
}