LEDs - 02
In this section we are going to: - Explain the Zilog C macros in our code - Examine the PAOUT register - Setup the Debugger with breakpoints to observe PAOUT changing when the Tutorial01.c program is run and downloaded to the ZCOG |
This is our initial C code for the eZ8:
The initial code we wrote turns off all LEDs attached to Port A, turns them on, and then turns them off before the program Returns. There are not LEDs setup to use Port A, there is no timing setup, no registers "primed", no supporting routines called, etc. In other words, it should not work. When you compiled and downloaded the Tutorial01.zdsproj file to your dev board, it should have stopped running the ledblink.zdsproj test file you created back in the eZ8 Development Kits section. The result is a board that apart from the green Power LED, appears dead. So let's do something useful with the code.
When you see the statement PAOUT = 0xFF, you may realize this is not C code. It's actually a macro that Zilog wrote to make our job easier. That macro can be found in the ez8.h header file that is "included" at the top of the code segment screenshot above. The full path to the ez8.h header file might be D:\Zilog\ZDSII_Z8Encore!_5.6.0\include\zilog. (From this point onward we'll use <install>\include\zilog to reference locations.)
This a breakdown of the Port A Output data register, PAOUT.
Examine the PAOUT register: BIT: 8 bits numbered 0 through 7. If referring to a pin, we might see PA0 and if many pins we might use PA7:0 meaning pins PA7 to PA0. FIELD: The POUT refers to the Port register in general because there are actually 9 ports labeled PortA (PA) through Port J (PJ). RESET: once the port is reset, we expect the bits to be zeroes. R/W: indicates the individual pins can be read from or written to. ADDRESS: This is the address for the whole port, e.g., Port A is at Register address FD3.
What is PAOUT? Searching for "PAOUT" within the ez8.h file we find the following on line 1454: #define PAOUT (*(unsigned char volatile far*)0xFD3) // Reset = 0x00, Port A Output Data The "PAOUT = 0x00" command will write all zeros to memory address 0xFD3. PAOUT is a Zilog macro. The macro will be replaced with the statement "(*(unsigned char volatile far*)0xFD3) = 0x00;". The meaning of "(*(unsigned char volatile far*)0xFD3) = 0x00;" is "the char-sized thing at address 0xFD3 that is not signed, can change value unexpectedly or has side-effects and requires a full 12-bit address, never an 8-bit one" If we attached LEDs to all 8 ports of PAOUT (PA7:0, register 0xFD3), then the three lines of code would theoretically toggle them from all off to all on and then off again. The assumption is we would need to send a 0 or low signal to complete the electrical circuit and light the LED (the LED and current limiting resistor are connected to 3v3 on one end and any PAOUT pin (PA0:PA7) on the other end).
VIDEO: Configure the Debugger for Breakpoints Below is a 2-minute video (you'll need to click on the .gif below for the full-size video) on stepping through Breakpoints to see the PAOUT register change with our code.
Our Next Challenge: Below is a schematic from our ZCOG board showing that PA is not used for lighting the red, green and yellow LEDs. Instead, bit 7 of Port B (PB7) is used for red, PC4 is used for yellow and PC5 is used for green.
Z8F64820100ZCOG Schematic for the LEDs circuit:
In the next section we'll look at all the other registers that need to be programmed so we can work with one or more of the LEDs shown above. |