|
#define Speeker_Out PB15 //蜂鸣器信号输出数字引脚38
#define DCREALY_ON PB14 //输出信号继电器低电平打开 高电平时断开继电器
#define DCMotorer_EN PA7 //L6203-PIN(11) ENABLE 高电平有效
#define L6203_IN1 PB0 //L6203-PIN(5) IN1
#define L6203_IN2 PA6 //L6203-PIN(7) IN2
#define BOARD_LED_PIN PC13 //定义板载LED(呼吸灯,运行中信号)为数字引脚
//全局变量定义==========================================================
//RTClock rt (RTCSEL_LSE); // 初始化内部时钟,使用 LSE should be 32768 Hz.
char s[128];
//tm_t mtt;
int Led_Cnt=0;
bool APPstatus=false;
//以上为全局变量定义=====================================================
void App_LED() {
Led_Cnt++;
if(Led_Cnt>=50){
digitalWrite(BOARD_LED_PIN, !digitalRead(BOARD_LED_PIN));
Led_Cnt=0;
}
//digitalWrite(L6203_IN1, !digitalRead(L6203_IN1));
}
void Start_DC_Motor(bool CCW_CC) { //按 CCW_CC=LOW or HIGH 方向启动直流马达
digitalWrite(DCREALY_ON, LOW); //高电平时中断对电机的能量供应
delay(500);
digitalWrite(DCMotorer_EN, HIGH); //L6230 Pin-11
if(CCW_CC)
{ analogWrite(L6203_IN1, 0); //L6230 Pin-7
analogWrite(L6203_IN2, 200); //L6230 Pin-5
} else
{
analogWrite(L6203_IN1, 255); //L6230 Pin-7
analogWrite(L6203_IN2, 0); //L6230 Pin-5
}
}
void Stop_DC_Motor() { //停止直流马达
analogWrite(L6203_IN1, 0);
analogWrite(L6203_IN2, 0);
digitalWrite(DCMotorer_EN, LOW);
delay(500);
digitalWrite(DCREALY_ON, HIGH); //高电平时中断对电机的能量供应
digitalWrite(Speeker_Out, HIGH);
delay(200);
digitalWrite(Speeker_Out, LOW);
}
void setup() {
// put your setup code here, to run once:
pinMode(DCREALY_ON, OUTPUT); //PB14->DC REALY ON/OFF
pinMode(L6203_IN1, PWM); //PA5->L6203 PIN5(IN1)
pinMode(L6203_IN2, PWM); //PA6->L6203 PIN7(IN2)
pinMode(DCMotorer_EN, OUTPUT); //PA7->L6203 PIN11(EN) 使用PWM信号,控制马达速度
pinMode(BOARD_LED_PIN, OUTPUT); //PB14->DC REALY ON/OFF
pinMode(Speeker_Out, OUTPUT); //SPEEK
digitalWrite(Speeker_Out, HIGH);
delay(200);
digitalWrite(Speeker_Out, LOW);
Start_DC_Motor(true);
}
void loop() {
// put your main code here, to run repeatedly:
} |
|