main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. main.c
  3. PLU example
  4. switch at PIO0_02 and PIO0_10
  5. LED at PIO0_09 and PIO0_15
  6. */
  7. #include <LPC8xx.h>
  8. #include <syscon.h>
  9. #include <gpio.h>
  10. #include <delay.h>
  11. void plu(void);
  12. /*=======================================================================*/
  13. /* Configuration */
  14. #define SYS_TICK_PERIOD_IN_MS 100
  15. /*=======================================================================*/
  16. /* system procedures and sys tick master task */
  17. volatile uint32_t sys_tick_irq_cnt=0;
  18. void __attribute__ ((interrupt)) SysTick_Handler(void)
  19. {
  20. sys_tick_irq_cnt++;
  21. }
  22. /*=======================================================================*/
  23. /*
  24. config: 0
  25. PIO0_2 --> PLUINPUT2 --> LUT4_INP0
  26. PIO0_10 --> IN0 --> OUT0 --> PIN0_22 --> PLUINPUT5 --> LUT4_INP1
  27. Cfg | PIO10 PIO2 | result
  28. 1 | 0 0 | 1
  29. Cfg | PIO10 PIO2 | result
  30. 2 | 0 1 | 1 falsch, sieht nach 2 | 1 0 | 1 aus (reihenfolge falsch???)
  31. Cfg | PIO10 PIO2 | result
  32. 3 | 0 1 | 1
  33. 3 | 1 1 | 1
  34. Config=1
  35. PIO10 PIO2 | result
  36. 0 0 | 1 --> ok
  37. 0 1 | 0
  38. 1 0 | 0
  39. 1 1 | 0
  40. Config=1
  41. PIO10 PIO2 | result
  42. 0 0 | 0 --> ok
  43. 0 1 | 1
  44. 1 0 | 0
  45. 1 1 | 0
  46. */
  47. /*=======================================================================*/
  48. /*
  49. setup the hardware and start interrupts.
  50. called by "Reset_Handler"
  51. */
  52. int __attribute__ ((noinline)) main(void)
  53. {
  54. /* call to the lpc lib setup procedure. This will set the IRC as clk src and main clk to 24 MHz */
  55. SystemInit();
  56. /* if the clock or PLL has been changed, also update the global variable SystemCoreClock */
  57. SystemCoreClockUpdate();
  58. /* set systick and start systick interrupt */
  59. SysTick_Config(main_clk/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS);
  60. /* */
  61. GPIOInit();
  62. /* enable clock for several subsystems */
  63. Enable_Periph_Clock(CLK_IOCON);
  64. Enable_Periph_Clock(CLK_SWM);
  65. GPIOSetDir( PORT0, 15, OUTPUT);
  66. GPIOSetDir( PORT0, 9, OUTPUT);
  67. GPIOSetDir( PORT0, 2, INPUT);
  68. plu();
  69. for(;;)
  70. {
  71. GPIOSetBitValue(PORT0, 15, 1);
  72. delay_micro_seconds(100000);
  73. GPIOSetBitValue(PORT0, 15, 0);
  74. delay_micro_seconds(1000000);
  75. }
  76. }