Sample code for exul452

This sample C code is provided for your reference to help you get started with your new development board.

You will need MPLAB X and the MPLAB C18 compiler for PIC18 MCUs. These can both be downloaded free of charge from Microchip's website.

For any additional information, please see the PIC18F452 datasheet.

The schematic for the board as delivered is available for download:

Download Circuit Diagram

You can also download a labelled picture of the board as it was shipped:

Download Diagram

If you have any questions about these samples or PIC programming in general, please visit our forum at http://buyhere22.com/forum/.

I/O sample

This sample shows how to set up pins as inputs and outputs, how to read a button press, and how to turn an LED on and off.

When you press the button attached to RA4, the LED attached to pin RC2 will light up for half a second.

You will need:

Download source code Download hex file Download Circuit Diagram

HD44780 LCD sample

This sample demonstrates the use of the HD44780 LCD - including both 4-bit and 8-bit modes and custom characters.

The sample will output the text "Hello World!" and then a custom character will be sent to the screen and output on the second line.

You will need:

Download source code Download hex file Download Circuit Diagram

Analog to Digital conversion samples

These two samples demonstrate the use of the 10-bit Analog to Digital converter on the PIC.

Sample 1 demonstrates the use of a single analog input on pin RA0 (AN0) using the VDD and VSS voltages as the references. The value will be read in and output to the LCD display.

Sample 2 demonstrates the use of a single analog input on pin RA0 (AN0) using pin RA3 as the positive voltage reference, and pin RA2 as the negative voltage reference. The value will be read in and output to the LCD display.

You will need:

Download source code Download hex file Download Circuit Diagram 1 Download Circuit Diagram 2

Pulse Width Modulation sample

These samples demonstrate the use of the PWM module.

Sample 1 uses it to adjust the brightness of an LED.

Sample 2 uses it to play 8 notes through a piezo-electric buzzer.

You will need:

Download source code Download hex file Download Circuit Diagram 1 Download Circuit Diagram 2

Interrupts sample

This sample demonstrates the use of interrupts, and how they affect the program that is running.

The sample will constantly increment a counter. Pressing the button attached to RB0 will toggle the LED on and off. Pressing the button attached to RB1 will set the counter to 10000. Pressing the button attached to RB2 will set the counter to 0.

You will need:

Download source code Download hex file Download Circuit Diagram

Timer samples

These two samples demonstrate the use of the PIC timer modules.

Sample 1 demonstrates the use of the internal clock source, including an example of using the prescaler. This sample will read the timer, wait for 1 second, read the timer again and then output the number of timer ticks that have elapsed during the 1 second period.

Sample 2 demonstrates the use of an external clock source. This sample will count the number of times the button attached to RA4 is pressed.

You will need:

Download source code Download hex file Download Circuit Diagram 1 Download Circuit Diagram 2

EEPROM sample

This sample demonstrates how to read from the PIC's internal EEPROM, and how to write data back to it.

Please note that reprogramming the PIC through MPLAB X will clear the EEPROM's contents.

This sample counts the number of times the button attached to RA4 is pressed, and writes it to the EEPROM. This will then be loaded into memory if the PIC resets - so the counter will continue from it's previous position.

You will need:

Download source code Download hex file Download Circuit Diagram

1-WIRE bus sample

This sample demonstrates an implementation of the 1-WIRE bus, and shows the operation of the DS18B20 digital thermometer.

You will need:

Download source code Download hex file Download Circuit Diagram

Board test program

This sample is the test program that shipped with your board.

This will display a welcome screen first, and then step through a series of tests. Button 5 (pin RA4) is used to advance to the first test.

The tests are:

  1. IO: Press button 5 (pin RA4) 5 times. After each press, the LED attached to RC2 will light for 500msec. After the 5th press, it will advance to the next test.
  2. LCD: This will display some text and a custom character on the LCD. Press button 5 to advance to the next test.
  3. Analog to Digital conversion: This will display the current value of AN0 (RA0). Adjust the potentiometer attached to AN0 to adjust the value shown on screen. Press button 5 to advance to the next test.
  4. Analog to Digital conversion (with voltage references): This will display the current value of AN0, using pins AN2 and AN3 as voltage references. Adjusting the potentiometers attached to AN0 and AN3 will adjust the value shown on screen. Press button 5 to advance to the next test.
  5. PWM: The LED attached to pin RC2 will fade in and out. The duty cycle is displayed on the screen. Press button 5 to advance to the next test.
  6. PWM (with sound): The piezo-sounder attached to pin RC1 will play a series of tones. Press button 5 after it has finished to advance to the next test.
  7. Interrupts: A counter will count up endlessly on the display. Button 2 (attached to INT0) will toggle the LED attached to RC2. Button 3 (INT1) will set the counter to 10,000. Button 4 (INT2) will set the counter to 0. Press button 5 to advance to the next test.
  8. Timer (internal): The device will time how many timer pulses occur during a single second, and display this number on the display. 39062.5 pulses occur within a second, so values 39062 and 39063 are normal. Press button 5 to advance to the next test.
  9. Timer (external): The device will count how many times button 5 is pressed. Press the button 10 times to advance to the next test.
  10. EEPROM: The device will self-test all of the EEPROM addresses. If it fails it will stop at the address which failed and display (for example) "Test 0x98: FAIL" on the screen. If it succeeds, it will display "Test 0xff: OK". Press button 5 to advance to the next test.
  11. 1-WIRE: The device will continuously display the current temperature as-read from the attached temperature sensor. Press button 5 to finish the tests.

You will need:

Download source code Download hex file Download Circuit Diagram