This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lpc1343 [2010/09/08 19:32] ladyada |
lpc1343 [2016/01/28 18:05] (current) |
||
---|---|---|---|
Line 46: | Line 46: | ||
</file> | </file> | ||
- | That didnt actually work. Went into **projectconfig.h** and commented out **#define CFG_PRINTF_USBCDC** **#define CFG_USBCDC** and **#define CFG_INTERFACE** did a Clean Build. File is now about 3Kb. LED blinks! | + | That didnt actually work. Went into **projectconfig.h** and commented out **#define CFG_INTERFACE** did a Clean & Build. File is now about 3Kb. LED blinks! Hooray! |
+ | Don't make the same mistakes I did, always do a Clean before Build!!! | ||
+ | |||
+ | ====== Adding USB CDC ====== | ||
+ | Now to add some basic printing capability! | ||
+ | |||
+ | <code> | ||
+ | int main (void) | ||
+ | { | ||
+ | // Configure cpu and mandatory peripherals | ||
+ | systemInit(); | ||
+ | |||
+ | while (1) | ||
+ | { | ||
+ | #ifdef CFG_INTERFACE | ||
+ | // Handle any incoming command line input | ||
+ | cmdPoll(); | ||
+ | #else | ||
+ | // Toggle LED @ 1 Hz | ||
+ | systickDelay(1000); | ||
+ | if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)) | ||
+ | gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); | ||
+ | else | ||
+ | gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); | ||
+ | |||
+ | // Say Hello to my little friend! | ||
+ | printf("hello World!\n\r"); | ||
+ | |||
+ | #endif | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | Do a build and upload the firmware. Connect using a Terminal program at 115.2kbps | ||
+ | |||
+ | {{:lpchello.gif|}} | ||
+ | |||
+ | You'll see a message every second when the LED changes state | ||
+ | |||
+ | ====== Adding analog ====== | ||
+ | |||
+ | You can read from the ADC converter (it can do up to 200ksps) quite easily! | ||
+ | |||
+ | <code> | ||
+ | #include "sysinit.h" | ||
+ | #include "core/adc/adc.h" | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | // Configure cpu and mandatory peripherals | ||
+ | systemInit(); | ||
+ | |||
+ | // initialize the internal ADC | ||
+ | adcInit(); | ||
+ | |||
+ | while (1) | ||
+ | { | ||
+ | #ifdef CFG_INTERFACE | ||
+ | // Handle any incoming command line input | ||
+ | cmdPoll(); | ||
+ | #else | ||
+ | // Toggle LED @ 1 Hz | ||
+ | systickDelay(1000); | ||
+ | if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)) | ||
+ | gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); | ||
+ | else | ||
+ | gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); | ||
+ | |||
+ | // Say Hello to my little friend! | ||
+ | printf("Analog 0: %d\n\r", adcRead(0)); | ||
+ | |||
+ | #endif | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | {{:lpcanalogtest.jpg?500|}} | ||
+ | |||
+ | {{:analog0-pot.gif|}} |