真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

GPIOtoLEDC語(yǔ)言之點(diǎn)燈之再封裝-創(chuàng)新互聯(lián)

gpio.h

新河ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書(shū)合作)期待與您的合作!
1 #ifndef __GPIO_H__                                                                 
  2 #define __GPIO_H__                                                                 
  3                                                                                    
  4                                                                                    
  5 #define RCC_MP_AHB4ENSETR (*(volatile unsigned int*)0x50000A28)//volatile 修飾     
  6 #define GPIOE ((gpio_config_t*)0x50006000)//做成指針?lè)奖愫瘮?shù)傳遞參數(shù)               
  7 #define GPIOF ((gpio_config_t*)0x50007000)                                         
  8                                                                                    
  9 #define GPIO_PIN_0 0                                                               
 10 #define GPIO_PIN_1 1                                                               
 11 #define GPIO_PIN_2 2                                                               
 12 #define GPIO_PIN_3 3                                                               
 13 #define GPIO_PIN_4 4                                                               
 14 #define GPIO_PIN_5 5                                                               
 15 #define GPIO_PIN_6 6                                                               
 16 #define GPIO_PIN_7 7                                                               
 17 #define GPIO_PIN_8 8                                                               
 18 #define GPIO_PIN_9 9                                                               
 19 #define GPIO_PIN_10 10                                                             
 20 #define GPIO_PIN_11 11                                                             
 21 #define GPIO_PIN_12 12                                                             
 22 #define GPIO_PIN_13 13                                                             
 23 #define GPIO_PIN_14 14                                                             
 24 #define GPIO_PIN_15 15                                                             
 25                                                                                    
 26 typedef struct  //方便給具體的gpio寄存器修改數(shù)值,首先有                           
 27 //一個(gè)一組寄存器的首地址,把地址的轉(zhuǎn)成該形式后,解引用訪問(wèn)成員就是訪問(wèn)對(duì)應(yīng)寄存器    
 28 {                                                                                  
 29     volatile unsigned int moder;//volatile 修飾                                    
 30     volatile unsigned int otyper;                                                  
 31     volatile unsigned int ospeedr;                                                 
 32     volatile unsigned int pupdr;                                                   
 33     volatile unsigned int idr;                                                     
 34     volatile unsigned int odr;                                                     
 35 }gpio_config_t;                                                                    
 36                                                                                    
 37 //下面封裝枚舉方便函數(shù)傳參時(shí)理解參數(shù)                                               
 38 typedef enum                                                                       
 39 {                                                                                  
 40     GPIO_INPUT = 0,                                                                
 41     GPIO_OUTPUT,                                                                   
 42     GPIO_AF,                                                                       
 43     GPIO_ANALOG,                                                                   
 44 }gpio_mode;                                                                        
 45                                                                                    
 46 typedef enum                                                                       
 47 {                                                                                  
 48     GPIO_PP = 0,                                                                   
 49     GPIO_OD,                                                                       
 50 }gpio_output_type;                                                                 
 51                                                                                    
 52 typedef enum                                                                       
 53 {                                                                                  
 54     GPIO_LOW = 0,                                                                  
 55     GPIO_MEDIUM,                                                                   
 56     GPIO_HIGH,                                                                     
 57     GPIO_VERY_HIGH,                                                                
 58 }gpio_output_speed;                                                                
 59                                                                                    
 60 typedef enum                                                                       
 61 {                                                                                  
 62     GPIO_NO_PULL = 0,                                                              
 63     GPIO_PULL_UP,                                                                  
 64     GPIO_PULL_DOWN,                                                                
 65 }gpio_pupd;                                                                        
 66                                                                                    
 67 typedef enum                                                                       
 68 {                                                                                  
 69     GPIO_RESET = 0,                                                                
 70     GPIO_SET,                                                                      
 71 }gpio_state;                                                                       
 72                                                                                    
 73 typedef struct                                                                     
 74 {                                                                                  
 75     gpio_mode mode;                                                                
 76     gpio_output_type type;                                                         
 77     gpio_output_speed speed;                                                       
 78     gpio_pupd pupd;                                                                
 79 }gpio_init;                                                                        
 80 //1.需要初始化哪一組的GPIO端口,                                                   
 81 //2.具體哪一個(gè)引腳                                                                 
 82 //3.傳一些引腳要設(shè)置成的模式速度等等,可以封裝成結(jié)構(gòu)體,并傳指針                   
 83 void hal_gpio_init(gpio_config_t *GPIOx , unsigned int pin , gpio_init *init);     
 84                                                                                    
 85 //1.需要寫(xiě)入哪一組的GPIO端口                                                       
 86 //2.具體哪一個(gè)引腳                                                                 
 87 //3.需要寫(xiě)入的是什么數(shù)據(jù)                                                           
 88 void hal_gpio_write(gpio_config_t *GPIOx , unsigned int pin , gpio_state state);   
 89 #endif                                                                             
 90                                                                                   

