發表文章

目前顯示的是 1月, 2019的文章

Leetcode-TwoSum

圖片
今天心血來潮了完成人生第一題leetcode /** * Note: The returned array must be malloced, assume caller calls free(). */ int* twoSum(int* nums, int numsSize, int target) { int *a= (int*)malloc(2*sizeof(int)); for(int i=0; i<numsSize; i++){ for(int j=i+1; j<numsSize; j++){ if(nums[i]+nums[j]==target&&i!=j){ a[0]=i; a[1]=j; //return a; } } } return a; } 詳細之後再補

危機處理-藍芽傳送字元(HC-05)

圖片
今天來補個用藍芽傳字元給M0的程式碼 使用的藍芽模組是HC-05(主從合一),之後有空再補上HC-05的設定 查了查資料發現藍牙傳輸的方式不會對傳輸內容做任何的手腳(應該說調變?)等效於一條RS-232傳輸線 所以關於藍牙與板子的溝通就是通過UART協定去寫 而NUC140關於UART的腳位如下 (擷取自樹德科技大學資訊工程系 吳鴻志副教授之PPT) 我測試用的程式碼如下: #include <stdio.h> #include "NUC1xx.h" #include "Driver\DrvSYS.h" #include "Driver\DrvGPIO.h" #include "Driver\DrvSPI.h" #include "LCD_Driver.h" #include "ScanKey.h" #include "Seven_Segment.h" #include "LCD_Driver_Extend.h" #include "Driver/DrvUART.h" #define DATASIZE 1 uint8_t mode; extern unsigned char Ascii[]; unsigned char TEXT1[16]="Keypad = "; unsigned char LCD_Point[64]; unsigned char DisplayBuf[8*128]; int main(void) { UNLOCKREG(); DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1); SysTimerDelay(5000); /* HCLK clock source. 0: external 12MHz; 4:internal 22MHz RC oscillator */ DrvSYS_SelectHCLKSource(0); LOCKREG(); Initial_pannel(); //call initial pannel f