Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices

E-Blocks

Flowcode Step By Step

PICmicro Projects

Labs

Setting up the LCD

<^< Port B Interrupts | Course Index | Using the ADC >^>

The Hi-Fi system will make use of the LCD display. We want to make the display show the volume and also the radio channel. Later on we can make it display data on the CD player etc. To do this we will use the first line of the display to show the volume and the second line to show the radio channel. In this program we will separate all of the main routines into separate macros to make the structure of the main program easier to read. The two macros we will set up here will initialise the display, and then refresh the display as the program runs.

  1. Add an LCD display to your project. Connect it to port C.
  2. Generate two new macros. One called 'updatedisplay' and the other called 'initialisedisplay'
  3. Develop the following program in the 'initialisedisplay' macro:
You should by now have a good grasp of what is happening here. The first icon starts the display, then the cursor is set to 0,0 or the top left. The third icon prints "Volume:" on the top line, and the next icon moves the cursor to the second line. The last icon prints "Channel:" on the bottom line.
  1. Add a few new variables, one called 'volume' set as a 'Byte', and 'ADCreading' as an 'Int' type. We will get to these later.
  2. Develop the following program in the 'updatedisplay' macro:
Here the first icon moves the cursor to a point after "Volume:". It prints three blank spaces to delete the old volume setting. The next two icons move the cursor back to the previous position and print the value of the 'volume' variable. The next cursor moves to the bottom line of the display after "Channel:", and the last icon prints the actual volume.
  1. To the main program add a macro icon which calls the 'initialisedisplay' macro.
  2. Next add another Interrupt icon. To demonstrate that it is possible to use more than one type of interrupt in a single program we will use a timer interrupt to call the 'updatedisplay' macro. Change the properties of the 'Interrupt on:' to 'Timer 0' ('TMR0'). Click on the properties button and set the 'Clock Source Select' to 'Internal clock (CLKO)' and set the 'Prescaler Rate' to 1:256 making the timer run at 75Hz with a 19.6608MHz crystal. Click OK and then change the properties of the 'Will call macro:' to 'updatedisplay', then click OK again. Your main program should now look like this:
  1. Simulate your program. Note that both the Port B change interrupt and the timer interrupt both simulate. You will have to wait some time during simulation before the timer interrupt is triggered. The interrupt rate is 75Hz and in this time the PICmicro can execute hundreds of instructions.

<^< Port B Interrupts | Course index | Using the ADC >^>

Print - Search - Login

Page last modified on May 14, 2013, at 01:45 PM