Kishore Varsha
Newbie level 4
Hey Friends.....!!!!!!!!!!!! Can anyone help me to provide CCS C code for CC3200 works along with UltraSonic Sensor HC SR04...Please reply as soon.....i worked but it goes an irrelevant output please...
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature currently requires accessing the site using the built-in Safari browser.
//*****************************************************************************
//
// Application Name - Distance Measurement using Ultrasonic Sensor
//*****************************************************************************
// Standard includes
#include <string.h>
#include <stdlib.h>
// Driverlib includes
#include "hw_types.h"
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "hw_timer.h"
#include "interrupt.h"
#include "hw_apps_rcm.h"
#include "prcm.h"
#include "rom.h"
#include "rom_map.h"
#include "prcm.h"
#include "gpio.h"
#include "utils.h"
#include "timer.h"
#include "adc.h"
// Common interface includes
#include "gpio_if.h"
#include "pinmux.h"
#include "timer_if.h"
#include "uart_if.h"
//****************************************************************************
// LOCAL DEFINES
//****************************************************************************
#define APPLICATION_VERSION "1.0.0"
#define APP_NAME "UltraSonic Sensor"
#define adc = 8
#define FOREVER 1
int millisNow, millisPrev = 0;
int microsPrev = 0;
#define true 1
#define false 0
//important functioning defines
#define INTNUM 3 //interrupt pin 1 is digital pin 3 on the duemilanove
#define PULSE 10 //microseconds
#define CYCLETIME 50 //milliseconds - this is the time to wait until the sensor is asked to find
#define DISTCHANGE 2 to 15 // the distance again. #times/second = 1000/CYCLETIME = 20 in this case
#define DISTLOW 2
#define DISTHIGH 400
//*****************************************************************************
// GLOBAL VARIABLES -- Start
//*****************************************************************************
#if defined(ccs)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif
unsigned int addr;
unsigned char pin;
unsigned int IntBase;
static volatile unsigned long g_ulBase;
char isHigh = false;
//*****************************************************************************
// GLOBAL VARIABLES -- End
//*****************************************************************************
//*****************************************************************************
// LOCAL FUNCTION PROTOTYPES
//*****************************************************************************
void LedWrite(unsigned int dtime);
void UltraSonic();
//*****************************************************************************
unsigned long micros()
{
return MAP_TimerValueGet(g_ulBase, TIMER_A);
}
/**********************************************************************************/
unsigned long millis()
{
return MAP_TimerValueGet(g_ulBase, TIMER_A) * 1000;
}
//*****************************************************************************
void LedWrite(unsigned int dtime)
{
MAP_IntDisable(IntBase); //lets not get interrupted while we are processing the first interrupt
int distance = dtime/58; //uS/58 = distance in cm => uS/148 = distance in inches
if (distance >= 2 || distance <= 400)
{
Report("Out of Range\r\n");
}
else
{
Report("Time :%d \nDistance = %d",dtime,distance);
Report(" cm\r\n");
}
MAP_UtilsDelay(8000);
}
//*****************************************************************************
void UltraSonic()
{
while(1)
{
GPIO_IF_LedOff(MCU_ALL_LED_IND);
//
// Base address for first timer
//
g_ulBase = TIMERA0_BASE;
Timer_IF_Init(PRCM_TIMERA0,g_ulBase,TIMER_CFG_PERIODIC,TIMER_A,0); // initiating timer
TimerLoadSet(g_ulBase, TIMER_A,1000);
TimerEnable(g_ulBase,TIMER_A);
/************************ MAKING ECHO PIN AS HARDWARE INTERRUPT **********************************/
GPIO_IF_GetPortNPin(7, &addr, &pin);//P62
MAP_GPIOIntTypeSet(addr,pin,GPIO_BOTH_EDGES);
if(addr==0x40004000){MAP_IntPrioritySet(INT_GPIOA0, INT_PRIORITY_LVL_1);IntBase=INT_GPIOA0;}
else if(addr==0x40005000){MAP_IntPrioritySet(INT_GPIOA1, INT_PRIORITY_LVL_1);IntBase=INT_GPIOA1;}
else if(addr==0x40006000){MAP_IntPrioritySet(INT_GPIOA2, INT_PRIORITY_LVL_1);IntBase=INT_GPIOA2;}
else if(addr==0x40007000){MAP_IntPrioritySet(INT_GPIOA3, INT_PRIORITY_LVL_1);IntBase=INT_GPIOA3;}
//Enable GPIO Interrupt
MAP_GPIOIntClear(addr,pin);
MAP_IntPendClear(IntBase);
MAP_IntEnable(IntBase);
MAP_GPIOIntEnable(addr,pin);
if(isHigh == false)
{ // pin LOW->HIGH
microsPrev = micros();
isHigh = true;
TimerDisable(g_ulBase,TIMER_A);
return;
}
else
{ //pin HIGH->lOW
LedWrite(micros());
isHigh = false;
TimerEnable(g_ulBase,TIMER_A);
MAP_IntEnable(IntBase);
microsPrev = 0;
return;
}
}
}
//****************************************************************************
//
//! Main function
//****************************************************************************
int
main()
{
//
// Configuring UART
//
InitTerm();
//
// Power on the corresponding GPIO port B for 9,10,11.
// Set up the GPIO lines to mode 0 (GPIO)
//
PinMuxConfig();
GPIO_IF_LedConfigure(LED1|LED2|LED3);
GPIO_IF_LedOff(MCU_ALL_LED_IND);
//
// Loop forever while the timers run.
//
while(FOREVER)
{
if( (millisNow = millis()) - millisPrev >= CYCLETIME)
{ //sufficient cycle time
GPIO_IF_GetPortNPin(9, &addr, &pin);//P64
GPIO_IF_Set(9, addr, pin, 1);
MAP_UtilsDelay(1000);
GPIO_IF_Set(9, addr, pin, 0);
millisPrev = millisNow; //reset clock
}
UltraSonic();
}
}