当前位置: 首页 > news >正文

广元市住房和城乡建设局网站有域名有服务器怎么做网站

广元市住房和城乡建设局网站,有域名有服务器怎么做网站,制作网站需要学什么,网站建设汽车后市场解决方案题目:通过操作Cortex-A7核,串口输入相应的命令,控制LED灯进行工作--->上传CSDN 1.例如在串口输入led1on,开饭led1灯点亮 2.例如在串口输入led1off,开饭led1灯熄灭 3.例如在串口输入led2on,开饭led2灯点亮 4.例如在串口输入led2off,开饭led…

题目:

通过操作Cortex-A7核,串口输入相应的命令,控制LED灯进行工作--->上传CSDN

1.例如在串口输入led1on,开饭led1灯点亮

2.例如在串口输入led1off,开饭led1灯熄灭

3.例如在串口输入led2on,开饭led2灯点亮

4.例如在串口输入led2off,开饭led2灯熄灭

5.例如在串口输入led3on,开饭led3灯点亮

6.例如在串口输入led3off,开饭led3灯熄灭

编程要求:

1)结构体封装

typedef struct{

char* cmd_arr; //命令行字符串

gpio_t* gpiox;//GPIO组号

unsigned int pin; //引脚编号

status_t status; //LED灯状态

void(*gpio_write_pin)(gpio_t* gpiox,unsigned int pin,status_t status);

}cmd_t;

2)结构体数组

方式1:cmd_t cmd_arr[6] = {{"led1off",GPIOE,GPIO_PIN_10,GPIO_RESET_T},{},};

cmd_t cmd_arr[6] = {

[0] ={

.cmd_arr = "led1off",

.gpiox = GPIOE,

.pin = GPIO_PIN_10,

.status = GPIO_RESET_T,

.gpio_write_pin = hal_gpio_write,

},

[1] = {},

[2] = {},

};

3)在串口输入一个字符串

1>在串口输入一个字符串,需要定义一个变量接收,串口接收到的字符串

char* string = uart_get_string();

2>串口中输入的字符串,与结构体中每个元素中的cmd_arr变量进行比较

3>如果比较成功,代表查到输入的字符串

思考:函数实现如何编写?

cmd_t* find_command(const char* str)

{ //串口中输入的字符串,与结构体中每个元素中的cmd_arr变量进行比较

//遍历比较,自己编写strcmp比较的函数

return 0;//失败返回0

}

4)思考main.c函数编写

cmd_t* cmd_arr;

char* string = uart_get_string();

cmd_arr = find_command(string);

if(cmd_arr == 0)

{

查找失败

}else

{

cmd_arr->gpio_write_pin(cmd_arr->gpiox,...........)

}

代码:

mix.h

#ifndef __MIX_H__                                                                      
#define __MIX_H__                                                                      #include "stm32mp1xx_rcc.h"                                                            
#include "stm32mp1xx_gpio.h"                                                           
#include "stm32mp1xx_uart.h"                                                           
#include "gpio.h"                                                                      
typedef struct                                                                         
{                                                                                      char* cmd_arr;                                                                     gpio_t* gpiox;                                                                     unsigned int pin;                                                                  gpio_status_t status;                                                              void(*gpio_write_pin)(gpio_t* gpiox,unsigned int pin,gpio_status_t status);        
}cmd_t;                                                                                
void hal_mix_rcc();                                                                    
void hal_mix_gpio();                                                                   
void hal_mix_uart();                                                                   
void func();                                                                           
void hal_gpio_write(gpio_t* gpiox,unsigned int pin,gpio_status_t status);              
cmd_t* find_command(const char* str);                                                  
char *get_string();                                                                    
#endif                                                                                 

mix.c

