SHARE
TWEET

Untitled

a guest Feb 22nd, 2018 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if defined (__USE_LPCOPEN)
  2. #if defined(NO_BOARD_LIB)
  3. #include "chip.h"
  4. #else
  5. #include "board.h"
  6. #endif
  7. #endif
  8. #include <cr_section_macros.h>
  9. #include "oled.h"
  10. #define _LPC_ADC_ID LPC_ADC
  11. #define FS 20
  12. #define SCREEN_WIDTH OLED_WIDTH
  13. #define SCREEN_EX (OLED_WIDTH-1)
  14. #define SCREEN_EY (OLED_HEIGHT-1)
  15. #define FRAME_UP 10
  16. #define FRAME_CN 36
  17. #define FRAME_DW 63
  18. #define SCALE 53
  19. uint16_t dataADC;
  20. float Vdata;
  21. char sbuffer[30];
  22. uint16_t y = 0, y1 = FRAME_CN, x = 0;
  23. /*--------------------------------------------------------------------------------*/
  24. void ADC_IRQHandler(void) {
  25.     Chip_ADC_ReadValue(_LPC_ADC_ID, ADC_CH0, &dataADC);
  26.     Vdata = (dataADC) / 4095.0;
  27.     y = SCREEN_EY - Vdata * SCALE;
  28.  
  29.     OLED_ClearVerLine(x, 15);
  30.     OLED_Draw_Dotline(0, FRAME_UP, SCREEN_EX, FRAME_UP);
  31.     OLED_Draw_Dotline(0, FRAME_CN, SCREEN_EX, FRAME_CN);
  32.     OLED_Draw_Dotline(0, FRAME_DW, SCREEN_EX, FRAME_DW);
  33.     OLED_Draw_Line(x, y1, x, y);
  34.     y1 = y;
  35.     x++;
  36.     if (x >= SCREEN_WIDTH) {
  37.         x = 0;
  38. //      OLED_Clear_Screen(0);
  39.     }
  40.  
  41.     sprintf(sbuffer, "Voltage: %5.2f [V]", Vdata * 3.3);
  42.     OLED_Puts(0, 0, sbuffer);
  43.     OLED_Refresh_Gram();
  44. }
  45. /*--------------------------------------------------------------------------------*/
  46. int main(void) {
  47.     static ADC_CLOCK_SETUP_T ADCSetup;
  48.     uint32_t timerFreq;
  49. #if defined (__USE_LPCOPEN)
  50. // Read clock settings and update SystemCoreClock variable
  51.     SystemCoreClockUpdate();
  52. #if !defined(NO_BOARD_LIB)
  53. // Set up and initialize all required blocks and
  54. // functions related to the board hardware
  55.     Board_Init();
  56. // Set the LED to the state of "On"
  57.     Board_LED_Set(0, true);
  58. #endif
  59. #endif
  60.  
  61. // TODO: insert code here
  62.     /*--------------------- OLED Init -----------------------*/
  63.     OLED_Init();
  64.     /*--------------------- ADC Init ------------------------*/
  65.     Chip_ADC_Init(_LPC_ADC_ID, &ADCSetup);
  66.     Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, ADC_CH0, ENABLE);
  67.     Chip_ADC_EnableChannel(_LPC_ADC_ID, ADC_CH0, ENABLE);
  68.     NVIC_ClearPendingIRQ(ADC_IRQn);
  69.     NVIC_EnableIRQ(ADC_IRQn);
  70.     Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_ON_ADCTRIG0,
  71.             ADC_TRIGGERMODE_RISING);
  72.     /*-------------------- Timer32_0 Init --------------------*/
  73.     Chip_TIMER_Init(LPC_TIMER32_0);
  74.     timerFreq = Chip_Clock_GetSystemClockRate();
  75.     Chip_TIMER_Reset(LPC_TIMER32_0);
  76.     Chip_TIMER_MatchEnableInt(LPC_TIMER32_0, 0);
  77.     Chip_TIMER_SetMatch(LPC_TIMER32_0, 0, (timerFreq / (2 * FS)));
  78.     Chip_TIMER_ResetOnMatchEnable(LPC_TIMER32_0, 0);
  79.     Chip_TIMER_ExtMatchControlSet(LPC_TIMER32_0, 0, TIMER_EXTMATCH_TOGGLE, 0);
  80.     Chip_TIMER_Enable(LPC_TIMER32_0);
  81.     /*-------------------- End of Init ----------------------*/
  82. //  OLED_Draw_Dotline(0, FRAME_UP, SCREEN_EX, FRAME_UP);
  83. //  OLED_Draw_Dotline(0, FRAME_CN, SCREEN_EX, FRAME_CN);
  84. //  OLED_Draw_Dotline(0, FRAME_DW, SCREEN_EX, FRAME_DW);
  85.     OLED_Refresh_Gram();
  86.     while (1) {
  87.     }
  88.     return 0;
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top