gpio.c?

1 #include "../include/gpio.h"                                                           
  2                                                                                        
  3                                                                                        
  4 //1.需要初始化哪一組的GPIO端口,                                                       
  5 //2.具體哪一個(gè)引腳                                                                     
  6 //3.傳一些引腳要設(shè)置成的模式速度等等,可以封裝成結(jié)構(gòu)體,并傳指針                       
  7 void hal_gpio_init(gpio_config_t *GPIOx , unsigned int pin , gpio_init *init)          
  8 {                                                                                      
  9     GPIOx->moder &= ~(0x3<<(pin*2));                                                  
 10     GPIOx->moder |= (init->mode<<(pin*2));                                            
 11                                                                                        
 12     GPIOx->otyper &= ~(0x1<otyper |= (init->type<ospeedr &= ~(0x3<<(pin*2));                                                
 16     GPIOx->ospeedr |= (init->speed<<(pin*2));                                         
 17                                                                                        
 18     GPIOx->pupdr &= ~(0x3<<(pin*2));                                                  
 19     GPIOx->pupdr |= (init->pupd<<(pin*2));                                            
 20     return;                                                                            
 21 }                                                                                      
 22                                                                                        
 23 //1.需要寫(xiě)入哪一組的GPIO端口                                                           
 24 //2.具體哪一個(gè)引腳                                                                     
 25 //3.需要寫(xiě)入的是什么數(shù)據(jù)                                                               
 26 void hal_gpio_write(gpio_config_t *GPIOx , unsigned int pin , gpio_state state)        
 27 {                                                                                      
 28     if(state)                                                                          
 29     {                                                                                  
 30         GPIOx->odr |= (0x1<odr &= ~(0x1<

main.c

|  1 #include "./include/gpio.h"                                 
|  2                                                             
|  3 extern void printf(const char *fmt, ...);                   
|  4 void delay_ms(int ms)                                       
|  5 {                                                           
|  6     int i,j;                                                
|  7     for(i = 0; i< ms;i++)                                  
|  8         for (j = 0; j< 1800; j++);                         
|  9 }                                                           
| 10                                                             
| 11 void led_init()                                             
| 12 {                                                           
| 13     //GPIOE\F RCC enable                                    
| 14     RCC_MP_AHB4ENSETR |= (0X3<<4);                         
| 15     gpio_init init = {                                      
| 16         .mode = GPIO_OUTPUT,                                
| 17         .type = GPIO_PP,                                    
| 18         .speed = GPIO_LOW,                                  
| 19         .pupd = GPIO_NO_PULL,                               
| 20     };                                                      
| 21                                                             
| 22     hal_gpio_init(GPIOE , GPIO_PIN_10 , &init);             
| 23     hal_gpio_init(GPIOE , GPIO_PIN_8 , &init);              
| 24     hal_gpio_init(GPIOF , GPIO_PIN_10 , &init);             
| 25                                                             
| 26     return;                                                 
| 27 }                                                           
| 28                                                             
| 29 void led_disply()                                           
| 30 {                                                           
| 31     hal_gpio_write(GPIOE , GPIO_PIN_10 , GPIO_SET);         
| 32     delay_ms(100);                                          
| 33     hal_gpio_write(GPIOE , GPIO_PIN_10 , GPIO_RESET);       
| 34     delay_ms(100);
| 35                                                             
| 36     hal_gpio_write(GPIOF , GPIO_PIN_10 , GPIO_SET);         
| 37     delay_ms(100);                                          
| 38     hal_gpio_write(GPIOF, GPIO_PIN_10 , GPIO_RESET);        
| 39     delay_ms(100);                                          
| 40                                                             
| 41     hal_gpio_write(GPIOE , GPIO_PIN_8 , GPIO_SET);          
| 42     delay_ms(100);                                          
| 43     hal_gpio_write(GPIOE , GPIO_PIN_8 , GPIO_RESET);        
| 44     delay_ms(100);                                          
| 45                                                             
| 46     hal_gpio_write(GPIOF , GPIO_PIN_10 , GPIO_SET);         
| 47     delay_ms(100);                                          
| 48     hal_gpio_write(GPIOF, GPIO_PIN_10 , GPIO_RESET);        
| 49     delay_ms(100);                                          
| 50                                                             
| 51     return;                                                 
| 52 }                                                           
| 53                                                             
| 54                                                             
| 55 int main()                                                  
| 56 {                                                           
| 57     led_init();                                             
| 58                                                             
| 59     while(1)                                                
| 60         led_disply();                                       
| 61                                                             
| 62     return 0;                                               
| 63 }                                                           
|~                                                               
|~                                                              

現(xiàn)象

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧


名稱(chēng)欄目:GPIOtoLEDC語(yǔ)言之點(diǎn)燈之再封裝-創(chuàng)新互聯(lián)
URL標(biāo)題:http://weahome.cn/article/dohhgp.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部