|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
#include "led.h"
#include "key.h"
#include "lcd1602.h"
#include "fan.h"
#include "adc.h"
#include "ntc.h"
//#include "motor.h"
//************************************************************************
//#define OVER_MENU 10 //定义一个数,判断这个数是否需要退出菜单设置
//vu8 auto_return=0;
/**********************
* 目录结构体定义 *
**********************/
/*
struct MenuItem
{
unsigned char MenuCount; //当前层节点数
unsigned char *DisplayString; //菜单标题
void (*Subs)(); //节点函数
struct MenuItem *ChildrenMenus; //子节点
struct MenuItem *ParentMenus; //父节点
};
/***********************
* 调用子函数区 *
********************** */
/*
void NullSubs(void)
{
}
void MotorSetPWM(void)
{
//不分频。PWM频率=72000000/900=80Khz
//delay_ms(10);
TIM_SetCompare2(TIM4,100);
}
/*********************
//------------------------------------------------------------------------------
/***********************
* 结构体区 *
***********************/
//----------------------以下为例子,请根据实际情况修改---------------------------
/*
struct MenuItem TimeMenu[4];
struct MenuItem UvlampMenu[4];
struct MenuItem UvfanMenu[4];
struct MenuItem MotorMenu[5];
struct MenuItem MainMenu[5];
struct MenuItem TimeMenu[4]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{4, "1.Time Set", NullSubs, Null, MainMenu},
{4, "2.OFF", NullSubs, Null, MainMenu},
{4, "3.ON", NullSubs, Null, MainMenu},
{4, "4.Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem UvlampMenu[4]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{4, "1.UVlamp Set", NullSubs, Null, MainMenu},
{4, "2.OFF", UVlampSetOFF, Null, MainMenu},
{4, "3.ON", UVlampSetON, Null, MainMenu},
{4, "4.Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem UvfanMenu[4]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{4, "1.UVfan Set" , NullSubs, Null, MainMenu},
{4, "2.OFF", UVfanSetOFF, Null, MainMenu},
{4, "3.ON", UVfanSetON, Null, MainMenu},
{4, "4.Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem MotorMenu[5]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{5, "1.Motor Set", NullSubs, Null, MainMenu},
{5, "2.Turnleft", MotorSetTurnleft, Null, MainMenu},
{5, "2.TurnRight", MotorSetTurnRight, Null, MainMenu},
{5, "4.OFF", MotorSetOFF, Null, MainMenu},
{5, "5.Back", NullSubs, MainMenu, MainMenu},
};
struct MenuItem MainMenu[5]=
{ //MenuCount DisplayString Subs ChildrenMenus ParentMenus
{5, "1.Time Set" , NullSubs, TimeMenu, Null},
{5, "2.UVlamp Set", NullSubs, UvlampMenu, Null},
{5, "3.UVfan Set", NullSubs, UvfanMenu, Null},
{5, "4.Motor Set", NullSubs, MotorMenu, Null},
{5, "5.Back", NullSubs, MainMenu, MainMenu},
};
//------------------------------------------------------------------------------
/***********************
* 全局变量声明区 *
***********************/
/*
struct MenuItem (*MenuPoint) = MainMenu; //结构体指针,指向结构体后由内部函数指针指向功能函数
vu8 DisplayStart = 0; //显示时的第一个菜单项
vu8 UserChoose = 0; //用户所选菜单项
u8 DisplayPoint = 0; //显示指针
u8 MaxItems; //同级最大菜单数
vu8 ShowCount=2; //同屏显示菜单数
/***********************
*显示函数区 *
***********************/
/*
void ShowMenu(void)
{
u8 n;
MaxItems = MenuPoint[0].MenuCount;//定义最大同级菜单
DisplayPoint = DisplayStart;
for(n=0;DisplayPoint<MaxItems&&n<ShowCount;n++)
{
if(DisplayPoint==UserChoose)
LCD1602_Show_Str(0,n,"->");
LCD1602_Show_Str(2,n,MenuPoint[DisplayPoint++].DisplayString);
}
}
/***********************************************************************************/
// KeyRunScan();
// UpdateDisplay();
// PtcRun();
// FanRun();
// Motor_Init();
//uart_init(115200);
//TIM4_PWM_Init(899000,0); //不分频。PWM频率=72000000/900=8Khz
//TIM_SetCompare2(TIM4,100);
//MotorSetTurnLeft();
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
void ERROR_CH(void)
{
u8 temp_N,temp_F=0;
temp_N=Get_Adc_Average(ADC_Channel_8,30);
if (temp_N>5000)
{
LCD1602_ClearScreen();
delay_ms(10);
LCD1602_Show_Str(0, 0, "SYSTEM STOP");
LCD1602_Show_Str(1, 0, "ERROR CODE:NTC");
}
temp_N=0;
while(1)
{
Ledred_pro(10);
}
// 可以增加风扇自检测试
}
int main(void)
{
u32 adcx;
u16 adcx_v;
u16 adc_value_16;
float vx;
u8 adcx1[2] ={ 0,0};
u8 adcx2[3] ={ 0,0,0};
u8 adc_vcc_1[3] ={0,0,0};
// u8 adc_vcc_2[2] ={0,0};
u16 led0pwmval=0;
delay_init();
LED_Init();
KEY_Init();
FAN_Init();
Adc_Init();
LCD1602_GPIO_Init();
LCD1602_Init();
LCD1602_ClearScreen();
LCD1602_Show_Str(0, 0, "Temperature:");
Setzi();
Displayonechar(5,1,0x00);
//LCD1602_Show_Str(0, 1, "Temperature:");
delay_ms(100);
while(1)
{
//ERROR_CH();
adcx_v = Read_NTC();
adc_vcc_1[0] =(adcx_v/100)+0x30; //把得到的值放到数组里面;
adc_vcc_1[1] =(adcx_v%100/10)+0x30;
adc_vcc_1[2] =(adcx_v%10)+0x30;
//LCD1602_ClearScreen(); // 显示ADC的值 0~4096;
LCD1602_Show_Str(0, 0, "Temperature:");
LCD1602_Show_Str(2, 1, adc_vcc_1); //第二行空两个字符再显示,
Setzi();
Displayonechar(5,1,0x00); //显示摄示度
// void KeyRunScan();
// void UpdateDisplay();
// void PtcRun();
// void LedRun();
// void FanRun();
/********显示NTC电压值********Dean-02-27*******
adc_value_16 = adcx_v*326/4096;
adcx1[0] =(adc_value_16/1000)+0x30; //把得到的值放到数组里面;
adcx1[1] =(adc_value_16%1000/100)+0x30;
adcx2[0] =(adc_value_16%100/10)+0x30;
adcx2[1] =(adc_value_16%10)+0x30;
// 显示NTC电压值
LCD1602_Show_Str(2, 1, adcx1); //第二行空两个字符再显示,
LCD1602_Show_Str(4, 1,"."); //adcx1占用两个显示,所以前面空4格字符开始显示
LCD1602_Show_Str(5, 1,adcx2); //adcx1和字符“.”占用5个显示位,所以前面空5个字符开始显示
LCD1602_Show_Str(7, 1,"V"); //adcx2占两个显示位+前面5个,所以移动7位再显示字符
*************************************/
delay_ms(280);
}
送给有需要的人!
NTC.zip
(110 KB, 下载次数: 3)
|
|