Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.60 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "LPC177x_8x.h"
  6. #include "system_LPC177x_8x.h"
  7. #include <retarget.h>
  8. #include "my_parse.h"
  9.  
  10. #include <DRV\drv_sdram.h>
  11. #include <DRV\drv_lcd.h>
  12. #include <DRV\drv_uart.h>
  13. #include <DRV\drv_touchscreen.h>
  14. #include <DRV\drv_led.h>
  15. #include <utils\timer_software.h>
  16. #include <utils\timer_software_init.h>
  17.  
  18.  
  19. AT_DATA at;
  20. const char at_command_simple[] = "AT\r\n";
  21. const char at_command_csq[] = "AT+CSQ\r\n";
  22. timer_software_handler_t my_timer_handler;
  23.  
  24. void sendComand(const char* command)
  25. {
  26.         DRV_UART_FlushRX(UART_3);
  27.         DRV_UART_FlushTX(UART_3);
  28.       DRV_UART_Write(UART_3, at_command_csq, strlen(at_command_csq));
  29. }
  30.  
  31. void getCommand()
  32. {
  33.         bool ready = false;
  34.       uint8_t byte = 0;
  35.       TIMER_SOFTWARE_request();
  36.       TIMER_SOFTWARE_configure();
  37.       TIMER_SOFTWARE_start();
  38. }
  39.  
  40. void ExecuteCommand(const char* command)
  41. {
  42.         sendComand(command);
  43.     //getCommand();
  44. }
  45.  
  46. void timer_callback_1(timer_software_handler_t h)
  47. {
  48. }
  49.  
  50. void testLCD()
  51. {
  52.     uint32_t i,j;
  53.     LCD_PIXEL foreground = {0, 255, 0, 0};
  54.     LCD_PIXEL background = {0, 0, 0, 0};
  55.    
  56.    
  57.     for (i = 0; i < LCD_HEIGHT; i++)
  58.     {
  59.         for (j = 0; j < LCD_WIDTH / 3; j++)
  60.         {
  61.             DRV_LCD_PutPixel(i, j, 255, 0, 0);
  62.         }
  63.         for (j = LCD_WIDTH / 3; j < 2 * (LCD_WIDTH / 3); j++)
  64.         {
  65.             DRV_LCD_PutPixel(i, j, 230, 220, 0);
  66.         }
  67.         for (j = 2 * (LCD_WIDTH / 3); j < LCD_WIDTH; j++)
  68.         {
  69.             DRV_LCD_PutPixel(i, j, 0, 0, 255);
  70.         }
  71.     }
  72.  
  73.     DRV_LCD_Puts("Hello", 20, 30, foreground, background, TRUE);
  74.     DRV_LCD_Puts("Hello", 20, 60, foreground, background, FALSE);  
  75. }
  76.  
  77. void TouchScreenCallBack(TouchResult* touchData)
  78. {
  79.     printf("touched X=%3d Y=%3d\n", touchData->X, touchData->Y);       
  80.    
  81. }
  82.  
  83. void BoardInit()
  84. {
  85.     timer_software_handler_t handler;
  86.    
  87.     TIMER_SOFTWARE_init_system();
  88.    
  89.    
  90.     DRV_SDRAM_Init();
  91.    
  92.     initRetargetDebugSystem();
  93.     DRV_LCD_Init();
  94.     DRV_LCD_ClrScr();
  95.     DRV_LCD_PowerOn(); 
  96.    
  97.     DRV_TOUCHSCREEN_Init();
  98.     DRV_TOUCHSCREEN_SetTouchCallback(TouchScreenCallBack);
  99.     DRV_LED_Init();
  100.     printf ("Hello\n");
  101.    
  102.     handler = TIMER_SOFTWARE_request_timer();
  103.     TIMER_SOFTWARE_configure_timer(handler, MODE_1, 100, 1);
  104.     TIMER_SOFTWARE_set_callback(handler, timer_callback_1);
  105.     TIMER_SOFTWARE_start_timer(handler);
  106. }
  107.  
  108. int main(void)
  109. {
  110.     uint32_t rssi_value_asu;
  111.     uint32_t rssi_value_dbmw;
  112.    
  113.     uint8_t ch;
  114.     BoardInit();
  115.     testLCD();
  116.    
  117.     DRV_UART_Configure(UART_3, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
  118.     DRV_UART_Configure(UART_2, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
  119.    
  120.     while(1)
  121.     {
  122.         DRV_LED_Toggle(LED_4);
  123.        
  124.     }
  125.     /*
  126.     while(1)
  127.     {
  128.         DRV_UART_SendByte(UART_3, 'A');
  129.     //  TIMER_SOFTWARE_Wait(1000);
  130.     }
  131.     */
  132.     /*
  133.     while(1)
  134.     {
  135.         if (DRV_UART_ReadByte(UART_3, &ch) == OK)
  136.         {
  137.             DRV_UART_SendByte(UART_3, ch);
  138.         }      
  139.     }
  140. */
  141.      while (1)
  142.      {
  143.          if (TIMER_SOFTWARE_interrupt_pending(my_timer_handler))
  144.          {
  145.                 ExecuteCommand(at_command_csq);
  146.          if (CommandResponseValid())
  147.          {
  148.                 rssi_value_asu = ExtractData(&at);
  149.                 rssi_value_dbmw = ConvertAsuToDbmw(rssi_value_asu);
  150.                 printf("Power of signal is %d - %d.\n",rssi_value_asu, rssi_value_dbmw);
  151.          }
  152.                 TIMER_SOFTWARE_clear_interrupt(my_timer_handler);
  153.          }
  154.      }
  155.    
  156.     while(1)
  157.     {
  158.         if (DRV_UART_ReadByte(UART_0, &ch) == OK)
  159.         {
  160.             DRV_UART_SendByte(UART_3, ch);
  161.         }
  162.         if (DRV_UART_ReadByte(UART_3, &ch) == OK)
  163.         {
  164.             DRV_UART_SendByte(UART_0, ch);
  165.         }
  166.         if (DRV_UART_ReadByte(UART_2, &ch) == OK)
  167.         {
  168.             DRV_UART_SendByte(UART_0, ch);
  169.         }
  170.     }
  171.    
  172.     while(1)
  173.     {
  174.         DRV_UART_Process();
  175.         DRV_TOUCHSCREEN_Process();
  176.     }
  177.    
  178.     return 0;
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement