Revision: 15418
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 5, 2009 21:00 by jimfred
Initial Code
//-----------------------------------------------------------------------------
// File: OsrUsbFx2_io.c
// Contents: Exercise I/O on OSR USB-FX2 board.
//
// Route switches to the bar LEDs.
// 7-seg LED just 'spins', displaying a pattern.
// Uses EzUsb.LIB.
//
// Tools:
// Compiled using Keil uVision (.uv2) on Windows XP.
// Expect no errors or warnings.
// Download the resulting .hex file (OsrUsbFx2_io.hex) using a utility like EzMr.
// Remove OSR USB-FX2 eeprom for EzMr to connect to it.
//
// Mapping of Cypress port I/O to OSR USB-FX2 board:
// Port A is the switches, SW1.
// PA0 is on the right.
// PA7 is on the left.
// 1 is OFF, 0 is ON.
// Port B is the 7-segment display, DN1.
// ==0==
// # #
// 6 1
// # #
// ==5==
// # #
// 4 2
// # #
// ==7== (3)
//
// Port D is the 10 - LED bar display, DN2. 1 is OFF, 0 is ON.
// 0 - nc
// 1 - nc
// 2 - PD4
// 3 - PD3
// 4 - PD2
// 5 - PD1
// 6 - PD0
// 7 - PD7
// 8 - PD6
// 9 - PD5
//
//-----------------------------------------------------------------------------
#include "fx2.h" // needed by fx2regs.h
#include "fx2regs.h" // needed for port identifiers such as IOB etc.
main()
{
// Set output-enables for ports A, B and D.
OEA = 0; // all inputs.
OEB = 0xFF; // all outputs.
OED = 0xFF; // all outputs.
while (TRUE)
{
static BYTE pattern7Seg[] = { 1, 2, 0x04, 0x80, 0x10, 0x40 }; // Create table for 7-seg pattern.
static BYTE x = 0;
IOB = ~pattern7Seg[x]; // Write a table element to 7-seg display.
x++; // Next table element.
if ( x>=sizeof( pattern7Seg ) ) { x=0; } // wrap-around.
// Route swtiches to corresponding LED.
// Note that the order of the switches and the order of the LEDs isn't intuitive.
// Route such that the left switch controls the top LED and the right swtich controls the bottom LED.
PD4 = PA7;
PD3 = PA6;
PD2 = PA5;
PD1 = PA4;
PD0 = PA3;
PD7 = PA2;
PD6 = PA1;
PD5 = PA0;
EZUSB_Delay(100);
} // while.
} // main.
Initial URL
Initial Description
Initial Title
Exercise I/O on OSR USB-FX2 board (Cypress) using Keil compiler
Initial Tags
Initial Language
C