HOME

NEXT: Switches 01a

Switches-01

In this section we are going to:

- Use the ledblink project code files to shortcut the development process for a new test project

- Using interrupts, we want to only flash LEDs when either switch SW2 (port pin PA6) or SW3 (port pin PA7) is pressed

- Examine Timers and Interrupts docs

Getting our files ready:

In our first project, Tutorial01.zdsproj, we built the source code file Tutorial01.c and deposited it in this path: D:\Zilog\ZDSII_Z8Encore!_5.6.0\samples\01_TUTORIAL

Our only file "include" was ez8.h by way of the C-compiler preprocessor directive  #include <ez8.h>  in the .c file. Due to the angle-brackets of the include directive, the preprocessor found it in the standard system and app directories used by ZDS-II. If the include directive was instead surrounded by quotes as in #include "leds.c", then the preprocessor  would search all the folders in the project directory. To make it simpler to find the files needed for our next project, close ZDS-II and then navigate to the following folder: D:\Zilog\ZDSII_Z8Encore!_5.6.0\samples\XP_F6482

With your mouse clicked on the XP_F6482_LedBlink_C folder, hold down the <CTRL> key and drag the folder to the bottom of the folder list. Right-click on this folder (prob'ly renamed to XP_F6482_LedBlink_C - Copy) and rename it to TEST.  Within the renamed folder, delete the *.wsp and *.ztgt files, then rename the *.zdsproj file to test.zdsproj.

You now have all the files you'll need to start coding. In the new TEST folder, open the new project TEST.zdsproj, expand the Standard Project Files folder/header in the left panel, and double-click main.c so you can see it in the workspace panel on the right.

 

Next steps:

Build | Set Active Configuration | Debug.

Project | Settings | Debugger "folder" : ensure your dev board is chosen in the top right panel and your USBSmartCable is chosen in the bottom panel.

Tools | Options | Editor | Advanced Editor Options: select Display Line Number Margin so you know which line to go to when the compiler complains with an error and line number.

Build | Rebuild All.

Debug | Go. The dev board demo file, ledblink, should now be running and the LEDs will illuminate in succession until one of the switches is pressed, at which time they'll change lighting direction.

This is the file set we'll modify for our needs as we build TEST.zdsproj.

 

Changing the code

Learning something new is easiest and fastest when it's handled in palatable portions. The original ledblink project printed to the host PC screen via its UART when a button was pressed to change the direction of the flashing LEDs. We'll simplify that initially in our code to just having a LED light up when a switch is pressed, and go out when the switch is released.

Both ledblink.zdsproj and TEST.zdsproj projects contain the same code that initializes various devices. We'll have a look at those routines before we build code to execute our design.

In the left panel under Standard Project Files, we can double-click on the main2.c file (I changed the name of mine from main.c) so that it appears in the workspace. Within the workspace, we can see there are a lot of code comment sections starting in the left margin. Rather than deleting them to keep more active code on the screen, we'll just click on the "-" hyphens in the left margin which will close up the unnecessary content for the moment. I believe this is called code folding.

We won't be needing the UART stuff so we can use the comment characters, "//", to remove them from execution. Once we're sure we haven't broken anything, we can delete them at a later date.

 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

In case you need more info on PATH:

Right-click This PC, choose Properties. Type Edit the System Environment  Variable and choose the Edit... entry. At the bottom select Environment Variables. Now you can check the PATH for your user account and for the PC. Need even more info on PATH for ZDS-II, try this link: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

 

 

NEXT: Switches 01a

TOP

 

HOME