/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include "project.h"
#include <stdio.h>
// set up variables for UART and Ultra Sonic Sensor
uint8 echo_flag = 0;
uint16 echo_distance;
//char serial_output[20];
int dist =0;
//Interupt
CY_ISR( Timer_Int_Handler ) {
// read centimeters
echo_distance = Timer_Echo_ReadCapture();
dist = echo_distance;
echo_flag = 1;
Timer_Echo_ClearInterrupt ( Timer_Echo_INTR_MASK_CC_MATCH );
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
// Start up code - enable UART, PWM and Timer used for ultrasonic module
LCD_Char_Start();
LCD_Char_DisplayOn();
Timer_Echo_Start();
Timer_Echo_Start();
PWM_Trigger_Start();
PWM_Trigger_Init();
//UART_Start();
for(;;) {
// Registration of Timer ISR
Timer_Echo_Int_StartEx( Timer_Int_Handler );
CyDelay(500);
// if a distance was measured, print the distance and clear the flag
/*sprintf(serial_output, "%d cm", dist);
UART_UartPutString(serial_output);
UART_UartPutCRLF(0u);*/
//LCD Display
LCD_Char_ClearDisplay();
LCD_Char_Position(0,0);
LCD_Char_PrintString("PSoC SonicRANGER");
LCD_Char_Position(1,0);
LCD_Char_PrintString("Distance: ");
LCD_Char_Position(1,10);
LCD_Char_PrintNumber(dist);
LCD_Char_Position(1,14);
LCD_Char_PrintString("cm");
CyGlobalIntDisable; /* Disable global interrupts, so the flag gets cleared. */
echo_flag = 0;
CyGlobalIntEnable; /* Enable global interrupts after the flag is cleared. */
}
}
/* [] END OF FILE */
Comments