| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lpc1343 [2010/09/08 19:37] ladyada |
lpc1343 [2016/01/28 18:05] (current) |
||
|---|---|---|---|
| Line 50: | Line 50: | ||
| Don't make the same mistakes I did, always do a Clean before Build!!! | Don't make the same mistakes I did, always do a Clean before Build!!! | ||
| - | ====== Headline ====== | + | ====== 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|}} | ||