When a console program needs to obtain information from the user, such as the user's name, it uses gets or perhaps scanf to obtain the desired input. The debug routines included in the PIC32 Starter Kit provide this capability. When the PIC32 board requests input, through the JTAG/USB interface, the host computer brings up a dialog window where the user can enter the requested information. |
The mechanics of using the MPLAB IDE are described in a separate tutorial. This document is devoted to the code itself. The necessary code files and MPLAB project and workspace files are packaged in hello2.zip.
hello2.c
01: /* hello2.c 02: * 03: * Try db_gets 04: */ 05: 06: #include <p32xxxx.h> 07: #include "db_utils.h" 08: 09: int main() 10: { 11: char name[25]; 12: DBPRINTF("Basic Starter Kit Lab (" __DATE__ ", " __TIME__ ")\n"); 13: DBPRINTF("What is your name?\n"); 14: DBGETS(name,24); 15: DBPRINTF("Hello, %s!\n",name); 16: DBPUTS("Program terminated. Click HALT and then RESET to stop the microcontroller. \n"); 17: return 0; 18: }
Select View > Memory Usage Gauge from the top menu of the MPLAB IDE to display the following diagram:
For the PIC32 processor, the program memory is given in 32-bit words (instructions) and the data memory in bytes.
char name[25]; int main() { ...
Does the program behave the same way with shorter and longer names?
code | program | data |
---|---|---|
original | 4323 | 1544 |
modified |
Maintained by John Loomis, updated Mon Jul 28 18:40:04 2008