PowerX 2 Posted August 30, 2012 Share Posted August 30, 2012 Hello, This is my first very simple test with the c2k launchpad, it simply lights up a led (gpio0) a turns it off when the button (gpio12) is pressed. Below is my code for it. Hope you like it. // // c2k launchpad led Hello world 1.0 + button // //includes #include "DSP28x_Project.h" #include "f2802x_common/include/clk.h" #include "f2802x_common/include/gpio.h" #include "f2802x_common/include/pll.h" #include "f2802x_common/include/wdog.h" #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif //main void main() { //wdog WDOG_Handle myWDog; myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); WDOG_disable(myWDog); //clk&pll CLK_Handle myClk; PLL_Handle myPll; myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); CLK_setOscSrc(myClk, CLK_OscSrc_Internal); PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2); //set gpio GPIO_Handle myGpio; myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); //set led gpio0 GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output); GPIO_setHigh(myGpio, GPIO_Number_0); //set button gpio12 GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose); GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Input); GPIO_setPullUp(myGpio, GPIO_Number_12, GPIO_PullUp_Disable); //loop for(; { // if gpio12 button is pressed led on-off once if(GPIO_getData(myGpio, GPIO_Number_12) == 1) { GPIO_setLow(myGpio, GPIO_Number_0); DELAY_US(1000000); GPIO_setHigh(myGpio, GPIO_Number_0); } } } Oppa, CorB and msptest6 3 Quote Link to post Share on other sites
TI_Trey 38 Posted August 30, 2012 Share Posted August 30, 2012 Looks good Mihai. What did you think of the drivers? They are pretty new so I'm trying to get some feedback. Were they helpful? Quote Link to post Share on other sites
PowerX 2 Posted August 30, 2012 Author Share Posted August 30, 2012 Looks good Mihai. What did you think of the drivers? They are pretty new so I'm trying to get some feedback. Were they helpful? They are very helpful, coding is much more easier. I had to search a little before i got my first program to work i didn`t know how to include them in the project. Anyway making them was a good ideea. Looking forward to learning more. Quote Link to post Share on other sites
CorB 64 Posted August 30, 2012 Share Posted August 30, 2012 Hi, Thanks for sharing this ! This part of the code: // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif should not be place before void main(), when I then compile the code for FLASH based operation it raises compiler-errors. Ive placed it inside the code after the line: PLL_setup(myPll .... ) Would be nice to set the code also up for an interrupt based action instead of a polling loop. Ive tried to use the external_interrupt code to build something like that but thusfar without a blinking led. cheers CorB Oppa 1 Quote Link to post Share on other sites
PowerX 2 Posted August 31, 2012 Author Share Posted August 31, 2012 Thank you for the info. Great job btw on your code with the interrupt sorry for the delay i had to work. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.