本帖最后由 4A32C007 于 2017-6-18 20:35 编辑
各位前輩們好
想請教如何將下列兩支程式結合起來
LCD顯示風扇功能示意圖如下:
fan/Exhaust fan
1 FOR BLOW WIND
2 FOR PUMP WIND
3 FOR STOP
1,2,3分別為矩陣鍵盤的按鍵編號,控制馬達正轉(1)
馬達逆轉(2)
馬達停止(3)
兩支程式皆能獨立執行,但結合起來就會導致所有功能消失
經過幾次常識仍無果又因時間窘迫,因此決定請教各位前輩如何解決這個問題,請各位多多指教!
[LCD顯示風扇功能的程式碼]
//
// LCD: display Text on LCD
//
// EVB : Nu-LB-NUC140
// MCU : NUC140VE3CN (LQPF-100)
#include <stdio.h>
#include "NUC100Series.h"
#include "MCU_init.h"
#include "SYS_init.h"
#include "LCD.h"
int main(void)
{
SYS_Init();
init_LCD();
clear_LCD();
print_Line(0, "fan/Exhaust fan ");
print_Line(1, "1 FOR BLOW WIND ");
print_Line(2, "2 FOR PUMP WIND ");
print_Line(3, "3 FOR STOP ");
}
[風扇主程式]
//
// ADC_VR1 : using ADC7 to read Variable Resistor
// (on-board Nu-LB-NUC140)
//
// EVB : Nu-LB-NUC140
// MCU : NUC140VE3CN
//
// ADC7/PA7 : NUC140VE3CN LQFP100 pin78
#include <stdio.h>
#include "NUC100Series.h"
#include "MCU_init.h"
#include "SYS_init.h"
#include "Seven_Segment.h"
#include "LCD.h"
#include "Scankey.h"
uint32_t u32ADCvalue;
volatile uint8_t u8ADF;
volatile uint8_t ledState =0;
uint32_t count = 0;
void Forward() // 馬達正轉副程式
{PA12=0; PA13=1; }
void Backward() // 馬達逆轉副程式
{PA12=1; PA13=0; }
void Stop() // 馬達停止副程式
{PA12=0; PA13=0;}
void Display_7seg(uint16_t value)
{
uint8_t digit;
digit = value / 1000;
CloseSevenSegment();
ShowSevenSegment(3,digit);
CLK_SysTickDelay(5000);
value = value - digit * 1000;
digit = value / 100;
CloseSevenSegment();
ShowSevenSegment(2,digit);
CLK_SysTickDelay(5000);
value = value - digit * 100;
digit = value / 10;
CloseSevenSegment();
ShowSevenSegment(1,digit);
CLK_SysTickDelay(5000);
value = value - digit * 10;
digit = value;
CloseSevenSegment();
ShowSevenSegment(0,digit);
CLK_SysTickDelay(5000);
}
void ADC_IRQHandler(void)
{
uint32_t u32Flag;
// Get ADC conversion finish interrupt flag
u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT);
if(u32Flag & ADC_ADF_INT)
u8ADF = 1;
ADC_CLR_INT_FLAG(ADC, u32Flag);
}
void Init_ADC(void)
{
ADC_Open(ADC, ADC_INPUT_MODE, ADC_OPERATION_MODE, ADC_CHANNEL_MASK);
ADC_POWER_ON(ADC);
ADC_EnableInt(ADC, ADC_ADF_INT);
NVIC_EnableIRQ(ADC_IRQn);
}
//void LCD(void)
//{
//init_LCD();
//clear_LCD();
//}
void Init_GPIO(void) // 定義PA12(綠燈)與P13(藍燈)為輸出
{
GPIO_SetMode(PA, BIT0, GPIO_MODE_OUTPUT);
GPIO_SetMode(PA, BIT1, GPIO_MODE_OUTPUT);
GPIO_SetMode(PA, BIT12, GPIO_MODE_OUTPUT);
GPIO_SetMode(PA, BIT13, GPIO_MODE_OUTPUT);
}
int32_t main (void)
{
uint32_t value;
uint16_t i;
uint16_t j;
uint16_t k;
SYS_Init();
Init_ADC();
Init_GPIO();
//LCD();
OpenSevenSegment();
OpenKeyPad();
PA0=0; PA1=0;
u8ADF = 0;
while(1) {
Stop();
ADC_START_CONV(ADC);
while (u8ADF == 0);
value = ADC_GET_CONVERSION_DATA(ADC, 7);
Display_7seg(value); // 七段顯示器顯示VR值
i=ScanKey(); // 讀取按鍵值
if(i == 1){ //馬達正轉:風扇吹風
while(1){
// 讀取VR值(開始)
ADC_START_CONV(ADC);
while (u8ADF == 0);
value = ADC_GET_CONVERSION_DATA(ADC, 7);
// 讀取VR值,即value
//Display_7seg(value); // 七段顯示器顯示VR值(有成功顯示)
Forward(); //正轉副程式PA12=0 / PA13=1 (定速:成功)
//PWM_ConfigOutputChannel(PWM0, PWM_CH1, 100, 10); (變速:失敗)
// PWM_ConfigOutputChannel(PWM0, PWM_CH0, 125000, 100);
CLK_SysTickDelay(5000000);
i=ScanKey();
if(i==3||i==2){break;}
}
}
if(i == 2){ //馬達反轉:風扇吹風
while(1){
Backward(); //逆轉副程式(定速:成功)
CLK_SysTickDelay(5000000);
i=ScanKey();
if(i==3||i==1){break;}
}
}
}
}
|