| Programming a New Development Board |
|
|
| Thursday, 12 November 2009 21:09 | |
|
When starting a new project on either a development board or a board of my own design, rather than trying to do everything in one huge programming effort, I break the project down into small pieces and work towards the end goal in small sections. This process really saves on frustration and makes troubleshooting easier when problems occur.
Determine Board Layout
While determining connections from the schematic, it's also useful to determine the sense of LEDs and switches. LEDs may be connected between V+ and the port pin, in which case, a LOW pin will activate the LED, or may be connected between the port pin and ground, which requires a high port pin to activate. See the drawing below. Similarly, a switch might be connected between ground and the port pin and pulled high, so a press results in the pin going low, or may be connected between V+ and the port pin and pulled low, in which case a press results in a high port pin. Either sense is equally valid, but to make a program work as planned, you need to know what to expect.
Finally, while looking at the schematic, determine the part numbers for any other chips installed. Consult the data sheet and schematic to determine the address of any I2C chips (EEPROM and a temperature sensor in this case) installed. Data sheets for I2C chips will get a good workout, so keep them close at hand.
Code Development
Device = 18F4520 Why such a trivial little program when you have far bigger things in mind? Because if the trivial program won't work, nothing else will! This checks that the PIC is actually running, that the programmer is working, the power supply is ok, and all the little gotcha's along the way. If this doesn't work, check for obvious problems, like no power (yes, it happens), the programmer is connected (yes, this happens too), the correct oscillator settings, the port pins really are connected like you think they are, and that any jumpers on a development board are in the right positions.
Next Steps
A Word About Programmers
UART/Serial Communications
(insert program listing)
Notice the SetBaudRate command in this code. It needs to be set to the same speed in the PIC and in the terminal program on the PC. If you see gibberish on the terminal screen, chances are that the baud rate is not set correctly. The baud rate generator depends on knowing the correct clock frequency, so the correct clock frequency must be selected (note: the clock frequency may be different than the crystal frequency depending on the oscillator configuration). Also note in the USART.write statement the 13 and 10; this corresponds to the ASCII codes for carriage control and line feed so that a new line is printed for each cycle.
Character LCD DisplayThis board has a built-in LCD display, compatible with the standard HD44780 controller. Swordfish has an LCD module to help us out. There is no standard port arrangement to connect an LCD module, so we need to define options prior to loading the LCD module to let Swordfish know what pins to use. (insert listing)
The option statements define the interface pins for the LCD and must be specified before including the LCD module. utils.bas and convert.bas include some common functions that are useful to have, including SetAllDigital, which configures ports (PORTA in this case) that have analog and digital capabilities.
Module Best PracticesThis would be a good place to mention best practices when using modules. The command Write is used in a number of modules. When Swordfish compiles a program, it first checks to see if a command is part of the basic library. If not, it continues looking through the include files until it finds a matching command. In the case of write, it might send something to the USART, the LCD, EEPROM or other places, depending on which module was loaded first. If we extend the command to USART.Write, Swordfish then knows to look in the USART module to find the command. The simple Write command will work, but as you add to a program, that which was perfect may give you unexpected results.
What Next?If you assemble these pieces, you're got a good framework to continue code development. You've got a PIC that functions, outputs via LED, UART or LCD and inputs via switches or UART. From here, the direction depends on what you're trying to accomplish. For each new hardware component or function, test how it works in small pieces. If you're developing a new algorithm or procedure, test to be sure it gives the results it should. Once you have the pieces working, build the "big stuff" from the tested parts. Using a development board such as this board from Sure is a good method to check out hardware and software before designing a dedicated pc board, and to make sure the hardware works as conceived.
Comments (18)
Joomla components by Compojoom
|
|
| Last Updated ( Sunday, 15 November 2009 21:56 ) |
Whos Online
- andyo
- Jon Chandler
- MrDEB
Forum Activity
LCD / 18F1320 - mrdeb Saturday, 20 March 2010 06:21 - [3 replies]
A 'throw-away" PIC board - mrdeb Thursday, 18 March 2010 06:19 - [32 replies]
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]
Recent Comments
- 2010-03-20 07:58:45 andyo
Nice. The TAP-28 boards are looking good. When I've had a buzzi...
- 2010-03-19 22:05:12 ozbec...
The author (Hop) suggests to "set the target PIC's configuratio...
- 2010-03-17 22:58:18 Jon C...
Graham, Thanks for fixing the spacing on the array. This is how i...
- 2010-03-17 21:14:34 ASDne...
Thanks Graham, It is a problem with Flowcode because the demo wa...
- 2010-03-17 19:50:32 Graha...
Looks like you've pretty much solved every minor issue that was enc...
- 2010-03-17 11:42:03 Jon C...
The low-cost servo does have one other feature. The origina...
- 2010-03-17 10:56:44 Graha...
I am not familiar with flowcode, though did you try powering the bo...
- 2010-03-15 21:47:55 ASDne...
Hello there, I am still trying to get the LCD to work but I am pro...







Thanks for yet another great share Jon. I've never used the development board discussed, though I am completely blown away by the price vs hardware ratio.
Just in case someone is wondering how much the Dem2PLUS Development Board costs, it is ~US$35 and can be brought from either eBay or direct. Given the solid reputation, that's a good buy.
http://shop.ebay.com/?_from=R40&_trksid=p3907.m38.l1313&_nkw=PIC18F 4520+Dem2PLUS+&_sacat=See-All-Categories
http://sureelectronics.net/goods.php?id=24