14.1 PROJECT 14.1 – Toggle LED

14.1.1 Project Description

This is perhaps the simplest Visual GLCD based project. In this project, a standard GLCD with touch screen is used, as described in Chapter 13. An LED is connected to pin RC7 of the microcontroller and the LED is toggled when a shape is touched on the screen.

14.1.2 Block Diagram

The block diagram of the project is as shown in Figure 13.3.

The operation of the project is as follows: After power-up and screen calibration, the user can touch the TOGGLE LED box to turn ON the LED. Touching this box again will turn the LED OFF.

14.1.3 Circuit Diagram

The circuit diagram of the project is as shown in Figure 13.5. Standard 128 × 64 pixel GLCD is used in this project. Switching transistors are used as the touch screen controller. A PIC18F45K22 type microcontroller is used in the design with 8 MHz crystal.

1. Create Project File
Start the Visual GLCD software. Select Project -> New from the top-down menu. A window will appear, as shown in Figure 14.1. Enter the project name and choose the desired project path. Then click OK. In this project, the name TOGGLE is given to the project.
2. Configure Project
In the Project Settings window, make the following settings:

Figure 14.1 Specify the project name and project path

img

14.1.3.1 General (see Figure 14.2)

Figure 14.2 General settings

img
  • Hardware patterns: EasyPIC6;
  • Target Compiler: mikroC Pro for PIC PRO for PIC;
  • Target Device: PIC18F45K22;
  • Device Clock (Hz): 8 000 000;
  • Configure PORT B, PORT C and PORT D as digital I/O, using the appropriate statements for the chosen microcontroller (e.g. use the ANSEL statements if using the PIC18F45K22 microcontroller), and configure PORT C as output in the ‘Init Code:’ section.

Notice here that the EasyPIC6 development board is used in the project, as this board uses the standard GLCD and touch screen to microcontroller interface.

14.1.3.2 GLCD (see Figure 14.3)

• GLCD_Data_Port: PORTD GLCD_CS1_Direction: TRISB0_bit
• GLCD_CS1: LATB0_bit GLCD_CS2_Direction: TRISB1_bit
• GLCD_CS2: LATB1_bit GLCD_RS_Direction: TRISB2_bit
• GLCD_RS: LATB2_bit GLCD_RW_Direction: TRISB3_bit
• GLCD_RW: LATB3_bit GLCD_EN_Direction: TRISB4_bit
• GLCD_EN: LATB4_bit GLCD_RST_Directiion:TRISB5_bit
• GLCD_RST: LATB5_bit

Figure 14.3 GLCD settings

img

14.1.3.3 Touch Panel (see Figure 14.4)

Figure 14.4 Touch Panel settings

img

img

You should also check the section ‘Init Code:’, to make sure that the entries are valid for the chosen microcontroller type.

Notice that the screen calibration can either be set as ‘Manual’ or ‘Preset’. In this project, the ‘Manual’ option is chosen so that the screen can be calibrated during the run time.

3. Add Screen and Give it a Name
Give a name to the screen. Let us rename the screen to MainScreen. In the Screens Properties on the left, find the Name property and change it to MainScreen, as shown in Figure 14.5. A new screen can be added if desired, by clicking on the Add Screen icon (green ‘ + ’ symbol).
4. Place Components
We can now use the Tools displayed on the right-hand side to place components on our screen. Click ‘Label’, place it on the screen, and change its ‘Caption’ to ‘TOGGLE LED:’ in the ‘Properties’ window in the bottom left-hand side. Then click ‘Rounded Button’ and place it on the screen. Change the ‘Caption’ of this button to ‘LED’. Figure 14.6 shows the screen layout with the components.
5. Assign Actions to Components
We can now add actions to our LED component, so that when the user clicks on this component, we can toggle the LED. Select the LED component by clicking on it. Then, double click on ‘OnClick’ property in the Properties window. You should see the event function name ‘ButtonRound1Click’ displayed in the Properties window and an empty function with this name will appear in the middle of the screen. Add the code associated with this event. Here, we wish to toggle the LED when the LED button is clicked, therefore, enter the code shown in Figure 14.7 to the function body.
6. Generate the Code
We are now ready to generate the code for our project. Just click the ‘Generate Code’ icon in the top menu. You should get a message to say that the code has been generated successfully. The generated code can be seen by clicking the ‘Generated Code’ at the bottom part of the screen.
7. Compile the Code and Load to the Microcontroller
Click the icon ‘Start Compiler’ in the top menu to start the mikroC Pro for PIC compiler. Compile the program as before by clicking the ‘Build’ icon in the top menu, and load the code to the target microcontroller by clicking the ‘Tools -> mE Programmer’ in the top menu.

Figure 14.5 Name the screen as MainScreen

img

Figure 14.6 Adding Components onto the Screen

img

Figure 14.7 Add the code associated with the event

img

You should now see the display, as in Figure 14.8. The LED connected to pin RC7 should toggle as you click the ‘TOGGLE LED’ button. When the program is run, the user is asked initially to calibrate the screen by touching the appropriate points of the screen in response to prompts ‘TOUCH BOTTOM LEFT’ and ‘TOUCH UPPER RIGHT’.

Figure 14.8 Typical display when the program is run

img

The code generated by the Visual GLCD program is large and consists of three modules. Assuming the project name is TOGGLE, the following modules are generated:

  • The main program: for example TOGGLE_main.C;
  • Events code: for example TOGGLE_events_code.C;
  • Driver program: for example TOGGLE_driver.C.

In addition, a number of include files are generated, for example TOGGLE_objects.h and TOGGLE_resources.h. The details of the generated files are beyond the scope of this book. Interested readers should consult the Visual GLCD documentation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.12.230