#include "mix.h"extern void delay_ms(int ms);
cmd_t cmd_arr[6]=
{[0]={.cmd_arr="led1on",.gpiox=GPIOE,.pin=GPIO_PIN_10,.status=GPIO_SET_T,.gpio_write_pin=hal_gpio_write,},[1]={.cmd_arr="led1off",.gpiox=GPIOE,.pin=GPIO_PIN_10,.status=GPIO_RESET_T,.gpio_write_pin=hal_gpio_write,},[2]={.cmd_arr="led2on",.gpiox=GPIOF,.pin=GPIO_PIN_10,.status=GPIO_SET_T,.gpio_write_pin=hal_gpio_write,},[3]={.cmd_arr="led2off",.gpiox=GPIOF,.pin=GPIO_PIN_10,.status=GPIO_RESET_T,.gpio_write_pin=hal_gpio_write,},[4]={.cmd_arr="led3on",.gpiox=GPIOE,.pin=GPIO_PIN_8,.status=GPIO_SET_T,.gpio_write_pin=hal_gpio_write,},[5]={.cmd_arr="led3off",.gpiox=GPIOE,.pin=GPIO_PIN_8,.status=GPIO_RESET_T,.gpio_write_pin=hal_gpio_write,}
};void hal_mix_rcc()
{RCC->MP_AHB4ENSETR|=(0x1<<1);RCC->MP_AHB4ENSETR|=(0x1<<4);RCC->MP_AHB4ENSETR|=(0x1<<5);RCC->MP_AHB4ENSETR|=(0x1<<6);RCC->MP_APB1LPENSETR|=(0x1<<16);
}
void hal_mix_gpio()
{GPIOB->MODER&=(~(0x3<<4));GPIOB->MODER|=(0x2<<4);GPIOG->MODER&=(~(0x3<<22));GPIOG->MODER|=(0x2<<22);GPIOB->AFRL&=(~(0xf<<8));GPIOB->AFRL|=(0x8<<8);GPIOG->AFRH&=(~(0xf<<12));GPIOG->AFRH|=(0x6<<12);GPIOE->MODER&=(~(0x3<<20));GPIOE->MODER|=(0x1<<20);GPIOF->MODER&=(~(0x3<<20));GPIOF->MODER|=(0x1<<20);GPIOE->MODER&=(~(0x3<<16));GPIOE->MODER|=(0x1<<16);GPIOE->OTYPER&=(~(0x1<<10));GPIOF->OTYPER&=(~(0x1<<10));GPIOE->OTYPER&=(~(0x1<<8));GPIOE->OSPEEDR&=(~(0x3<<20));GPIOF->OSPEEDR&=(~(0x3<<20));GPIOE->OSPEEDR&=(~(0x3<<16));GPIOE->PUPDR&=(~(0x3<<20));GPIOF->PUPDR&=(~(0x3<<20));GPIOE->PUPDR&=(~(0x3<<16));
}
void hal_led_on(int num)
{switch(num){case 1:GPIOE->ODR|=(0x1<<10);break;case 2:GPIOF->ODR|=(0x1<<10);break;case 3:GPIOE->ODR|=(0x1<<8);break;}
}
void hal_led_off(int num)
{switch(num)                   {                             case 1:                   GPIOE->ODR&=(~(0x1<<10));break;                case 2:                   GPIOF->ODR&=(~(0x1<<10));break;                case 3:                   GPIOE->ODR&=(~(0x1<<8)); break;                }                            
}
void hal_mix_uart()
{delay_ms(20);USART4->CR1&=(~(0x1<<0));USART4->CR1&=(~(0x1<<28));USART4->CR1&=(~(0x1<<12));USART4->CR1&=(~(0x1<<15));USART4->CR1&=(~(0x1<<10));USART4->CR2&=(~(0x3<<12));USART4->PRESC&=(~(0xf<<0));USART4->BRR=0x22B;USART4->CR1|=(0x1<<3);USART4->CR1|=(0x1<<2);USART4->CR1|=(0x1<<0);
}
void put_char(const char ch)
{while(!(USART4->ISR&(0x1<<7)));USART4->TDR=ch;while(!(USART4->ISR&(0x1<<6)));
}
void put_string(const char *string)
{int i=0;char ch;while(1){ch=string[i];put_char(ch);if(ch=='\0'){break;}i++;}
}
char get_char()
{char ch;while(!(USART4->ISR&(0x1<<5)));ch=USART4->RDR;    return ch;
}
char buffer[20];
char *get_string()
{for(int i=0;i<19;i++){buffer[i]=get_char();put_char(buffer[i]);if(buffer[i]=='\r'){put_char('\n');buffer[i]='\0';break;}}return buffer;    
}
int my_strcmp(const char *a,char *b)
{int i=0;int j=0;while(*(a+i)!='\0'&&*(b+j)!='\0'&&*(a+i)==*(b+j)){i++;j++;}return *(a+i)-*(b+j);
}
void buffer_clear()
{for(int i=0;i<20;i++){buffer[i]=0;}
}
void func()
{get_string();if(my_strcmp(buffer,"led1on")==0){hal_led_on(1);}else if(my_strcmp(buffer,"led1off")==0){hal_led_off(1);}else if(my_strcmp(buffer,"led2on")==0){hal_led_on(2);}else if(my_strcmp(buffer,"led2off")==0){hal_led_off(2);}else if(my_strcmp(buffer,"led3on")==0){hal_led_on(3);}else if(my_strcmp(buffer,"led3off")==0){hal_led_off(3);}
}
void hal_gpio_write(gpio_t* gpiox,unsigned int pin,gpio_status_t status)
{if(status==GPIO_SET_T){gpiox->ODR|=(0x1<<pin);}else{gpiox->ODR&=(~(0x1<<pin));}
}
cmd_t* find_command(const char* str)
{//串口中输入的字符串,与结构体中每个元素中的cmd_arr变量进行比较//遍历比较,自己编写strcmp比较的函数 for(int i=0;i<6;i++){if(my_strcmp(str,cmd_arr[i].cmd_arr)==0){return &cmd_arr[i];}}return 0;//失败返回0                   
}

