main.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <chip.h>
  2. #include <delay.h>
  3. #include "u8g2.h"
  4. /*=======================================================================*/
  5. /* Configuration */
  6. #define SYS_TICK_PERIOD_IN_MS 100
  7. /*=======================================================================*/
  8. /* external functions */
  9. uint8_t u8x8_gpio_and_delay_lpc824(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
  10. /*=======================================================================*/
  11. /* system procedures and sys tick master task */
  12. volatile uint32_t sys_tick_irq_cnt=0;
  13. void __attribute__ ((interrupt)) SysTick_Handler(void)
  14. {
  15. sys_tick_irq_cnt++;
  16. }
  17. /*=======================================================================*/
  18. u8g2_t u8g2;
  19. void draw(u8g2_t *u8g2)
  20. {
  21. u8g2_SetFontMode(u8g2, 1); // Transparent
  22. u8g2_SetFontDirection(u8g2, 0);
  23. u8g2_SetFont(u8g2, u8g2_font_6x12_tr);
  24. u8g2_DrawStr(u8g2, 0, 20, "Hello World");
  25. }
  26. /*=======================================================================*/
  27. /*
  28. setup the hardware and start interrupts.
  29. called by "Reset_Handler"
  30. */
  31. int __attribute__ ((noinline)) main(void)
  32. {
  33. /* call to the lpc lib setup procedure. This will set the IRC as clk src and main clk to 24 MHz */
  34. Chip_SystemInit();
  35. /* if the clock or PLL has been changed, also update the global variable SystemCoreClock */
  36. SystemCoreClockUpdate();
  37. /* set systick and start systick interrupt */
  38. SysTick_Config(SystemCoreClock/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS);
  39. /* enable clock for several subsystems */
  40. Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON | SYSCTL_CLOCK_GPIO | SYSCTL_CLOCK_SWM);
  41. /* turn on GPIO */
  42. Chip_GPIO_Init(LPC_GPIO_PORT); /* Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO); */
  43. //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, IOCON_FUNC1); /* RxD */
  44. Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 15);
  45. /* setup display */
  46. u8g2_Setup_ssd1306_i2c_128x64_noname_2(&u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_lpc824);
  47. u8g2_InitDisplay(&u8g2);
  48. u8g2_SetPowerSave(&u8g2, 0);
  49. for(;;)
  50. {
  51. Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 15);
  52. delay_micro_seconds(1000000);
  53. u8g2_FirstPage(&u8g2);
  54. do
  55. {
  56. draw(&u8g2);
  57. } while( u8g2_NextPage(&u8g2) );
  58. Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 15);
  59. delay_micro_seconds(1000000);
  60. }
  61. }