Exercise I/O on OSR USB-FX2 board (Cypress) using Keil compiler


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //-----------------------------------------------------------------------------
  2. // File: OsrUsbFx2_io.c
  3. // Contents: Exercise I/O on OSR USB-FX2 board.
  4. //
  5. // Route switches to the bar LEDs.
  6. // 7-seg LED just 'spins', displaying a pattern.
  7. // Uses EzUsb.LIB.
  8. //
  9. // Tools:
  10. // Compiled using Keil uVision (.uv2) on Windows XP.
  11. // Expect no errors or warnings.
  12. // Download the resulting .hex file (OsrUsbFx2_io.hex) using a utility like EzMr.
  13. // Remove OSR USB-FX2 eeprom for EzMr to connect to it.
  14. //
  15. // Mapping of Cypress port I/O to OSR USB-FX2 board:
  16. // Port A is the switches, SW1.
  17. // PA0 is on the right.
  18. // PA7 is on the left.
  19. // 1 is OFF, 0 is ON.
  20. // Port B is the 7-segment display, DN1.
  21. // ==0==
  22. // # #
  23. // 6 1
  24. // # #
  25. // ==5==
  26. // # #
  27. // 4 2
  28. // # #
  29. // ==7== (3)
  30. //
  31. // Port D is the 10 - LED bar display, DN2. 1 is OFF, 0 is ON.
  32. // 0 - nc
  33. // 1 - nc
  34. // 2 - PD4
  35. // 3 - PD3
  36. // 4 - PD2
  37. // 5 - PD1
  38. // 6 - PD0
  39. // 7 - PD7
  40. // 8 - PD6
  41. // 9 - PD5
  42. //
  43. //-----------------------------------------------------------------------------
  44.  
  45. #include "fx2.h" // needed by fx2regs.h
  46. #include "fx2regs.h" // needed for port identifiers such as IOB etc.
  47.  
  48.  
  49. main()
  50. {
  51. // Set output-enables for ports A, B and D.
  52. OEA = 0; // all inputs.
  53. OEB = 0xFF; // all outputs.
  54. OED = 0xFF; // all outputs.
  55.  
  56. while (TRUE)
  57. {
  58. static BYTE pattern7Seg[] = { 1, 2, 0x04, 0x80, 0x10, 0x40 }; // Create table for 7-seg pattern.
  59. static BYTE x = 0;
  60.  
  61. IOB = ~pattern7Seg[x]; // Write a table element to 7-seg display.
  62. x++; // Next table element.
  63. if ( x>=sizeof( pattern7Seg ) ) { x=0; } // wrap-around.
  64.  
  65. // Route swtiches to corresponding LED.
  66. // Note that the order of the switches and the order of the LEDs isn't intuitive.
  67. // Route such that the left switch controls the top LED and the right swtich controls the bottom LED.
  68. PD4 = PA7;
  69. PD3 = PA6;
  70. PD2 = PA5;
  71. PD1 = PA4;
  72. PD0 = PA3;
  73. PD7 = PA2;
  74. PD6 = PA1;
  75. PD5 = PA0;
  76.  
  77. EZUSB_Delay(100);
  78. } // while.
  79. } // main.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.