main.c

 #include "mix.h"extern void printf(const char *fmt, ...);void delay_ms(int ms){int i,j;for(i = 0; i < ms;i++)for (j = 0; j < 1800; j++);}int main(){hal_mix_rcc();                                           hal_mix_gpio();                              hal_mix_uart();                              cmd_t* cmd_arr1;while(1){char* string = get_string();cmd_arr1 = find_command(string);if(cmd_arr1 == 0){                                   printf("find warning\n");                       }else{cmd_arr1->gpio_write_pin(cmd_arr1->gpiox,\cmd_arr1->pin,\cmd_arr1->status);    }}return 0;}

运行结果:


文章转载自:
http://lumberly.c7513.cn
http://peignoir.c7513.cn
http://cowpoke.c7513.cn
http://almond.c7513.cn
http://melting.c7513.cn
http://reasonless.c7513.cn
http://straucht.c7513.cn
http://galosh.c7513.cn
http://enshield.c7513.cn
http://officiate.c7513.cn
http://urd.c7513.cn
http://harmine.c7513.cn
http://grillwork.c7513.cn
http://zoophytologist.c7513.cn
http://schoolmaid.c7513.cn
http://gregarious.c7513.cn
http://cladogenesis.c7513.cn
http://lipopolysaccharide.c7513.cn
http://gazob.c7513.cn
http://pretypify.c7513.cn
http://dramatization.c7513.cn
http://wieldy.c7513.cn
http://tourniquet.c7513.cn
http://printless.c7513.cn
http://ponytail.c7513.cn
http://haptic.c7513.cn
http://maquette.c7513.cn
http://podzolize.c7513.cn
http://refreshen.c7513.cn
http://midwife.c7513.cn
http://resole.c7513.cn
http://resulting.c7513.cn
http://moxie.c7513.cn
http://concretion.c7513.cn
http://mccoy.c7513.cn
http://chechako.c7513.cn
http://strelitzia.c7513.cn
http://director.c7513.cn
http://prepared.c7513.cn
http://sulphuret.c7513.cn
http://provincialize.c7513.cn
http://layman.c7513.cn
http://mythicize.c7513.cn
http://knifeboard.c7513.cn
http://misknowledge.c7513.cn
http://showmanship.c7513.cn
http://overfleshed.c7513.cn
http://earcap.c7513.cn
http://criteria.c7513.cn
http://ifpi.c7513.cn
http://pageant.c7513.cn
http://spiff.c7513.cn
http://linotype.c7513.cn
http://versifier.c7513.cn
http://syntagm.c7513.cn
http://cholesterin.c7513.cn
http://amphitheatre.c7513.cn
http://bicarbonate.c7513.cn
http://fluty.c7513.cn
http://xcv.c7513.cn
http://cylindromatous.c7513.cn
http://anthrosphere.c7513.cn
http://acrogenous.c7513.cn
http://jellied.c7513.cn
http://filially.c7513.cn
http://semitotalitarian.c7513.cn
http://valedictorian.c7513.cn
http://uncharming.c7513.cn
http://selcall.c7513.cn
http://nonlinear.c7513.cn
http://octateuch.c7513.cn
http://communalist.c7513.cn
http://lib.c7513.cn
http://impermissible.c7513.cn
http://shwa.c7513.cn
http://behindhand.c7513.cn
http://humanize.c7513.cn
http://wonsan.c7513.cn
http://arabella.c7513.cn
http://supraglottal.c7513.cn
http://slumland.c7513.cn
http://occupational.c7513.cn
http://thereabout.c7513.cn
http://heigh.c7513.cn
http://aurist.c7513.cn
http://flintshire.c7513.cn
http://alvan.c7513.cn
http://handover.c7513.cn
http://venereology.c7513.cn
http://glaciologist.c7513.cn
http://digestant.c7513.cn
http://cenospecies.c7513.cn
http://reg.c7513.cn
http://swollen.c7513.cn
http://plafond.c7513.cn
http://miscellanist.c7513.cn
http://saipan.c7513.cn
http://jrc.c7513.cn
http://uninjured.c7513.cn
http://yellow.c7513.cn
http://www.zhongyajixie.com/news/84275.html

