main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_inb24_mf);
  24. u8g2_DrawStr(u8g2, 0, 30, "U");
  25. u8g2_SetFontDirection(u8g2, 1);
  26. u8g2_SetFont(u8g2, u8g2_font_inb30_mn);
  27. u8g2_DrawStr(u8g2, 21,8,"8");
  28. u8g2_SetFontDirection(u8g2, 0);
  29. u8g2_SetFont(u8g2, u8g2_font_inb24_mf);
  30. u8g2_DrawStr(u8g2, 51,30,"g");
  31. u8g2_DrawStr(u8g2, 67,30,"\xb2");
  32. u8g2_DrawHLine(u8g2, 2, 35, 47);
  33. u8g2_DrawHLine(u8g2, 3, 36, 47);
  34. u8g2_DrawVLine(u8g2, 45, 32, 12);
  35. u8g2_DrawVLine(u8g2, 46, 33, 12);
  36. u8g2_SetFont(u8g2, u8g2_font_4x6_tr);
  37. u8g2_DrawStr(u8g2, 1,54,"github.com/olikraus/u8g2");
  38. }
  39. /*=======================================================================*/
  40. /*
  41. setup the hardware and start interrupts.
  42. called by "Reset_Handler"
  43. */
  44. int __attribute__ ((noinline)) main(void)
  45. {
  46. /* call to the lpc lib setup procedure. This will set the IRC as clk src and main clk to 24 MHz */
  47. Chip_SystemInit();
  48. /* if the clock or PLL has been changed, also update the global variable SystemCoreClock */
  49. SystemCoreClockUpdate();
  50. /* set systick and start systick interrupt */
  51. SysTick_Config(SystemCoreClock/1000UL*(unsigned long)SYS_TICK_PERIOD_IN_MS);
  52. /* enable clock for several subsystems */
  53. Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON | SYSCTL_CLOCK_GPIO | SYSCTL_CLOCK_SWM);
  54. /* turn on GPIO */
  55. Chip_GPIO_Init(LPC_GPIO_PORT); /* Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_GPIO); */
  56. //Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 15, IOCON_FUNC1); /* RxD */
  57. Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 0, 15);
  58. /* setup display */
  59. u8g2_Setup_ssd1306_i2c_128x64_noname_2(&u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_lpc824);
  60. u8g2_InitDisplay(&u8g2);
  61. u8g2_SetPowerSave(&u8g2, 0);
  62. for(;;)
  63. {
  64. //Chip_GPIO_SetPinOutHigh(LPC_GPIO_PORT, 0, 15);
  65. //delay_micro_seconds(1000000);
  66. u8g2_FirstPage(&u8g2);
  67. do
  68. {
  69. draw(&u8g2);
  70. } while( u8g2_NextPage(&u8g2) );
  71. //Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, 0, 15);
  72. delay_micro_seconds(1000000);
  73. }
  74. }