验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
语言: C/C++
分类: 嵌入式开发
最后更新于 2018-12-09 10:36
片段 1 片段 2 片段 3 片段 4 片段 5 片段 6
main.c
原始数据 复制代码
#include "includes.h"
#include "light.h"
#include "beep.h"
int main()
{
u8 flag=1;
uint_32 counter;
light_init(light_port,light_red,light_off);
light_init(light_port,light_green,light_off);
light_init(light_port,light_blue,light_off);
beep_init(beep_port,beep_pin,beep_off);
while(1)
{
counter++;
if(counter>=counter_max)
{
counter=0;
switch(flag)
{
case 1:
light_change(light_port,light_red);
light_control(light_port,light_green,light_off);
light_control(light_port,light_blue,light_off);
beep_control(beep_port,beep_pin,beep_on);
flag=2;
break;
case 2:
light_change(light_port,light_green);
light_control(light_port,light_red,light_off);
light_control(light_port,light_blue,light_off);
beep_change(beep_port,beep_pin);
flag=3;
break;
case 3:
light_change(light_port,light_blue);
light_control(light_port,light_red,light_off);
light_control(light_port,light_green,light_off);
beep_change(beep_port,beep_pin);
flag=1;
break;
default:
flag=1;
break;
}
}
}
}
includes.h
原始数据 复制代码
#ifndef includes_h
#define includes_h
#include "common.h"
#include "gpio.h"
#include "light.h"
#define counter_max 1500000u
#endif
light.c
原始数据 复制代码
#include "light.h"
void light_init(u8 port,u8 pin,u8 state)
{
gpio_init(port,pin,1,state);
}
void light_control(u8 port,u8 pin,u8 state)
{
gpio_set(port,pin,state);
}
void light_change(u8 port,u8 pin)
{
gpio_reverse(port,pin);
}
light.h
原始数据 复制代码
#ifndef light_h
#define light_h
#include "common.h"
#include "gpio.h"
#define light_port PORTB
#define light_red 19
#define light_green 18
#define light_blue 9
#define light_on 0
#define light_off 1
#define u8 uint_8
void light_init(u8 port,u8 pin,u8 state);
void light_control(u8 port,u8 pin,u8 state);
void light_change(u8 port,u8 pin);
#endif
beep.h
原始数据 复制代码
/*
* beep.h
*
* Created on: Sep 26, 2018
* Author: Administrator
*/
#ifndef BEEP_H_
#define BEEP_H_
#include "common.h"
#include "gpio.h"
#define u8 uint_8
#define beep_port PORTC
#define beep_pin 3
#define beep_on 1
#define beep_off 0
#define output 1
void beep_init(u8 port,u8 pin,u8 state);
void beep_control(u8 port,u8 pin,u8 state);
void beep_change(u8 port,u8 pin);
#endif /* BEEP_H_ */
beep.c
原始数据 复制代码
/*
* beep.c
*
* Created on: Sep 26, 2018
* Author: Administrator
*/
#include "beep.h"
void beep_init(u8 port,u8 pin,u8 state)
{
gpio_init(port,pin,output,state);
}
void beep_control(u8 port,u8 pin,u8 state)
{
gpio_set(port,pin,state);
}
void beep_change(u8 port,u8 pin)
{
gpio_reverse(port,pin);
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助