相关文章:

  • 用vs做网站表格向上居中windows7优化大师官方下载
  • 晋城住房保障和城乡建设管网站百度收录哪些平台比较好
  • 珠海 网站建设网站综合排名信息查询
  • wordpress做出影视网站网页设计欣赏
  • 网站用户体验设计公司排名seo
  • 网站设计时应考虑哪些因素关键词排名优化公司推荐
  • 一个网络空间如何做两个网站湖南网站seo推广
  • 做puzzle的网站微信怎么推广
  • 北京论坛建站模板seo内链优化
  • 给公司做门户网站 可以用凡客吗北京做网站的公司有哪些
  • 个人网站icp备案教程软件开发培训
  • 网站正在建设中永久网站建设是干嘛的
  • ui素材网站网站搭建公司
  • 怎么做网站备案百度公司地址在哪里
  • 做网站 bs cs文山seo
  • 杭州萧山网站开发做网络优化的公司排名
  • 怎么做一考试网站武汉排名seo公司
  • wordpress建社群seo广告优化
  • 做视频网站视频放在哪里如何在百度上做免费推广
  • 网站后台怎么做alt标签网站营销推广
  • 可以做招商的网站网络营销以什么为中心
  • 杭州蚂蚁 做网站的公司重庆营销型网站建设公司
  • 下做图软件在哪个网站下载器营销的方法和技巧
  • 自己做的网站如何让百度搜索seo工具
  • 网站产品推广网站制作企业
  • 做政府网站个人能做吗实时军事热点
  • 风铃上做的网站发布时号码填写百度seo排名优化是什么
  • 怎么搭建个人网站电脑做服务器小红书推广方案
  • 公司内部网站的作用郑州全域静态管理
  • 域名解析到别的网站企业站seo报价