久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3904|回復: 2
收起左側

mcp23017程序包:樹莓PI+STM32F429+arduino

[復制鏈接]
ID:473376 發表于 2019-1-27 15:59 | 顯示全部樓層 |閱讀模式
可以自己,只有程序包哦
0.png

單片機源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "main.h"
  3. #include "stm32f4xx_hal.h"
  4. #include "i2c.h"
  5. #include "usart.h"
  6. #include "gpio.h"

  7. /* USER CODE BEGIN Includes */
  8. #include "MCP23017.h"
  9. /* USER CODE END Includes */

  10. /* Private variables ---------------------------------------------------------*/

  11. /* USER CODE BEGIN PV */
  12. /* Private variables ---------------------------------------------------------*/

  13. /* USER CODE END PV */

  14. /* Private function prototypes -----------------------------------------------*/
  15. void SystemClock_Config(void);

  16. /* USER CODE BEGIN PFP */
  17. /* Private function prototypes -----------------------------------------------*/

  18. /* USER CODE END PFP */

  19. /* USER CODE BEGIN 0 */

  20. /* USER CODE END 0 */

  21. /**
  22.   * @brief  The application entry point.
  23.   *
  24.   * @retval None
  25.   */
  26. int main(void)
  27. {
  28.   /* USER CODE BEGIN 1 */

  29.   /* USER CODE END 1 */

  30.   /* MCU Configuration----------------------------------------------------------*/

  31.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  32.   HAL_Init();

  33.   /* USER CODE BEGIN Init */
  34.   //the param can be 0 to 7,don't solder A0,A1,A2 result in default address 0x27,param is 7
  35.   //Addr(BIN)    Addr(hex)   param
  36.   //010 0111      0x27         7
  37.   //010 0110      0x26         6
  38.   //010 0101      0x25         5
  39.   //010 0100      0x24         4
  40.   //010 0011      0x23         3
  41.   //010 0010      0x22         2
  42.   //010 0001      0x21         1
  43.   //010 0000      0x20         0
  44.   begin(7);
  45.   /* USER CODE END Init */

  46.   /* Configure the system clock */
  47.   SystemClock_Config();

  48.   /* USER CODE BEGIN SysInit */

  49.   /* USER CODE END SysInit */

  50.   /* Initialize all configured peripherals */
  51.   MX_GPIO_Init();
  52.   MX_USART1_UART_Init();
  53.   MX_I2C1_Init();
  54.   /* USER CODE BEGIN 2 */
  55.   //Change this Macro definition to different demo test
  56.   #define debug 0
  57.   #define outputTest 0
  58.   #define inputTest 0
  59.   //For interrupt test, you need Connect PA7 and PB7 to a button(when the button pressed,it connect to GND)
  60.   #define interruptTest 1
  61.   /* USER CODE END 2 */

  62.   /* Infinite loop */
  63.   /* USER CODE BEGIN WHILE */
  64.     while (1)
  65.     {

  66.   /* USER CODE END WHILE */

  67.   /* USER CODE BEGIN 3 */

  68.         HAL_Delay(500);

  69.         #if(debug)
  70.         for(int addr = 0; addr< 22; addr++)
  71.         {
  72.           printf("addr:0x%02x,value:0x%02x\r\n",addr,readRegister(addr));
  73.         }
  74.         printf("------------------------------------------\r\n");
  75.         #endif

  76.         #if(outputTest)
  77.         for(int i = 0; i<16; i++)
  78.         {
  79.             pinMode(i, 0);
  80.         }

  81.         for(int i = 0; i<16; i++)
  82.         {
  83.             digitalWrite(i,1);
  84.         }

  85.         HAL_Delay(500);

  86.         for(int i = 0; i<16; i++)
  87.         {
  88.             digitalWrite(i,0);
  89.         }
  90.         #endif

  91.         #if(inputTest)
  92.         //Pin0 Output
  93.         pinMode(0, 0);
  94.         //Pin1 Input
  95.         pinMode(1, 1);
  96.         //Pin1 Pullup
  97.         pullUp(1,1);
  98.         digitalWrite(0, digitalRead(1));
  99.         #endif

  100.         #if(interruptTest)
  101.         //mirroring, don't openDrain, INT output pin will be low when interrupt occur
  102.         setupInterrupts(1,0,0);

  103.         //input
  104.         pinMode(7,1);
  105.         //pullup
  106.         pullUp(7,1);
  107.         //1 means compare against given value,and 1 means when differ from 1 occur the interrupt
  108.         setupInterruptPin(7,1);

  109.         //input
  110.         pinMode(15,1);
  111.         //pullup
  112.         pullUp(15,1);
  113.         //1 means compare against given value,and 1 means when differ from 1 occur the interrupt
  114.         setupInterruptPin(15,1);
  115.         #endif
  116.     }
  117.   /* USER CODE END 3 */

  118. }

  119. /**
  120.   * @brief System Clock Configuration
  121.   * @retval None
  122.   */
  123. void SystemClock_Config(void)
  124. {

  125.   RCC_OscInitTypeDef RCC_OscInitStruct;
  126.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  127.     /**Configure the main internal regulator output voltage
  128.     */
  129.   __HAL_RCC_PWR_CLK_ENABLE();

  130.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  131.     /**Initializes the CPU, AHB and APB busses clocks
  132.     */
  133.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  134.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  135.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  136.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  137.   RCC_OscInitStruct.PLL.PLLM = 4;
  138.   RCC_OscInitStruct.PLL.PLLN = 168;
  139.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  140.   RCC_OscInitStruct.PLL.PLLQ = 4;
  141.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  142.   {
  143.     _Error_Handler(__FILE__, __LINE__);
  144.   }

  145.     /**Initializes the CPU, AHB and APB busses clocks
  146.     */
  147.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  148.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  149.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  150.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  151.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  152.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  153.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  154.   {
  155.     _Error_Handler(__FILE__, __LINE__);
  156.   }

  157.     /**Configure the Systick interrupt time
  158.     */
  159.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  160.     /**Configure the Systick
  161.     */
  162.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  163.   /* SysTick_IRQn interrupt configuration */
  164.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  165. }

  166. /* USER CODE BEGIN 4 */
  167. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  168. {
  169.   if(GPIO_Pin == GPIO_PIN_0)
  170.   {
  171.       printf("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\r\n");
  172.       printf("the key has been pressed!!!\r\n");
  173.       printf("the last interrupt Pin is: %d\r\n",getLastInterruptPin());
  174.       printf("the last interrupt value is: %d\r\n",getLastInterruptPinValue());
  175.       printf("_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\r\n");
  176.   }  
  177. }
  178. /* USER CODE END 4 */

  179. /**
  180.   * @brief  This function is executed in case of error occurrence.
  181.   * @param  file: The file name as string.
  182.   * @param  line: The line in file as a number.
  183.   * @retval None
  184.   */
  185. void _Error_Handler(char *file, int line)
  186. {
  187.   /* USER CODE BEGIN Error_Handler_Debug */
  188.   /* User can add his own implementation to report the HAL error return state */
  189.   while(1)
  190.   {
  191.   }
  192. ……………………

  193. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
MCP23017-IO-Expansion-Board-Demo-Code.7z (3.85 MB, 下載次數: 65)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:529070 發表于 2019-5-6 22:42 | 顯示全部樓層
謝謝分享。。
回復

使用道具 舉報

ID:364261 發表于 2020-3-4 09:38 | 顯示全部樓層
謝謝樓主!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久精品电影 | 日韩成人久久 | 色欧美综合 | caoporn国产精品免费公开 | www日| 精品美女在线观看 | 国产激情视频 | 激情av在线 | 91久久国产综合久久91精品网站 | 免费观看成人性生生活片 | 精品国产一二三区 | 91视频在线观看免费 | av网站免费观看 | 伊人春色在线观看 | 一区二区三区在线看 | 亚洲欧美一区二区三区国产精品 | 成人精品鲁一区一区二区 | 亚洲国产中文在线 | 黄色在线观看网址 | 二区在线观看 | 久久一二区| 午夜视频精品 | 亚洲最新在线视频 | 亚洲成人一区 | 国产成人亚洲精品 | 97超碰在线播放 | 亚洲视频在线观看 | 午夜精品一区二区三区在线观看 | 草b视频| 国产a爽一区二区久久久 | 亚洲欧美一区二区三区1000 | 99re在线视频观看 | 久久久久亚洲精品国产 | 日本天天操 | 亚洲成人av | 久久尤物免费一区二区三区 | 国产精品综合网 | 亚洲欧美日韩在线一区二区 | 欧美一级欧美三级在线观看 | 久久精品国产99国产精品 | 亚洲成人一区 |