fix:修复调光时间BUG
解决调光时间一样的情况下,调光亮与调光灭的实际调光时间不一致问题
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Objects/*.obj
|
||||
71
GPIO.c
Normal file
71
GPIO.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "GPIO.h"
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: u8 GPIO_Inilize(u8 GPIO, GPIO_InitTypeDef *GPIOx)
|
||||
// <20><><EFBFBD><EFBFBD>: <20><>ʼ<EFBFBD><CABC>IO<49><4F>.
|
||||
// <20><><EFBFBD><EFBFBD>: GPIOx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>timer.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0, <20>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1,<2C><><EFBFBD><EFBFBD>2.
|
||||
// <20>汾: V1.0, 2012-10-22
|
||||
//========================================================================
|
||||
u8 GPIO_Inilize(u8 GPIO, GPIO_InitTypeDef *GPIOx)
|
||||
{
|
||||
if(GPIO > GPIO_P7) return 1; //<2F>ղ<EFBFBD><D5B2><EFBFBD>
|
||||
if(GPIOx->Mode > GPIO_OUT_PP) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
if(GPIO == GPIO_P0)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P0M1 &= ~GPIOx->Pin, P0M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P0M1 |= GPIOx->Pin, P0M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P0M1 |= GPIOx->Pin, P0M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P0M1 &= ~GPIOx->Pin, P0M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P1)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P1M1 &= ~GPIOx->Pin, P1M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P1M1 |= GPIOx->Pin, P1M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P1M1 |= GPIOx->Pin, P1M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P1M1 &= ~GPIOx->Pin, P1M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P2)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P2M1 &= ~GPIOx->Pin, P2M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P2M1 |= GPIOx->Pin, P2M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P2M1 |= GPIOx->Pin, P2M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P2M1 &= ~GPIOx->Pin, P2M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P3)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P3M1 &= ~GPIOx->Pin, P3M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P3M1 |= GPIOx->Pin, P3M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P3M1 |= GPIOx->Pin, P3M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P3M1 &= ~GPIOx->Pin, P3M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P4)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P4M1 &= ~GPIOx->Pin, P4M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P4M1 |= GPIOx->Pin, P4M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P4M1 |= GPIOx->Pin, P4M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P4M1 &= ~GPIOx->Pin, P4M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P5)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P5M1 &= ~GPIOx->Pin, P5M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P5M1 |= GPIOx->Pin, P5M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P5M1 |= GPIOx->Pin, P5M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P5M1 &= ~GPIOx->Pin, P5M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P6)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P6M1 &= ~GPIOx->Pin, P6M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P6M1 |= GPIOx->Pin, P6M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P6M1 |= GPIOx->Pin, P6M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P6M1 &= ~GPIOx->Pin, P6M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(GPIO == GPIO_P7)
|
||||
{
|
||||
if(GPIOx->Mode == GPIO_PullUp) P7M1 &= ~GPIOx->Pin, P7M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_HighZ) P7M1 |= GPIOx->Pin, P7M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_OD) P7M1 |= GPIOx->Pin, P7M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
if(GPIOx->Mode == GPIO_OUT_PP) P7M1 &= ~GPIOx->Pin, P7M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
41
GPIO.h
Normal file
41
GPIO.h
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#ifndef __GPIO_H
|
||||
#define __GPIO_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define GPIO_PullUp 0 //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
#define GPIO_HighZ 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define GPIO_OUT_OD 2 //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
#define GPIO_OUT_PP 3 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
#define GPIO_Pin_0 0x01 //IO<49><4F><EFBFBD><EFBFBD> Px.0
|
||||
#define GPIO_Pin_1 0x02 //IO<49><4F><EFBFBD><EFBFBD> Px.1
|
||||
#define GPIO_Pin_2 0x04 //IO<49><4F><EFBFBD><EFBFBD> Px.2
|
||||
#define GPIO_Pin_3 0x08 //IO<49><4F><EFBFBD><EFBFBD> Px.3
|
||||
#define GPIO_Pin_4 0x10 //IO<49><4F><EFBFBD><EFBFBD> Px.4
|
||||
#define GPIO_Pin_5 0x20 //IO<49><4F><EFBFBD><EFBFBD> Px.5
|
||||
#define GPIO_Pin_6 0x40 //IO<49><4F><EFBFBD><EFBFBD> Px.6
|
||||
#define GPIO_Pin_7 0x80 //IO<49><4F><EFBFBD><EFBFBD> Px.7
|
||||
#define GPIO_Pin_All 0xFF //IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define GPIO_Pin_Left 0x0F //IO<49><4F>1,2,3,4<><34>
|
||||
|
||||
#define GPIO_P0 0
|
||||
#define GPIO_P1 1
|
||||
#define GPIO_P2 2
|
||||
#define GPIO_P3 3
|
||||
#define GPIO_P4 4
|
||||
#define GPIO_P5 5
|
||||
#define GPIO_P6 6
|
||||
#define GPIO_P7 7
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 Mode; //IOģʽ, GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
u8 Pin; //Ҫ<><D2AA><EFBFBD>õĶ˿<C4B6>
|
||||
} GPIO_InitTypeDef;
|
||||
|
||||
u8 GPIO_Inilize(u8 GPIO, GPIO_InitTypeDef *GPIOx);
|
||||
|
||||
#endif
|
||||
2652
Listings/BLV_C12_Dimm_V19.m51
Normal file
2652
Listings/BLV_C12_Dimm_V19.m51
Normal file
File diff suppressed because it is too large
Load Diff
97
Listings/GPIO.lst
Normal file
97
Listings/GPIO.lst
Normal file
@@ -0,0 +1,97 @@
|
||||
C51 COMPILER V9.01 GPIO 12/15/2025 20:45:03 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE GPIO
|
||||
OBJECT MODULE PLACED IN .\Objects\GPIO.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE GPIO.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\GPIO
|
||||
-.lst) OBJECT(.\Objects\GPIO.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "GPIO.h"
|
||||
2
|
||||
3 //========================================================================
|
||||
4 // <20><><EFBFBD><EFBFBD>: u8 GPIO_Inilize(u8 GPIO, GPIO_InitTypeDef *GPIOx)
|
||||
5 // <20><><EFBFBD><EFBFBD>: <20><>ʼ<EFBFBD><CABC>IO<49><4F>.
|
||||
6 // <20><><EFBFBD><EFBFBD>: GPIOx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>timer.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
7 // <20><><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0, <20>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1,<2C><><EFBFBD><EFBFBD>2.
|
||||
8 // <20>汾: V1.0, 2012-10-22
|
||||
9 //========================================================================
|
||||
10 u8 GPIO_Inilize(u8 GPIO, GPIO_InitTypeDef *GPIOx)
|
||||
11 {
|
||||
12 1 if(GPIO > GPIO_P7) return 1; //<2F>ղ<EFBFBD><D5B2><EFBFBD>
|
||||
13 1 if(GPIOx->Mode > GPIO_OUT_PP) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
14 1 if(GPIO == GPIO_P0)
|
||||
15 1 {
|
||||
16 2 if(GPIOx->Mode == GPIO_PullUp) P0M1 &= ~GPIOx->Pin, P0M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
17 2 if(GPIOx->Mode == GPIO_HighZ) P0M1 |= GPIOx->Pin, P0M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
18 2 if(GPIOx->Mode == GPIO_OUT_OD) P0M1 |= GPIOx->Pin, P0M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
19 2 if(GPIOx->Mode == GPIO_OUT_PP) P0M1 &= ~GPIOx->Pin, P0M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
20 2 }
|
||||
21 1 if(GPIO == GPIO_P1)
|
||||
22 1 {
|
||||
23 2 if(GPIOx->Mode == GPIO_PullUp) P1M1 &= ~GPIOx->Pin, P1M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
24 2 if(GPIOx->Mode == GPIO_HighZ) P1M1 |= GPIOx->Pin, P1M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
25 2 if(GPIOx->Mode == GPIO_OUT_OD) P1M1 |= GPIOx->Pin, P1M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
26 2 if(GPIOx->Mode == GPIO_OUT_PP) P1M1 &= ~GPIOx->Pin, P1M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
27 2 }
|
||||
28 1 if(GPIO == GPIO_P2)
|
||||
29 1 {
|
||||
30 2 if(GPIOx->Mode == GPIO_PullUp) P2M1 &= ~GPIOx->Pin, P2M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
31 2 if(GPIOx->Mode == GPIO_HighZ) P2M1 |= GPIOx->Pin, P2M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
32 2 if(GPIOx->Mode == GPIO_OUT_OD) P2M1 |= GPIOx->Pin, P2M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
33 2 if(GPIOx->Mode == GPIO_OUT_PP) P2M1 &= ~GPIOx->Pin, P2M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
34 2 }
|
||||
35 1 if(GPIO == GPIO_P3)
|
||||
36 1 {
|
||||
37 2 if(GPIOx->Mode == GPIO_PullUp) P3M1 &= ~GPIOx->Pin, P3M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
38 2 if(GPIOx->Mode == GPIO_HighZ) P3M1 |= GPIOx->Pin, P3M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
39 2 if(GPIOx->Mode == GPIO_OUT_OD) P3M1 |= GPIOx->Pin, P3M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
40 2 if(GPIOx->Mode == GPIO_OUT_PP) P3M1 &= ~GPIOx->Pin, P3M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
41 2 }
|
||||
42 1 if(GPIO == GPIO_P4)
|
||||
43 1 {
|
||||
44 2 if(GPIOx->Mode == GPIO_PullUp) P4M1 &= ~GPIOx->Pin, P4M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
45 2 if(GPIOx->Mode == GPIO_HighZ) P4M1 |= GPIOx->Pin, P4M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
46 2 if(GPIOx->Mode == GPIO_OUT_OD) P4M1 |= GPIOx->Pin, P4M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
47 2 if(GPIOx->Mode == GPIO_OUT_PP) P4M1 &= ~GPIOx->Pin, P4M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
48 2 }
|
||||
49 1 if(GPIO == GPIO_P5)
|
||||
50 1 {
|
||||
51 2 if(GPIOx->Mode == GPIO_PullUp) P5M1 &= ~GPIOx->Pin, P5M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
52 2 if(GPIOx->Mode == GPIO_HighZ) P5M1 |= GPIOx->Pin, P5M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
53 2 if(GPIOx->Mode == GPIO_OUT_OD) P5M1 |= GPIOx->Pin, P5M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
54 2 if(GPIOx->Mode == GPIO_OUT_PP) P5M1 &= ~GPIOx->Pin, P5M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
C51 COMPILER V9.01 GPIO 12/15/2025 20:45:03 PAGE 2
|
||||
|
||||
55 2 }
|
||||
56 1 if(GPIO == GPIO_P6)
|
||||
57 1 {
|
||||
58 2 if(GPIOx->Mode == GPIO_PullUp) P6M1 &= ~GPIOx->Pin, P6M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
59 2 if(GPIOx->Mode == GPIO_HighZ) P6M1 |= GPIOx->Pin, P6M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
60 2 if(GPIOx->Mode == GPIO_OUT_OD) P6M1 |= GPIOx->Pin, P6M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
61 2 if(GPIOx->Mode == GPIO_OUT_PP) P6M1 &= ~GPIOx->Pin, P6M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
62 2 }
|
||||
63 1 if(GPIO == GPIO_P7)
|
||||
64 1 {
|
||||
65 2 if(GPIOx->Mode == GPIO_PullUp) P7M1 &= ~GPIOx->Pin, P7M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD>˫<D7BC><CBAB><EFBFBD><EFBFBD>
|
||||
66 2 if(GPIOx->Mode == GPIO_HighZ) P7M1 |= GPIOx->Pin, P7M0 &= ~GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
67 2 if(GPIOx->Mode == GPIO_OUT_OD) P7M1 |= GPIOx->Pin, P7M0 |= GPIOx->Pin; //<2F><>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
||||
68 2 if(GPIOx->Mode == GPIO_OUT_PP) P7M1 &= ~GPIOx->Pin, P7M0 |= GPIOx->Pin; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
69 2 }
|
||||
70 1 return 0; //<2F>ɹ<EFBFBD>
|
||||
71 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 596 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = ---- ----
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
575
Listings/PWM15bit.lst
Normal file
575
Listings/PWM15bit.lst
Normal file
@@ -0,0 +1,575 @@
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE PWM15BIT
|
||||
OBJECT MODULE PLACED IN .\Objects\PWM15bit.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE PWM15bit.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\
|
||||
-PWM15bit.lst) OBJECT(.\Objects\PWM15bit.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 /*---------------------------------------------------------------------*/
|
||||
2 /* --- STC MCU Limited ------------------------------------------------*/
|
||||
3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
4 /* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
7 /* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
9 /* --- QQ: 800003751 -------------------------------------------------*/
|
||||
10 /* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
11 /*---------------------------------------------------------------------*/
|
||||
12
|
||||
13 #include "PWM15bit.h"
|
||||
14
|
||||
15 u16 code PWMxCR[48] = {
|
||||
16 0xff14, /* PWM00CR */
|
||||
17 0xff1c, /* PWM01CR */
|
||||
18 0xff24, /* PWM02CR */
|
||||
19 0xff2c, /* PWM03CR */
|
||||
20 0xff34, /* PWM04CR */
|
||||
21 0xff3c, /* PWM05CR */
|
||||
22 0xff44, /* PWM06CR */
|
||||
23 0xff4c, /* PWM07CR */
|
||||
24 0xff64, /* PWM10CR */
|
||||
25 0xff6c, /* PWM11CR */
|
||||
26 0xff74, /* PWM12CR */
|
||||
27 0xff7c, /* PWM13CR */
|
||||
28 0xff84, /* PWM14CR */
|
||||
29 0xff8c, /* PWM15CR */
|
||||
30 0xff94, /* PWM16CR */
|
||||
31 0xff9c, /* PWM17CR */
|
||||
32 0xffb4, /* PWM20CR */
|
||||
33 0xffbc, /* PWM21CR */
|
||||
34 0xffc4, /* PWM22CR */
|
||||
35 0xffcc, /* PWM23CR */
|
||||
36 0xffd4, /* PWM24CR */
|
||||
37 0xffdc, /* PWM25CR */
|
||||
38 0xffe4, /* PWM26CR */
|
||||
39 0xffec, /* PWM27CR */
|
||||
40 0xfc14, /* PWM30CR */
|
||||
41 0xfc1c, /* PWM31CR */
|
||||
42 0xfc24, /* PWM32CR */
|
||||
43 0xfc2c, /* PWM33CR */
|
||||
44 0xfc34, /* PWM34CR */
|
||||
45 0xfc3c, /* PWM35CR */
|
||||
46 0xfc44, /* PWM36CR */
|
||||
47 0xfc4c, /* PWM37CR */
|
||||
48 0xfc64, /* PWM40CR */
|
||||
49 0xfc6c, /* PWM41CR */
|
||||
50 0xfc74, /* PWM42CR */
|
||||
51 0xfc7c, /* PWM43CR */
|
||||
52 0xfc84, /* PWM44CR */
|
||||
53 0xfc8c, /* PWM45CR */
|
||||
54 0xfc94, /* PWM46CR */
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
55 0xfc9c, /* PWM47CR */
|
||||
56 0xfcb4, /* PWM50CR */
|
||||
57 0xfcbc, /* PWM51CR */
|
||||
58 0xfcc4, /* PWM52CR */
|
||||
59 0xfccc, /* PWM53CR */
|
||||
60 0xfcd4, /* PWM54CR */
|
||||
61 0xfcdc, /* PWM55CR */
|
||||
62 0xfce4, /* PWM56CR */
|
||||
63 0xfcec, /* PWM57CR */
|
||||
64 };
|
||||
65
|
||||
66 u16 code PWMxT1[48] = {
|
||||
67 0xff10, /* PWM00T1 */
|
||||
68 0xff18, /* PWM01T1 */
|
||||
69 0xff20, /* PWM02T1 */
|
||||
70 0xff28, /* PWM03T1 */
|
||||
71 0xff30, /* PWM04T1 */
|
||||
72 0xff38, /* PWM05T1 */
|
||||
73 0xff40, /* PWM06T1 */
|
||||
74 0xff48, /* PWM07T1 */
|
||||
75 0xff60, /* PWM10T1 */
|
||||
76 0xff68, /* PWM11T1 */
|
||||
77 0xff70, /* PWM12T1 */
|
||||
78 0xff78, /* PWM13T1 */
|
||||
79 0xff80, /* PWM14T1 */
|
||||
80 0xff88, /* PWM15T1 */
|
||||
81 0xff90, /* PWM16T1 */
|
||||
82 0xff98, /* PWM17T1 */
|
||||
83 0xffb0, /* PWM20T1 */
|
||||
84 0xffb8, /* PWM21T1 */
|
||||
85 0xffc0, /* PWM22T1 */
|
||||
86 0xffc8, /* PWM23T1 */
|
||||
87 0xffd0, /* PWM24T1 */
|
||||
88 0xffd8, /* PWM25T1 */
|
||||
89 0xffe0, /* PWM26T1 */
|
||||
90 0xffe8, /* PWM27T1 */
|
||||
91 0xfc10, /* PWM30T1 */
|
||||
92 0xfc18, /* PWM31T1 */
|
||||
93 0xfc20, /* PWM32T1 */
|
||||
94 0xfc28, /* PWM33T1 */
|
||||
95 0xfc30, /* PWM34T1 */
|
||||
96 0xfc38, /* PWM35T1 */
|
||||
97 0xfc40, /* PWM36T1 */
|
||||
98 0xfc48, /* PWM37T1 */
|
||||
99 0xfc60, /* PWM40T1 */
|
||||
100 0xfc68, /* PWM41T1 */
|
||||
101 0xfc70, /* PWM42T1 */
|
||||
102 0xfc78, /* PWM43T1 */
|
||||
103 0xfc80, /* PWM44T1 */
|
||||
104 0xfc88, /* PWM45T1 */
|
||||
105 0xfc90, /* PWM46T1 */
|
||||
106 0xfc98, /* PWM47T1 */
|
||||
107 0xfcb0, /* PWM50T1 */
|
||||
108 0xfcb8, /* PWM51T1 */
|
||||
109 0xfcc0, /* PWM52T1 */
|
||||
110 0xfcc8, /* PWM53T1 */
|
||||
111 0xfcd0, /* PWM54T1 */
|
||||
112 0xfcd8, /* PWM55T1 */
|
||||
113 0xfce0, /* PWM56T1 */
|
||||
114 0xfce8, /* PWM57T1 */
|
||||
115 };
|
||||
116
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 3
|
||||
|
||||
117 u16 code PWMxT2[48] = {
|
||||
118 0xff12, /* PWM00T2 */
|
||||
119 0xff1a, /* PWM01T2 */
|
||||
120 0xff22, /* PWM02T2 */
|
||||
121 0xff2a, /* PWM03T2 */
|
||||
122 0xff32, /* PWM04T2 */
|
||||
123 0xff3a, /* PWM05T2 */
|
||||
124 0xff42, /* PWM06T2 */
|
||||
125 0xff4a, /* PWM07T2 */
|
||||
126 0xff62, /* PWM10T2 */
|
||||
127 0xff6a, /* PWM11T2 */
|
||||
128 0xff72, /* PWM12T2 */
|
||||
129 0xff7a, /* PWM13T2 */
|
||||
130 0xff82, /* PWM14T2 */
|
||||
131 0xff8a, /* PWM15T2 */
|
||||
132 0xff92, /* PWM16T2 */
|
||||
133 0xff9a, /* PWM17T2 */
|
||||
134 0xffb2, /* PWM20T2 */
|
||||
135 0xffba, /* PWM21T2 */
|
||||
136 0xffc2, /* PWM22T2 */
|
||||
137 0xffca, /* PWM23T2 */
|
||||
138 0xffd2, /* PWM24T2 */
|
||||
139 0xffda, /* PWM25T2 */
|
||||
140 0xffe2, /* PWM26T2 */
|
||||
141 0xffea, /* PWM27T2 */
|
||||
142 0xfc12, /* PWM30T2 */
|
||||
143 0xfc1a, /* PWM31T2 */
|
||||
144 0xfc22, /* PWM32T2 */
|
||||
145 0xfc2a, /* PWM33T2 */
|
||||
146 0xfc32, /* PWM34T2 */
|
||||
147 0xfc3a, /* PWM35T2 */
|
||||
148 0xfc42, /* PWM36T2 */
|
||||
149 0xfc4a, /* PWM37T2 */
|
||||
150 0xfc62, /* PWM40T2 */
|
||||
151 0xfc6a, /* PWM41T2 */
|
||||
152 0xfc72, /* PWM42T2 */
|
||||
153 0xfc7a, /* PWM43T2 */
|
||||
154 0xfc82, /* PWM44T2 */
|
||||
155 0xfc8a, /* PWM45T2 */
|
||||
156 0xfc92, /* PWM46T2 */
|
||||
157 0xfc9a, /* PWM47T2 */
|
||||
158 0xfcb2, /* PWM50T2 */
|
||||
159 0xfcba, /* PWM51T2 */
|
||||
160 0xfcc2, /* PWM52T2 */
|
||||
161 0xfcca, /* PWM53T2 */
|
||||
162 0xfcd2, /* PWM54T2 */
|
||||
163 0xfcda, /* PWM55T2 */
|
||||
164 0xfce2, /* PWM56T2 */
|
||||
165 0xfcea, /* PWM57T2 */
|
||||
166 };
|
||||
167
|
||||
168 u16 code PWMxHLD[48] = {
|
||||
169 0xff15, /* PWM00HLD */
|
||||
170 0xff1d, /* PWM01HLD */
|
||||
171 0xff25, /* PWM02HLD */
|
||||
172 0xff2d, /* PWM03HLD */
|
||||
173 0xff35, /* PWM04HLD */
|
||||
174 0xff3d, /* PWM05HLD */
|
||||
175 0xff45, /* PWM06HLD */
|
||||
176 0xff4d, /* PWM07HLD */
|
||||
177 0xff65, /* PWM10HLD */
|
||||
178 0xff6d, /* PWM11HLD */
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 4
|
||||
|
||||
179 0xff75, /* PWM12HLD */
|
||||
180 0xff7d, /* PWM13HLD */
|
||||
181 0xff85, /* PWM14HLD */
|
||||
182 0xff8d, /* PWM15HLD */
|
||||
183 0xff95, /* PWM16HLD */
|
||||
184 0xff9d, /* PWM17HLD */
|
||||
185 0xffb5, /* PWM20HLD */
|
||||
186 0xffbd, /* PWM21HLD */
|
||||
187 0xffc5, /* PWM22HLD */
|
||||
188 0xffcd, /* PWM23HLD */
|
||||
189 0xffd5, /* PWM24HLD */
|
||||
190 0xffdd, /* PWM25HLD */
|
||||
191 0xffe5, /* PWM26HLD */
|
||||
192 0xffed, /* PWM27HLD */
|
||||
193 0xfc15, /* PWM30HLD */
|
||||
194 0xfc1d, /* PWM31HLD */
|
||||
195 0xfc25, /* PWM32HLD */
|
||||
196 0xfc2d, /* PWM33HLD */
|
||||
197 0xfc35, /* PWM34HLD */
|
||||
198 0xfc3d, /* PWM35HLD */
|
||||
199 0xfc45, /* PWM36HLD */
|
||||
200 0xfc4d, /* PWM37HLD */
|
||||
201 0xfc65, /* PWM40HLD */
|
||||
202 0xfc6d, /* PWM41HLD */
|
||||
203 0xfc75, /* PWM42HLD */
|
||||
204 0xfc7d, /* PWM43HLD */
|
||||
205 0xfc85, /* PWM44HLD */
|
||||
206 0xfc8d, /* PWM45HLD */
|
||||
207 0xfc95, /* PWM46HLD */
|
||||
208 0xfc9d, /* PWM47HLD */
|
||||
209 0xfcb5, /* PWM50HLD */
|
||||
210 0xfcbd, /* PWM51HLD */
|
||||
211 0xfcc5, /* PWM52HLD */
|
||||
212 0xfccd, /* PWM53HLD */
|
||||
213 0xfcd5, /* PWM54HLD */
|
||||
214 0xfcdd, /* PWM55HLD */
|
||||
215 0xfce5, /* PWM56HLD */
|
||||
216 0xfced, /* PWM57HLD */
|
||||
217 };
|
||||
218
|
||||
219 //========================================================================
|
||||
220 // <20><><EFBFBD><EFBFBD>: u8 PWMChannelCtrl(u8 PWM_id, u8 pwm_eno, u8 pwm_ini, u8 pwm_eni, u8 pwm_ent2i, u8 pwm_ent1i)
|
||||
221 // <20><><EFBFBD><EFBFBD>: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
222 // <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
223 // pwm_eno: pwm<77><6D><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, 0<><30>ΪGPIO, 1<><31>ΪPWM<57><4D><EFBFBD><EFBFBD>.
|
||||
224 // pwm_ini: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ, 0Ϊ<30>͵<EFBFBD>ƽ, 1Ϊ<31>ߵ<EFBFBD>ƽ.
|
||||
225 // pwm_eni: pwmͨ<6D><CDA8><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57>ж<EFBFBD>.
|
||||
226 // pwm_ent2i: pwmͨ<6D><CDA8><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>.
|
||||
227 // pwm_ent1i: pwmͨ<6D><CDA8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57><4D>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57><4D>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>.
|
||||
228 // <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
229 // <20>汾: V1.0, 2020-09-22
|
||||
230 //========================================================================
|
||||
231 u8 PWMChannelCtrl(u8 PWM_id, u8 pwm_eno, u8 pwm_ini, u8 pwm_eni, u8 pwm_ent2i, u8 pwm_ent1i)
|
||||
232 {
|
||||
233 1 u8 xdata *pPWMxCR;
|
||||
234 1
|
||||
235 1 if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
236 1 if(pwm_eno > 1) return 2; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
237 1 if(pwm_ini > 1) return 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
238 1 if(pwm_eni > 1) return 2; //<2F>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
239 1 if(pwm_ent2i > 1) return 2; //<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
240 1 if(pwm_ent1i > 1) return 2; //<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 5
|
||||
|
||||
241 1
|
||||
242 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
243 1 pPWMxCR = (u8 *)PWMxCR[PWM_id];
|
||||
244 1 *pPWMxCR = (pwm_eno << 7) | (pwm_ini << 6) | (pwm_eni << 2)| (pwm_ent2i << 1)| pwm_ent1i;
|
||||
245 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
246 1 return 0;
|
||||
247 1 }
|
||||
248
|
||||
249 //========================================================================
|
||||
250 // <20><><EFBFBD><EFBFBD>: u8 PWMPeriodDuty(u8 PWM_id, u16 Period, u16 dutyL, u16 dutyH)
|
||||
251 // <20><><EFBFBD><EFBFBD>: PWM<57><4D><EFBFBD><EFBFBD>, ռ<>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD>.
|
||||
252 // <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
253 // dutyL: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, ȡֵ 0~0x7fff.
|
||||
254 // dutyH: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>, ȡֵ 0~0x7fff.
|
||||
255 // <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
256 // <20>汾: V1.0, 2020-09-22
|
||||
257 //========================================================================
|
||||
258 u8 PWM15Duty(u8 PWM_id,u16 dutyL)
|
||||
259 {
|
||||
260 1 u16 xdata *pPWMxT1;
|
||||
261 1 u16 xdata *pPWMxT2;
|
||||
262 1
|
||||
263 1 if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
264 1 if(dutyL > 0x7fff) return 2; //<2F>͵<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
265 1 //if(dutyH > 0x7fff) return 2; //<2F>ߵ<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
266 1
|
||||
267 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
268 1 pPWMxT1 = (u16 *)PWMxT1[PWM_id];
|
||||
269 1 *pPWMxT1 = dutyL & 0x7fff;
|
||||
270 1
|
||||
271 1 pPWMxT2 = (u16 *)PWMxT2[PWM_id];
|
||||
272 1 *pPWMxT2 = 0x0000 & 0x7fff;
|
||||
273 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
274 1 return 0;
|
||||
275 1 }
|
||||
276
|
||||
277 u8 qPWM15Duty(u8 PWM_id,u16 dutyL, u16 dutyH)
|
||||
278 {
|
||||
279 1 u16 xdata *pPWMxT1;
|
||||
280 1 u16 xdata *pPWMxT2;
|
||||
281 1
|
||||
282 1 if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
283 1 if(dutyL > 0x7fff) return 2; //<2F>͵<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
284 1 if(dutyH > 0x7fff) return 2; //<2F>ߵ<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
285 1
|
||||
286 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
287 1 pPWMxT1 = (u16 *)PWMxT1[PWM_id];
|
||||
288 1 *pPWMxT1 = dutyL & 0x7fff;
|
||||
289 1
|
||||
290 1 pPWMxT2 = (u16 *)PWMxT2[PWM_id];
|
||||
291 1 *pPWMxT2 = dutyH & 0x7fff;
|
||||
292 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
293 1 return 0;
|
||||
294 1 }
|
||||
295 //========================================================================
|
||||
296 // <20><><EFBFBD><EFBFBD>: u8 PWMOutputSet(u8 PWM_id, u8 pwm_hldl, u8 pwm_hldh)
|
||||
297 // <20><><EFBFBD><EFBFBD>: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
298 // <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
299 // pwm_hldl: pwmǿ<6D><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>λ, 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 1ǿ<31><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ.
|
||||
300 // pwm_hldh: pwmǿ<6D><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>λ, 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 1ǿ<31><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ.
|
||||
301 // <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
302 // <20>汾: V1.0, 2020-09-22
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 6
|
||||
|
||||
303 //========================================================================
|
||||
304 u8 PWMLevelSet(u8 PWM_id, u8 pwm_hldl, u8 pwm_hldh)
|
||||
305 {
|
||||
306 1 u8 xdata *pPWMxHLD;
|
||||
307 1
|
||||
308 1 if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
309 1 if(pwm_hldh > 1) return 2; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
310 1 if(pwm_hldl > 1) return 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
311 1
|
||||
312 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
313 1 pPWMxHLD = (u8 *)PWMxHLD[PWM_id];
|
||||
314 1 *pPWMxHLD = (pwm_hldh << 1) | pwm_hldl;
|
||||
315 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
316 1 return 0;
|
||||
317 1 }
|
||||
318
|
||||
319 //========================================================================
|
||||
320 // <20><><EFBFBD><EFBFBD>: void PWM15_Init(u8 PWM_id, PWM15_InitTypeDef *PWMx)
|
||||
321 // <20><><EFBFBD><EFBFBD>: 15λ<35><CEBB>ǿ<EFBFBD><C7BF>PWM<57><4D>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
322 // <20><><EFBFBD><EFBFBD>: PWM_id: PWM<57><4D><EFBFBD><EFBFBD>. ȡֵ PWM0,PWM1,PWM2,PWM3,PWM4,PWM5
|
||||
323 // PWMx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
324 // <20><><EFBFBD><EFBFBD>: none.
|
||||
325 // <20>汾: V1.0, 2020-09-22
|
||||
326 //========================================================================
|
||||
327 void PWM15_Init(u8 PWM_id, PWM15_InitTypeDef *PWMx)
|
||||
328 {
|
||||
329 1 if(PWM_id > PWM5) return; //id<69><64><EFBFBD><EFBFBD>
|
||||
330 1
|
||||
331 1 EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
332 1 if(PWM_id == PWM0)
|
||||
333 1 {
|
||||
334 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM0_Enable(); //ʹ<><CAB9>PWM0
|
||||
335 2 else PWM15_PWM0_Disable(); //<2F>ر<EFBFBD>PWM0
|
||||
336 2 PWM0_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
337 2 PWM0C = PWMx->PWM_Period & 0x7fff;
|
||||
338 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter0_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
339 2 else PWM15_Counter0_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
340 2 }
|
||||
341 1
|
||||
342 1 if(PWM_id == PWM1)
|
||||
343 1 {
|
||||
344 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM1_Enable(); //ʹ<><CAB9>PWM1
|
||||
345 2 else PWM15_PWM1_Disable(); //<2F>ر<EFBFBD>PWM1
|
||||
346 2 PWM1_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
347 2 PWM1C = PWMx->PWM_Period & 0x7fff;
|
||||
348 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter1_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
349 2 else PWM15_Counter1_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
350 2 }
|
||||
351 1
|
||||
352 1 if(PWM_id == PWM2)
|
||||
353 1 {
|
||||
354 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM2_Enable(); //ʹ<><CAB9>PWM2
|
||||
355 2 else PWM15_PWM2_Disable(); //<2F>ر<EFBFBD>PWM2
|
||||
356 2 PWM2_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
357 2 PWM2C = PWMx->PWM_Period & 0x7fff;
|
||||
358 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter2_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
359 2 else PWM15_Counter2_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
360 2 }
|
||||
361 1
|
||||
362 1 if(PWM_id == PWM3)
|
||||
363 1 {
|
||||
364 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM3_Enable(); //ʹ<><CAB9>PWM3
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 7
|
||||
|
||||
365 2 else PWM15_PWM3_Disable(); //<2F>ر<EFBFBD>PWM3
|
||||
366 2 PWM3_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
367 2 PWM3C = PWMx->PWM_Period & 0x7fff;
|
||||
368 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter3_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
369 2 else PWM15_Counter3_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
370 2 }
|
||||
371 1
|
||||
372 1 if(PWM_id == PWM4)
|
||||
373 1 {
|
||||
374 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM4_Enable(); //ʹ<><CAB9>PWM4
|
||||
375 2 else PWM15_PWM4_Disable(); //<2F>ر<EFBFBD>PWM4
|
||||
376 2 PWM4_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
377 2 PWM4C = PWMx->PWM_Period & 0x7fff;
|
||||
378 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter4_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
379 2 else PWM15_Counter4_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
380 2 }
|
||||
381 1
|
||||
382 1 if(PWM_id == PWM5)
|
||||
383 1 {
|
||||
384 2 if(PWMx->PWM_Enable == ENABLE) PWM15_PWM5_Enable(); //ʹ<><CAB9>PWM5
|
||||
385 2 else PWM15_PWM5_Disable(); //<2F>ر<EFBFBD>PWM5
|
||||
386 2 PWM5_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
387 2 PWM5C = PWMx->PWM_Period & 0x7fff;
|
||||
388 2 if(PWMx->PWM_Counter == ENABLE) PWM15_Counter5_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
389 2 else PWM15_Counter5_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
390 2 }
|
||||
391 1 EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
392 1 }
|
||||
393
|
||||
394
|
||||
395 //========================================================================
|
||||
396 // <20><><EFBFBD><EFBFBD>: void PWM0_Handler (void) interrupt PWM0_VECTOR
|
||||
397 // <20><><EFBFBD><EFBFBD>: PWM0<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
398 // <20><><EFBFBD><EFBFBD>: None
|
||||
399 // <20><><EFBFBD><EFBFBD>: none.
|
||||
400 // <20>汾: V1.0, 2020-10-13
|
||||
401 //========================================================================
|
||||
402 void PWM0_Handler (void) interrupt PWM0_VECTOR
|
||||
403 {
|
||||
404 1 char store;
|
||||
405 1 store = P_SW2;
|
||||
406 1 P_SW2 |= 0x80;
|
||||
407 1
|
||||
408 1 if(PWMCFG01 & 0x08) //PWM0<4D>ж<EFBFBD>
|
||||
409 1 {
|
||||
410 2 PWMCFG01 &= ~0x08; //<2F><>PWM0<4D>жϱ<D0B6>־
|
||||
411 2 // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
412 2 }
|
||||
413 1 if(PWM0IF)
|
||||
414 1 {
|
||||
415 2 PWM0IF = 0;
|
||||
416 2 P27 = ~P27;
|
||||
417 2 }
|
||||
418 1 P_SW2 = store;
|
||||
419 1 }
|
||||
420 //========================================================================
|
||||
421 // <20><><EFBFBD><EFBFBD>: void PWM1_Handler (void) interrupt PWM1_VECTOR
|
||||
422 // <20><><EFBFBD><EFBFBD>: PWM1<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
423 // <20><><EFBFBD><EFBFBD>: None
|
||||
424 // <20><><EFBFBD><EFBFBD>: none.
|
||||
425 // <20>汾: V1.0, 2020-10-13
|
||||
426 //========================================================================
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 8
|
||||
|
||||
427 void PWM1_Handler (void) interrupt PWM1_VECTOR
|
||||
428 {
|
||||
429 1 char store;
|
||||
430 1 store = P_SW2;
|
||||
431 1 P_SW2 |= 0x80;
|
||||
432 1
|
||||
433 1 if(PWMCFG01 & 0x80) //PWM1<4D>ж<EFBFBD>
|
||||
434 1 {
|
||||
435 2 PWMCFG01 &= ~0x80; //<2F><>PWM1<4D>жϱ<D0B6>־
|
||||
436 2 // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
437 2 }
|
||||
438 1 if(PWM1IF)
|
||||
439 1 {
|
||||
440 2 PWM1IF = 0;
|
||||
441 2 P26 = ~P26;
|
||||
442 2 }
|
||||
443 1 P_SW2 = store;
|
||||
444 1 }
|
||||
445 //========================================================================
|
||||
446 // <20><><EFBFBD><EFBFBD>: void PWM2_Handler (void) interrupt PWM2_VECTOR
|
||||
447 // <20><><EFBFBD><EFBFBD>: PWM2<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
448 // <20><><EFBFBD><EFBFBD>: None
|
||||
449 // <20><><EFBFBD><EFBFBD>: none.
|
||||
450 // <20>汾: V1.0, 2020-10-13
|
||||
451 //========================================================================
|
||||
452 void PWM2_Handler (void) interrupt PWM2_VECTOR
|
||||
453 {
|
||||
454 1 char store;
|
||||
455 1 store = P_SW2;
|
||||
456 1 P_SW2 |= 0x80;
|
||||
457 1
|
||||
458 1 if(PWMCFG23 & 0x08) //PWM2<4D>ж<EFBFBD>
|
||||
459 1 {
|
||||
460 2 PWMCFG23 &= ~0x08; //<2F><>PWM2<4D>жϱ<D0B6>־
|
||||
461 2 // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
462 2 }
|
||||
463 1 if(PWM2IF)
|
||||
464 1 {
|
||||
465 2 PWM2IF = 0;
|
||||
466 2 P25 = ~P25;
|
||||
467 2 }
|
||||
468 1 P_SW2 = store;
|
||||
469 1 }
|
||||
470 //========================================================================
|
||||
471 // <20><><EFBFBD><EFBFBD>: void PWM3_Handler (void) interrupt PWM3_VECTOR
|
||||
472 // <20><><EFBFBD><EFBFBD>: PWM3<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
473 // <20><><EFBFBD><EFBFBD>: None
|
||||
474 // <20><><EFBFBD><EFBFBD>: none.
|
||||
475 // <20>汾: V1.0, 2020-10-13
|
||||
476 //========================================================================
|
||||
477 void PWM3_Handler (void) interrupt PWM3_VECTOR
|
||||
478 {
|
||||
479 1 char store;
|
||||
480 1 store = P_SW2;
|
||||
481 1 P_SW2 |= 0x80;
|
||||
482 1
|
||||
483 1 if(PWMCFG23 & 0x80) //PWM3<4D>ж<EFBFBD>
|
||||
484 1 {
|
||||
485 2 PWMCFG23 &= ~0x80; //<2F><>PWM3<4D>жϱ<D0B6>־
|
||||
486 2 // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
487 2 }
|
||||
488 1 if(PWM3IF)
|
||||
C51 COMPILER V9.01 PWM15BIT 12/15/2025 20:45:04 PAGE 9
|
||||
|
||||
489 1 {
|
||||
490 2 PWM3IF = 0;
|
||||
491 2 P24 = ~P24;
|
||||
492 2 }
|
||||
493 1 P_SW2 = store;
|
||||
494 1 }
|
||||
495 //========================================================================
|
||||
496 // <20><><EFBFBD><EFBFBD>: void PWM4_Handler (void) interrupt PWM4_VECTOR
|
||||
497 // <20><><EFBFBD><EFBFBD>: PWM4<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
498 // <20><><EFBFBD><EFBFBD>: None
|
||||
499 // <20><><EFBFBD><EFBFBD>: none.
|
||||
500 // <20>汾: V1.0, 2020-10-13
|
||||
501 //========================================================================
|
||||
502 void PWM4_Handler (void) interrupt PWM4_VECTOR
|
||||
503 {
|
||||
504 1 char store;
|
||||
505 1 store = P_SW2;
|
||||
506 1 P_SW2 |= 0x80;
|
||||
507 1
|
||||
508 1 if(PWMCFG45 & 0x08) //PWM4<4D>ж<EFBFBD>
|
||||
509 1 {
|
||||
510 2 PWMCFG45 &= ~0x08; //<2F><>PWM4<4D>жϱ<D0B6>־
|
||||
511 2 // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
512 2 }
|
||||
513 1 if(PWM4IF)
|
||||
514 1 {
|
||||
515 2 PWM4IF = 0;
|
||||
516 2 P23 = ~P23;
|
||||
517 2 }
|
||||
518 1 P_SW2 = store;
|
||||
519 1 }
|
||||
520 //========================================================================
|
||||
521 // <20><><EFBFBD><EFBFBD>: void PWM5_Handler (void) interrupt PWM5_VECTOR
|
||||
522 // <20><><EFBFBD><EFBFBD>: PWM5<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
523 // <20><><EFBFBD><EFBFBD>: None
|
||||
524 // <20><><EFBFBD><EFBFBD>: none.
|
||||
525 // <20>汾: V1.0, 2020-10-13
|
||||
526 //========================================================================
|
||||
527 //void PWM5_Handler (void) interrupt PWM5_VECTOR //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD>31<33><31><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϺ<D0B6><CFBA><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>
|
||||
528 //{
|
||||
529 // if(PWMCFG45 & 0x80) //PWM5<4D>ж<EFBFBD>
|
||||
530 // {
|
||||
531 // PWMCFG45 &= ~0x80; //<2F><>PWM5<4D>жϱ<D0B6>־
|
||||
532 // // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
533 // }
|
||||
534 //}
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 1058 ----
|
||||
CONSTANT SIZE = 384 ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = ---- 6
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
69
Listings/Start_Init.lst
Normal file
69
Listings/Start_Init.lst
Normal file
@@ -0,0 +1,69 @@
|
||||
C51 COMPILER V9.01 START_INIT 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE START_INIT
|
||||
OBJECT MODULE PLACED IN .\Objects\Start_Init.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE Start_Init.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listing
|
||||
-s\Start_Init.lst) OBJECT(.\Objects\Start_Init.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "STC8xxxx.h"
|
||||
2 #include "Start_Init.h"
|
||||
3 #include "string.h"
|
||||
4 #include "UART_Set.h"
|
||||
5 #include "timer.h"
|
||||
6 #include "pwm_control.h"
|
||||
7
|
||||
8 void Start_Init(void)
|
||||
9 {
|
||||
10 1 u8 i;
|
||||
11 1 memset(&g_Usart,0,sizeof(g_Usart));
|
||||
12 1 memset(&s_recv, 0, sizeof(s_recv));
|
||||
13 1 memset(&g_answer,0,sizeof(g_answer));
|
||||
14 1 g_Usart.lastsn=0xFF;
|
||||
15 1 s_recv.B_min = 0;
|
||||
16 1 s_recv.B_max = 100;
|
||||
17 1 s_recv.global_brightness = 100;
|
||||
18 1
|
||||
19 1 for(i=0;i<12;i++)
|
||||
20 1 {
|
||||
21 2 s_recv.pwm_step[i] = 1;
|
||||
22 2 s_recv.key_status[i] = 1;
|
||||
23 2 s_recv.gradual_time[i] = 300;
|
||||
24 2 }
|
||||
25 1 }
|
||||
26
|
||||
27 //<2F><>ʱ<EFBFBD><CAB1>2<EFBFBD><32>1ms<6D><73>ʱ
|
||||
28 void Timer2_Init_1ms(void)
|
||||
29 {
|
||||
30 1 TIM_InitTypeDef TIM_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
31 1 TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ, TIM_16BitAutoReload,TIM_16Bit,TI
|
||||
-M_8BitAutoReload,TIM_16BitAutoReloadNoMask
|
||||
32 1 TIM_InitStructure.TIM_Priority = Priority_3; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority
|
||||
-_2,Priority_3
|
||||
33 1 TIM_InitStructure.TIM_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE. (ע<><D7A2>: Timer2<72>̶<EFBFBD>Ϊ16λ<36>
|
||||
-Զ<><D4B6><EFBFBD>װ, <20>жϹ̶<CFB9>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>)
|
||||
34 1 TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T; //ָ<><D6B8>ʱ<EFBFBD><CAB1>Դ, TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_
|
||||
-Ext
|
||||
35 1 TIM_InitStructure.TIM_ClkOut = DISABLE; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
36 1 TIM_InitStructure.TIM_Value = 63693UL; //<2F><>ֵ,<2C><>ʱΪ1ms
|
||||
37 1 TIM_InitStructure.TIM_Run = ENABLE; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>, ENABLE<4C><45>DISABLE
|
||||
38 1 Timer_Inilize(Timer2,&TIM_InitStructure); //<2F><>ʼ<EFBFBD><CABC>Timer2 Timer0,Timer1,Timer2,Timer3,Timer4
|
||||
39 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 168 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = ---- 8
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
C51 COMPILER V9.01 START_INIT 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
531
Listings/UART.lst
Normal file
531
Listings/UART.lst
Normal file
@@ -0,0 +1,531 @@
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE UART
|
||||
OBJECT MODULE PLACED IN .\Objects\UART.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE UART.C OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\UART
|
||||
-.lst) OBJECT(.\Objects\UART.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 /*---------------------------------------------------------------------*/
|
||||
2 /* --- STC MCU Limited ------------------------------------------------*/
|
||||
3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
4 /* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
7 /* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
9 /* --- QQ: 800003751 -------------------------------------------------*/
|
||||
10 /* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
11 /*---------------------------------------------------------------------*/
|
||||
12
|
||||
13 #include "UART.h"
|
||||
14 #include "timer.h"
|
||||
15
|
||||
16 #ifdef UART1
|
||||
17 COMx_Define COM1;
|
||||
18 u8 xdata TX1_Buffer[COM_TX1_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
19 u8 xdata RX1_Buffer[COM_RX1_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
20 #endif
|
||||
21 #ifdef UART2
|
||||
COMx_Define COM2;
|
||||
u8 xdata TX2_Buffer[COM_TX2_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX2_Buffer[COM_RX2_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
26 #ifdef UART3
|
||||
27 COMx_Define COM3;
|
||||
28 u8 xdata TX3_Buffer[COM_TX3_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
29 u8 xdata RX3_Buffer[COM_RX3_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
30 #endif
|
||||
31 #ifdef UART4
|
||||
COMx_Define COM4;
|
||||
u8 xdata TX4_Buffer[COM_TX4_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX4_Buffer[COM_RX4_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
36
|
||||
37 u8 UART_Configuration(u8 UARTx, COMx_InitDefine *COMx)
|
||||
38 {
|
||||
39 1 u8 i;
|
||||
40 1 u32 j;
|
||||
41 1
|
||||
42 1 #ifdef UART1
|
||||
43 1 if(UARTx == UART1)
|
||||
44 1 {
|
||||
45 2 COM1.id = 1;
|
||||
46 2 COM1.TX_read = 0;
|
||||
47 2 COM1.TX_write = 0;
|
||||
48 2 COM1.B_TX_busy = 0;
|
||||
49 2 COM1.RX_Cnt = 0;
|
||||
50 2 COM1.RX_TimeOut = 0;
|
||||
51 2 COM1.B_RX_OK = 0;
|
||||
52 2 for(i=0; i<COM_TX1_Lenth; i++) TX1_Buffer[i] = 0;
|
||||
53 2 for(i=0; i<COM_RX1_Lenth; i++) RX1_Buffer[i] = 0;
|
||||
54 2
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 2
|
||||
|
||||
55 2 if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
56 2 UART1_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_
|
||||
-3
|
||||
57 2 if(COMx->UART_Mode > UART_9bit_BRTx) return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
58 2 SCON = (SCON & 0x3f) | COMx->UART_Mode;
|
||||
59 2 if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
60 2 {
|
||||
61 3 j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
62 3 if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
63 3 j = 65536UL - j;
|
||||
64 3 if(COMx->UART_BRT_Use == BRT_Timer1)
|
||||
65 3 {
|
||||
66 4 TR1 = 0;
|
||||
67 4 AUXR &= ~0x01; //S1 BRT Use Timer1;
|
||||
68 4 TMOD &= ~(1<<6); //Timer1 set As Timer
|
||||
69 4 TMOD &= ~0x30; //Timer1_16bitAutoReload;
|
||||
70 4 AUXR |= (1<<6); //Timer1 set as 1T mode
|
||||
71 4 TH1 = (u8)(j>>8);
|
||||
72 4 TL1 = (u8)j;
|
||||
73 4 ET1 = 0; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
74 4 TMOD &= ~0x40; //<2F><>ʱ
|
||||
75 4 INT_CLKO &= ~0x02; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
76 4 TR1 = 1;
|
||||
77 4 }
|
||||
78 3 else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
79 3 {
|
||||
80 4 AUXR &= ~(1<<4); //Timer stop
|
||||
81 4 AUXR |= 0x01; //S1 BRT Use Timer2;
|
||||
82 4 AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
83 4 AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
84 4 TH2 = (u8)(j>>8);
|
||||
85 4 TL2 = (u8)j;
|
||||
86 4 IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
87 4 AUXR |= (1<<4); //Timer run enable
|
||||
88 4 }
|
||||
89 3 else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
90 3 }
|
||||
91 2 else if(COMx->UART_Mode == UART_ShiftRight)
|
||||
92 2 {
|
||||
93 3 if(COMx->BaudRateDouble == ENABLE) AUXR |= (1<<5); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/2
|
||||
94 3 else AUXR &= ~(1<<5); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/12
|
||||
95 3 }
|
||||
96 2 else if(COMx->UART_Mode == UART_9bit) //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk*2^SMOD/64
|
||||
97 2 {
|
||||
98 3 if(COMx->BaudRateDouble == ENABLE) PCON |= (1<<7); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/32
|
||||
99 3 else PCON &= ~(1<<7); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/64
|
||||
100 3 }
|
||||
101 2 if(COMx->UART_Interrupt == ENABLE) ES = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
102 2 else ES = 0; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
103 2 if(COMx->UART_RxEnable == ENABLE) REN = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
104 2 else REN = 0; //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
105 2 P_SW1 = (P_SW1 & 0x3f) | (COMx->UART_P_SW & 0xc0); //<2F>л<EFBFBD>IO
|
||||
106 2 return 0;
|
||||
107 2 }
|
||||
108 1 #endif
|
||||
109 1 #ifdef UART2
|
||||
if(UARTx == UART2)
|
||||
{
|
||||
COM2.id = 2;
|
||||
COM2.TX_read = 0;
|
||||
COM2.TX_write = 0;
|
||||
COM2.B_TX_busy = 0;
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 3
|
||||
|
||||
COM2.RX_Cnt = 0;
|
||||
COM2.RX_TimeOut = 0;
|
||||
COM2.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX2_Lenth; i++) TX2_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX2_Lenth; i++) RX2_Buffer[i] = 0;
|
||||
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) ||(COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART2_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority
|
||||
-_3
|
||||
if(COMx->UART_Mode == UART_9bit_BRTx) S2CON |= (1<<7); //9bit
|
||||
else S2CON &= ~(1<<7); //8bit
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
if(COMx->UART_Interrupt == ENABLE) IE2 |= 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else IE2 &= ~1; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) S2CON |= (1<<4); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else S2CON &= ~(1<<4); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW2 = (P_SW2 & ~1) | (COMx->UART_P_SW & 0x01); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
148 1 #ifdef UART3
|
||||
149 1 if(UARTx == UART3)
|
||||
150 1 {
|
||||
151 2 COM3.id = 3;
|
||||
152 2 COM3.TX_read = 0;
|
||||
153 2 COM3.TX_write = 0;
|
||||
154 2 COM3.B_TX_busy = 0;
|
||||
155 2 COM3.RX_Cnt = 0;
|
||||
156 2 COM3.RX_TimeOut = 0;
|
||||
157 2 COM3.B_RX_OK = 0;
|
||||
158 2 for(i=0; i<COM_TX3_Lenth; i++) TX3_Buffer[i] = 0;
|
||||
159 2 for(i=0; i<COM_RX3_Lenth; i++) RX3_Buffer[i] = 0;
|
||||
160 2
|
||||
161 2 if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
162 2 {
|
||||
163 3 if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
164 3 UART3_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priorit
|
||||
-y_3
|
||||
165 3 if(COMx->UART_Mode == UART_9bit_BRTx) S3_9bit(); //9bit
|
||||
166 3 else S3_8bit(); //8bit
|
||||
167 3 j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
168 3 if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
169 3 j = 65536UL - j;
|
||||
170 3 if(COMx->UART_BRT_Use == BRT_Timer3)
|
||||
171 3 {
|
||||
172 4 S3_BRT_UseTimer3(); //S3 BRT Use Timer3;
|
||||
173 4 TH3 = (u8)(j>>8);
|
||||
174 4 TL3 = (u8)j;
|
||||
175 4 T4T3M &= 0xf0;
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 4
|
||||
|
||||
176 4 T4T3M |= 0x0a; //Timer3 set As Timer, 1T mode, Start timer3
|
||||
177 4 }
|
||||
178 3 else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
179 3 {
|
||||
180 4 AUXR &= ~(1<<4); //Timer stop
|
||||
181 4 S3_BRT_UseTimer2(); //S3 BRT Use Timer2;
|
||||
182 4 AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
183 4 AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
184 4 TH2 = (u8)(j>>8);
|
||||
185 4 TL2 = (u8)j;
|
||||
186 4 IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
187 4 AUXR |= (1<<4); //Timer run enable
|
||||
188 4 }
|
||||
189 3 else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
190 3 }
|
||||
191 2 else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
192 2 if(COMx->UART_Interrupt == ENABLE) S3_Int_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
193 2 else S3_Int_Disable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
194 2 if(COMx->UART_RxEnable == ENABLE) S3_RX_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
195 2 else S3_RX_Disable(); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
196 2 P_SW2 = (P_SW2 & ~2) | (COMx->UART_P_SW & 0x02); //<2F>л<EFBFBD>IO
|
||||
197 2 return 0;
|
||||
198 2 }
|
||||
199 1 #endif
|
||||
200 1 #ifdef UART4
|
||||
if(UARTx == UART4)
|
||||
{
|
||||
COM4.id = 3;
|
||||
COM4.TX_read = 0;
|
||||
COM4.TX_write = 0;
|
||||
COM4.B_TX_busy = 0;
|
||||
COM4.RX_Cnt = 0;
|
||||
COM4.RX_TimeOut = 0;
|
||||
COM4.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX4_Lenth; i++) TX4_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX4_Lenth; i++) RX4_Buffer[i] = 0;
|
||||
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART4_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority
|
||||
-_3
|
||||
if(COMx->UART_Mode == UART_9bit_BRTx) S4_9bit(); //9bit
|
||||
else S4_8bit(); //8bit
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
if(COMx->UART_BRT_Use == BRT_Timer4)
|
||||
{
|
||||
S4_BRT_UseTimer4(); //S4 BRT Use Timer4;
|
||||
TH4 = (u8)(j>>8);
|
||||
TL4 = (u8)j;
|
||||
T4T3M &= 0x0f;
|
||||
T4T3M |= 0xa0; //Timer4 set As Timer, 1T mode, Start timer4
|
||||
}
|
||||
else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
{
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
S4_BRT_UseTimer2(); //S4 BRT Use Timer2;
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 5
|
||||
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
if(COMx->UART_Interrupt == ENABLE) S4_Int_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else S4_Int_Disable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) S4_RX_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else S4_RX_Disable(); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW2 = (P_SW2 & ~4) | (COMx->UART_P_SW & 0x04); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
252 1 return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
253 1 }
|
||||
254
|
||||
255 /*********************************************************/
|
||||
256
|
||||
257 /********************* UART1 <20><><EFBFBD><EFBFBD> ************************/
|
||||
258 #ifdef UART1
|
||||
259 void TX1_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
260 {
|
||||
261 1 TX1_Buffer[COM1.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
262 1 if(++COM1.TX_write >= COM_TX1_Lenth) COM1.TX_write = 0;
|
||||
263 1
|
||||
264 1 if(COM1.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
265 1 {
|
||||
266 2 COM1.B_TX_busy = 1; //<2F><>־æ
|
||||
267 2 TI = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
268 2 }
|
||||
269 1 }
|
||||
270
|
||||
271 void PrintString1(u8 *puts)
|
||||
272 {
|
||||
273 1 for (; *puts != 0; puts++) TX1_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
274 1 }
|
||||
275 void Printbuffer1(u8 *puts,u8 len)
|
||||
276 {
|
||||
277 1 u8 i;
|
||||
278 1 for (i=0; i<len;i++) TX1_write2buff(puts[i]);
|
||||
279 1 }
|
||||
280
|
||||
281 u8 recv_start_flag=0;
|
||||
282 u32 recv_time=0;
|
||||
283 void UART1_int (void) interrupt UART1_VECTOR
|
||||
284 {
|
||||
285 1 static u8 stage=0;
|
||||
286 1 u8 dat;
|
||||
287 1 if(RI)
|
||||
288 1 {
|
||||
289 2 RI = 0;
|
||||
290 2 recv_start_flag=1;
|
||||
291 2 recv_time=systick_1ms;
|
||||
292 2
|
||||
293 2 if(COM1.B_RX_OK == 0)
|
||||
294 2 {
|
||||
295 3 dat=SBUF;
|
||||
296 3 if(COM1.RX_Cnt >= COM_RX1_Lenth) COM1.RX_Cnt = 0;
|
||||
297 3 if(dat=='D') //<2F><><EFBFBD><EFBFBD>10<31><30>'D',<2C><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>
|
||||
298 3 {
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 6
|
||||
|
||||
299 4 stage++;
|
||||
300 4 }
|
||||
301 3 else
|
||||
302 3 {
|
||||
303 4 stage=0;
|
||||
304 4 }
|
||||
305 3 if(stage==10)
|
||||
306 3 {
|
||||
307 4 IAP_CONTR=0x60;
|
||||
308 4 }
|
||||
309 3 RX1_Buffer[COM1.RX_Cnt++] = SBUF;
|
||||
310 3 COM1.RX_TimeOut = TimeOutSet1;
|
||||
311 3 }
|
||||
312 2 }
|
||||
313 1
|
||||
314 1 if(TI)
|
||||
315 1 {
|
||||
316 2 TI = 0;
|
||||
317 2 if(COM1.TX_read != COM1.TX_write)
|
||||
318 2 {
|
||||
319 3 SBUF = TX1_Buffer[COM1.TX_read];
|
||||
320 3 if(++COM1.TX_read >= COM_TX1_Lenth) COM1.TX_read = 0;
|
||||
321 3 }
|
||||
322 2 else COM1.B_TX_busy = 0;
|
||||
323 2 }
|
||||
324 1 }
|
||||
325 #endif
|
||||
326
|
||||
327 /********************* UART2 <20><><EFBFBD><EFBFBD> ************************/
|
||||
328 #ifdef UART2
|
||||
void TX2_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX2_Buffer[COM2.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM2.TX_write >= COM_TX2_Lenth) COM2.TX_write = 0;
|
||||
|
||||
if(COM2.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM2.B_TX_busy = 1; //<2F><>־æ
|
||||
SET_TI2(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString2(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX2_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void UART2_int (void) interrupt UART2_VECTOR
|
||||
{
|
||||
if(RI2)
|
||||
{
|
||||
CLR_RI2();
|
||||
if(COM2.B_RX_OK == 0)
|
||||
{
|
||||
if(COM2.RX_Cnt >= COM_RX2_Lenth) COM2.RX_Cnt = 0;
|
||||
RX2_Buffer[COM2.RX_Cnt++] = S2BUF;
|
||||
COM2.RX_TimeOut = TimeOutSet2;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI2)
|
||||
{
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 7
|
||||
|
||||
CLR_TI2();
|
||||
if(COM2.TX_read != COM2.TX_write)
|
||||
{
|
||||
S2BUF = TX2_Buffer[COM2.TX_read];
|
||||
if(++COM2.TX_read >= COM_TX2_Lenth) COM2.TX_read = 0;
|
||||
}
|
||||
else COM2.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
371
|
||||
372 /********************* UART3 <20><><EFBFBD><EFBFBD> ************************/
|
||||
373 #ifdef UART3
|
||||
374 void TX3_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
375 {
|
||||
376 1 TX3_Buffer[COM3.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
377 1 if(++COM3.TX_write >= COM_TX3_Lenth) COM3.TX_write = 0;
|
||||
378 1
|
||||
379 1 if(COM3.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
380 1 {
|
||||
381 2 COM3.B_TX_busy = 1; //<2F><>־æ
|
||||
382 2 SET_TI3(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
383 2 }
|
||||
384 1 }
|
||||
385
|
||||
386 void PrintString3(u8 *puts)
|
||||
387 {
|
||||
388 1 for (; *puts != 0; puts++) TX3_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
389 1 }
|
||||
390
|
||||
391 void Printbuffer3(u8 *puts,u8 len)
|
||||
392 {
|
||||
393 1 u8 i;
|
||||
394 1 for (i=0; i<len;i++) TX3_write2buff(*puts++); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
395 1 }
|
||||
396
|
||||
397 void UART3_int (void) interrupt UART3_VECTOR
|
||||
398 {
|
||||
399 1 if(RI3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
|
||||
400 1 {
|
||||
401 2 recv_start_flag=1;
|
||||
402 2 recv_time=systick_1ms;
|
||||
403 2 CLR_RI3();
|
||||
404 2 if(COM3.B_RX_OK == 0)
|
||||
405 2 {
|
||||
406 3 if(COM3.RX_Cnt >= COM_RX3_Lenth) COM3.RX_Cnt = 0;
|
||||
407 3 RX3_Buffer[COM3.RX_Cnt++] = S3BUF;
|
||||
408 3 COM3.RX_TimeOut = TimeOutSet3;
|
||||
409 3 }
|
||||
410 2 }
|
||||
411 1
|
||||
412 1 if(TI3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
|
||||
413 1 {
|
||||
414 2 CLR_TI3();
|
||||
415 2 if(COM3.TX_read != COM3.TX_write)
|
||||
416 2 {
|
||||
417 3 S3BUF = TX3_Buffer[COM3.TX_read];
|
||||
418 3 if(++COM3.TX_read >= COM_TX3_Lenth) COM3.TX_read = 0;
|
||||
419 3 }
|
||||
420 2 else COM3.B_TX_busy = 0;
|
||||
421 2 }
|
||||
422 1 }
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 8
|
||||
|
||||
423 #endif
|
||||
424
|
||||
425 /********************* UART4 <20><><EFBFBD><EFBFBD> ************************/
|
||||
426 #ifdef UART4
|
||||
void TX4_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX4_Buffer[COM4.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM4.TX_write >= COM_TX4_Lenth) COM4.TX_write = 0;
|
||||
|
||||
if(COM4.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM4.B_TX_busy = 1; //<2F><>־æ
|
||||
SET_TI4(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString4(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX4_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void UART4_int (void) interrupt UART4_VECTOR
|
||||
{
|
||||
if(RI4)
|
||||
{
|
||||
CLR_RI4();
|
||||
if(COM4.B_RX_OK == 0)
|
||||
{
|
||||
if(COM4.RX_Cnt >= COM_RX4_Lenth) COM4.RX_Cnt = 0;
|
||||
RX4_Buffer[COM4.RX_Cnt++] = S4BUF;
|
||||
COM4.RX_TimeOut = TimeOutSet4;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI4)
|
||||
{
|
||||
CLR_TI4();
|
||||
if(COM4.TX_read != COM4.TX_write)
|
||||
{
|
||||
S4BUF = TX4_Buffer[COM4.TX_read];
|
||||
if(++COM4.TX_read >= COM_TX4_Lenth) COM4.TX_read = 0;
|
||||
}
|
||||
else COM4.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
469
|
||||
470 /*************** <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *****************/
|
||||
471 void UART3_config(void)
|
||||
472 {
|
||||
473 1 COMx_InitDefine COMx_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
474 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,U
|
||||
-ART_9bit_BRTx
|
||||
475 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer3; //ʹ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>, BRT_Timer2, BRT_Timer3 (ע<><D7A2>: <20><><EFBFBD><EFBFBD>2<EFBFBD>̶<EFBFBD>
|
||||
-ʹ<><CAB9>BRT_Timer2)
|
||||
476 1 COMx_InitStructure.UART_BaudRate = 115200; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 110 ~ 115200
|
||||
477 1 COMx_InitStructure.UART_RxEnable = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
478 1 COMx_InitStructure.UART_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
479 1 COMx_InitStructure.UART_Priority = Priority_0; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priori
|
||||
-ty_2,Priority_3
|
||||
480 1 COMx_InitStructure.UART_P_SW = UART3_SW_P50_P51; //<2F>л<EFBFBD><D0BB>˿<EFBFBD>, UART3_SW_P00_P01,UART3_SW_P50_P51
|
||||
481 1 UART_Configuration(UART3, &COMx_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3 UART1,UART2,UART3,UART4
|
||||
C51 COMPILER V9.01 UART 12/15/2025 20:45:03 PAGE 9
|
||||
|
||||
482 1
|
||||
483 1 //PrintString3("STC8 UART3 Test Programme!\r\n"); //UART3<54><33><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
484 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 1347 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = 128 ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 20 27
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
657
Listings/UART_Set.lst
Normal file
657
Listings/UART_Set.lst
Normal file
@@ -0,0 +1,657 @@
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE UART_SET
|
||||
OBJECT MODULE PLACED IN .\Objects\UART_Set.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE UART_Set.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\
|
||||
-UART_Set.lst) OBJECT(.\Objects\UART_Set.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "UART_Set.h"
|
||||
2 #include "UART.h"
|
||||
3 #include "pwm_control.h"
|
||||
4 #include "string.h"
|
||||
5 #include "config.h"
|
||||
6 #include "timer.h"
|
||||
7 #include "STC8xxxx.h"
|
||||
8 #include "PWM15bit.h"
|
||||
9
|
||||
10 G_Usart g_Usart;
|
||||
11 G_answer g_answer;
|
||||
12 S_recv s_recv;
|
||||
13
|
||||
14 u8 debug = 0x00;
|
||||
15
|
||||
16
|
||||
17 /*
|
||||
18 <20>жϽ<D0B6><CFBD>յ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
|
||||
19 */
|
||||
20 void Usart_judge_Data(void)
|
||||
21 {
|
||||
22 1 u8 len = 0;
|
||||
23 1 u8 i, sum;
|
||||
24 1 sum = 0;
|
||||
25 1 g_Usart.ok_flag = 0;
|
||||
26 1
|
||||
27 1 if((recv_start_flag==1)&&(systick_1ms-recv_time>8))
|
||||
28 1 {
|
||||
29 2 recv_start_flag=0;
|
||||
30 2 #if DEBUG_
|
||||
{
|
||||
for(i=0;i<COM1.RX_Cnt;i++)
|
||||
{
|
||||
g_Usart.recv_buffer[i]=RX1_Buffer[i];
|
||||
}
|
||||
COM1.RX_Cnt = 0;
|
||||
memset(RX1_Buffer,0,sizeof(RX1_Buffer));
|
||||
}
|
||||
#else
|
||||
40 2 {
|
||||
41 3 len = COM3.RX_Cnt;
|
||||
42 3 for(i=0;i<COM3.RX_Cnt;i++)
|
||||
43 3 {
|
||||
44 4 g_Usart.recv_buffer[i]=RX3_Buffer[i];
|
||||
45 4 }
|
||||
46 3 COM3.RX_Cnt = 0;
|
||||
47 3 memset(RX3_Buffer,0,sizeof(RX3_Buffer));
|
||||
48 3 // if(debug) Printbuffer1(g_Usart.recv_buffer,11);
|
||||
49 3 }
|
||||
50 2 #endif
|
||||
51 2
|
||||
52 2 for (i = 0; i < g_Usart.recv_buffer[UART_FMT_LEN]; i++)
|
||||
53 2 {
|
||||
54 3 sum += g_Usart.recv_buffer[i];
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
55 3 }
|
||||
56 2 if (sum == 0xff)
|
||||
57 2 {
|
||||
58 3 if(len == g_Usart.recv_buffer[UART_FMT_LEN])
|
||||
59 3 {
|
||||
60 4 if ((g_Usart.recv_buffer[UART_FMT_ADDR_RX] == ADDR_RX) && (g_Usart.recv_buffer[UART_FMT_DEV_TYPE] == D
|
||||
-EV_TYPE))
|
||||
61 4 {
|
||||
62 5 g_Usart.Sn = g_Usart.recv_buffer[UART_FMT_TYPE]&0x0F;
|
||||
63 5
|
||||
64 5 if ((g_Usart.recv_buffer[UART_FMT_TYPE] & 0x40) == 0x00) //<2F><><EFBFBD>кż<D0BA><C5BC>飬<EFBFBD><EFBFBD>
|
||||
65 5 {
|
||||
66 6 g_Usart.ok_flag = 1; //<2F><EFBFBD><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
67 6 }
|
||||
68 5 else //<2F><><EFBFBD>к<EFBFBD>Ϊ<EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD>
|
||||
-<2D><><EFBFBD><EFBFBD>Ӧ<EFBFBD>øı<C3B8><C4B1><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
69 5 {
|
||||
70 6 if (g_Usart.Sn == g_Usart.lastsn)
|
||||
71 6 {
|
||||
72 7 g_Usart.ok_flag = 0;
|
||||
73 7 g_answer.short_answer[UART_FMT_CMD]=0xF0;
|
||||
74 7 g_answer.short_answer_flag=0x01;
|
||||
75 7 }
|
||||
76 6 else
|
||||
77 6 {
|
||||
78 7 g_Usart.ok_flag = 1;
|
||||
79 7 }
|
||||
80 6 }
|
||||
81 5 g_Usart.lastsn = g_Usart.Sn;
|
||||
82 5 }
|
||||
83 4 }
|
||||
84 3 }
|
||||
85 2 }
|
||||
86 1 }
|
||||
87
|
||||
88 void Usart_Deal_Data(void)
|
||||
89 {
|
||||
90 1 u8 i;
|
||||
91 1 if(g_Usart.ok_flag)
|
||||
92 1 {
|
||||
93 2 if(debug)
|
||||
94 2 {
|
||||
95 3 PrintString1("data ok");
|
||||
96 3 }
|
||||
97 2 switch(g_Usart.recv_buffer[UART_FMT_CMD])
|
||||
98 2 {
|
||||
99 3 //<2F><>ѯ״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
||||
100 3 case USART_CMD_QUEST:
|
||||
101 3 if(debug)
|
||||
102 3 {
|
||||
103 4 PrintString1("ask");
|
||||
104 4 }
|
||||
105 3 g_answer.long_answer[UART_FMT_CMD]=USART_CMD_QUEST_A;
|
||||
106 3 g_answer.long_answer_flag=0x01;
|
||||
107 3 break;
|
||||
108 3 //<2F><><EFBFBD>ðٷֱ<D9B7><D6B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
109 3 case USART_CMD_SET_BRIGHTNESS:
|
||||
110 3 g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SET_BRIGHTNESS_A;
|
||||
111 3 if(debug)
|
||||
112 3 {
|
||||
113 4 PrintString1("percent");
|
||||
114 4 }
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 3
|
||||
|
||||
115 3 //<2F><>һ<EFBFBD><D2BB>ʹ<EFBFBD><CAB9>λ
|
||||
116 3 for (i = 0; i < 8; i++)
|
||||
117 3 {
|
||||
118 4 if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
119 4 {
|
||||
120 5 s_recv.flag1[i] = 1;
|
||||
121 5 s_recv.flag2[i] = 0;
|
||||
122 5 s_recv.B_Ch[i] = g_Usart.recv_buffer[21 - i];
|
||||
123 5
|
||||
124 5 if (s_recv.B_Ch[i] < s_recv.B_min)
|
||||
125 5 {
|
||||
126 6 s_recv.B_Ch[i] = s_recv.B_min;
|
||||
127 6 }
|
||||
128 5
|
||||
129 5 if (s_recv.B_Ch[i] > s_recv.B_max)
|
||||
130 5 {
|
||||
131 6 s_recv.B_Ch[i] = s_recv.B_max;
|
||||
132 6 }
|
||||
133 5
|
||||
134 5 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_Ch[i] * PWM_MAX_VALUE * s_recv.global_
|
||||
-brightness / 100 / 100 * s_recv.key_status[i];
|
||||
135 5 s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
136 5
|
||||
137 5 s_recv.gradual_time[i] = g_Usart.recv_buffer[9] * 10; /*<2A><><EFBFBD>յĽ<D5B5><C4BD><EFBFBD>ʱ<EFBFBD><CAB1>*/
|
||||
138 5 /*
|
||||
139 5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
140 5 */
|
||||
141 5 if (s_recv.gradual_time[i] == 0)
|
||||
142 5 {
|
||||
143 6 s_recv.gradual_time[i] = 1;
|
||||
144 6 }
|
||||
145 5
|
||||
146 5 /*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
147 5 if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
148 5 {
|
||||
149 6 s_pwm.every_change_10ms[i] = (float)(s_pwm.wanttopwm[i] - s_pwm.currpwm[i]) / s_
|
||||
-recv.gradual_time[i];
|
||||
150 6 if (s_pwm.every_change_10ms[i] < 1)
|
||||
151 6 {
|
||||
152 7 s_pwm.every_change_10ms[i] = 1;
|
||||
153 7 }
|
||||
154 6 }
|
||||
155 5
|
||||
156 5 if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
157 5 {
|
||||
158 6 s_pwm.every_change_10ms[i] = (float)(s_pwm.currpwm[i] - s_pwm.wanttopwm[i]) / s_
|
||||
-recv.gradual_time[i];
|
||||
159 6 if (s_pwm.every_change_10ms[i] < 1)
|
||||
160 6 {
|
||||
161 7 s_pwm.every_change_10ms[i] = 1;
|
||||
162 7 }
|
||||
163 6 }
|
||||
164 5 }
|
||||
165 4 }
|
||||
166 3
|
||||
167 3 //<2F>ڶ<EFBFBD><DAB6><EFBFBD>ʹ<EFBFBD><CAB9>λ
|
||||
168 3 for (i = 0; i < 4; i++)
|
||||
169 3 {
|
||||
170 4 if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
171 4 {
|
||||
172 5 s_recv.flag1[i+8] = 1;
|
||||
173 5 s_recv.flag2[i+8] = 0;
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 4
|
||||
|
||||
174 5 s_recv.B_Ch[i+8] = g_Usart.recv_buffer[13 - i];
|
||||
175 5
|
||||
176 5 if (s_recv.B_Ch[i+8] < s_recv.B_min)
|
||||
177 5 {
|
||||
178 6 s_recv.B_Ch[i+8] = s_recv.B_min;
|
||||
179 6 }
|
||||
180 5
|
||||
181 5 if (s_recv.B_Ch[i+8] > s_recv.B_max)
|
||||
182 5 {
|
||||
183 6 s_recv.B_Ch[i+8] = s_recv.B_max;
|
||||
184 6 }
|
||||
185 5
|
||||
186 5 s_pwm.wanttopwm[i+8] = PWM_MAX_VALUE - s_recv.B_Ch[i+8] * PWM_MAX_VALUE * s_recv.g
|
||||
-lobal_brightness / 100 / 100 * s_recv.key_status[i+8];
|
||||
187 5 s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
188 5
|
||||
189 5 s_recv.gradual_time[i+8] = g_Usart.recv_buffer[9] * 10; /*<2A><><EFBFBD>յĽ<D5B5><C4BD><EFBFBD>ʱ<EFBFBD><CAB1>*/
|
||||
190 5
|
||||
191 5 /*
|
||||
192 5 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
193 5 */
|
||||
194 5 if (s_recv.gradual_time[i+8] == 0)
|
||||
195 5 {
|
||||
196 6 s_recv.gradual_time[i+8] = 1;
|
||||
197 6 }
|
||||
198 5
|
||||
199 5 /*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
200 5 if (s_pwm.wanttopwm[i+8] > s_pwm.currpwm[i+8])
|
||||
201 5 {
|
||||
202 6 s_pwm.every_change_10ms[i+8] = (float)(s_pwm.wanttopwm[i+8] - s_pwm.currpwm[i+
|
||||
-8]) / s_recv.gradual_time[i+8];
|
||||
203 6 if (s_pwm.every_change_10ms[i+8] < 1)
|
||||
204 6 {
|
||||
205 7 s_pwm.every_change_10ms[i+8] = 1;
|
||||
206 7 }
|
||||
207 6 }
|
||||
208 5
|
||||
209 5
|
||||
210 5 if (s_pwm.wanttopwm[i+8] < s_pwm.currpwm[i+8])
|
||||
211 5 {
|
||||
212 6 s_pwm.every_change_10ms[i+8] = (float)(s_pwm.currpwm[i+8] - s_pwm.wanttopwm[i
|
||||
-+8]) / s_recv.gradual_time[i+8];
|
||||
213 6 if (s_pwm.every_change_10ms[i+8] < 1)
|
||||
214 6 {
|
||||
215 7 s_pwm.every_change_10ms[i+8] = 1;
|
||||
216 7 }
|
||||
217 6 }
|
||||
218 5 }
|
||||
219 4 }
|
||||
220 3
|
||||
221 3 g_answer.short_answer_flag=0x01;
|
||||
222 3 break;
|
||||
223 3
|
||||
224 3
|
||||
225 3 //<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>ѭ<EFBFBD><D1AD>
|
||||
226 3 case USART_CMD_SET_MODE:
|
||||
227 3 g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SET_MODE_A;
|
||||
228 3 if(debug)
|
||||
229 3 {
|
||||
230 4 PrintString1("change light");
|
||||
231 4 }
|
||||
232 3
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 5
|
||||
|
||||
233 3 for (i = 0; i < 8; i++)
|
||||
234 3 {
|
||||
235 4 if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
236 4 {
|
||||
237 5 s_recv.flag1[i] = 0;
|
||||
238 5 s_recv.flag2[i] = 1;
|
||||
239 5 s_recv.mode[i] = g_Usart.recv_buffer[9];
|
||||
240 5 s_recv.pwm_step[i] = g_Usart.recv_buffer[11];
|
||||
241 5
|
||||
242 5 if (s_recv.mode[i] == 0x00)
|
||||
243 5 {
|
||||
244 6 if (g_Usart.recv_buffer[10] == 0x00)
|
||||
245 6 {
|
||||
246 7 s_recv.forward[i] = 0;
|
||||
247 7 }
|
||||
248 6
|
||||
249 6 if (g_Usart.recv_buffer[10] == 0x01)
|
||||
250 6 {
|
||||
251 7 s_recv.forward[i] = 1;
|
||||
252 7 }
|
||||
253 6
|
||||
254 6 if (g_Usart.recv_buffer[10] == 0x02) //<2F><>ת
|
||||
255 6 {
|
||||
256 7 if (s_recv.forward[i] == 0x01)
|
||||
257 7 {
|
||||
258 8 s_recv.forward[i] = 0x00;
|
||||
259 8 continue; // Ϊ<><CEAA>ֹ<EFBFBD><D6B9>ת֮<D7AA><D6AE>ֱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
|
||||
260 8 }
|
||||
261 7
|
||||
262 7 if (s_recv.forward[i] == 0x00)
|
||||
263 7 {
|
||||
264 8 s_recv.forward[i] = 0x01;
|
||||
265 8 continue;
|
||||
266 8 }
|
||||
267 7 }
|
||||
268 6 }
|
||||
269 5 }
|
||||
270 4 }
|
||||
271 3
|
||||
272 3
|
||||
273 3 for (i = 0; i < 4; i++)
|
||||
274 3 {
|
||||
275 4 if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
276 4 {
|
||||
277 5 s_recv.flag1[i+8] = 0;
|
||||
278 5 s_recv.flag2[i+8] = 1;
|
||||
279 5 s_recv.mode[i+8] = g_Usart.recv_buffer[9];
|
||||
280 5 s_recv.pwm_step[i+8] = g_Usart.recv_buffer[11];
|
||||
281 5
|
||||
282 5 if (s_recv.mode[i+8] == 0x00)
|
||||
283 5 {
|
||||
284 6 if (g_Usart.recv_buffer[10] == 0x00)
|
||||
285 6 {
|
||||
286 7 s_recv.forward[i+8] = 0;
|
||||
287 7 }
|
||||
288 6
|
||||
289 6 if (g_Usart.recv_buffer[10] == 0x01)
|
||||
290 6 {
|
||||
291 7 s_recv.forward[i+8] = 1;
|
||||
292 7 }
|
||||
293 6
|
||||
294 6 if (g_Usart.recv_buffer[10] == 0x02) //<2F><>ת
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 6
|
||||
|
||||
295 6 {
|
||||
296 7 if (s_recv.forward[i+8] == 0x01)
|
||||
297 7 {
|
||||
298 8 s_recv.forward[i+8] = 0x00;
|
||||
299 8 continue; // Ϊ<><CEAA>ֹ<EFBFBD><D6B9>ת֮<D7AA><D6AE>ֱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
|
||||
300 8 }
|
||||
301 7
|
||||
302 7 if (s_recv.forward[i+8] == 0x00)
|
||||
303 7 {
|
||||
304 8 s_recv.forward[i+8] = 0x01;
|
||||
305 8 continue;
|
||||
306 8 }
|
||||
307 7 }
|
||||
308 6 }
|
||||
309 5 }
|
||||
310 4 }
|
||||
311 3 g_answer.short_answer_flag=0x01;
|
||||
312 3 break;
|
||||
313 3
|
||||
314 3
|
||||
315 3 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
316 3 case USART_CMD_ALL_BRIGHTNESS:
|
||||
317 3 g_answer.short_answer[UART_FMT_CMD]=USART_CMD_ALL_BRIGHTNESS_A;
|
||||
318 3
|
||||
319 3 if(debug)
|
||||
320 3 {
|
||||
321 4 PrintString1("global light");
|
||||
322 4 }
|
||||
323 3
|
||||
324 3 // s_recv.changeflag = 1;
|
||||
325 3 if (g_Usart.recv_buffer[7] & (1 << 5)) //ȫ<>ֿɵ<D6BF><C9B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
326 3 {
|
||||
327 4 s_recv.B_min = g_Usart.recv_buffer[10];
|
||||
328 4 for (i = 0; i < 12; i++)
|
||||
329 4 {
|
||||
330 5 if ( s_pwm.currvalue[i] < s_recv.B_min)
|
||||
331 5 {
|
||||
332 6 s_pwm.currvalue[i] = s_recv.B_min;
|
||||
333 6 }
|
||||
334 5 }
|
||||
335 4 }
|
||||
336 3
|
||||
337 3 if (g_Usart.recv_buffer[7] & (1 << 6)) //ȫ<>ֿɵ<D6BF><C9B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
338 3 {
|
||||
339 4 s_recv.B_max = g_Usart.recv_buffer[9];
|
||||
340 4 for (i = 0; i < 12; i++)
|
||||
341 4 {
|
||||
342 5 if ( s_pwm.currvalue[i] > s_recv.B_max)
|
||||
343 5 {
|
||||
344 6 s_pwm.currvalue[i] = s_recv.B_max;
|
||||
345 6 }
|
||||
346 5 }
|
||||
347 4 }
|
||||
348 3
|
||||
349 3 if (g_Usart.recv_buffer[7] & (1 << 7)) //ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
350 3 {
|
||||
351 4 s_recv.global_brightness = g_Usart.recv_buffer[8];
|
||||
352 4
|
||||
353 4 for (i = 0; i < 12; i++)
|
||||
354 4 {
|
||||
355 5 // s_pwm.wanttopwmflash[i] = PWM_MAX_VALUE - s_pwm.currvalue[i] * PWM_MAX_VALUE *
|
||||
-s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 7
|
||||
|
||||
356 5
|
||||
357 5 s_recv.flag1[i] = 1;
|
||||
358 5 s_recv.flag2[i] = 0;
|
||||
359 5
|
||||
360 5 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_Ch[i] * PWM_MAX_VALUE * s_recv.glo
|
||||
-bal_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
361 5 s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
362 5 if(s_pwm.wanttopwm[i] > PWM_MAX_VALUE)
|
||||
363 5 {
|
||||
364 6 s_pwm.wanttopwm[i] = PWM_MAX_VALUE;
|
||||
365 6 }
|
||||
366 5
|
||||
367 5 /*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
368 5 if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
369 5 {
|
||||
370 6 s_pwm.every_change_10ms[i] = (float)(s_pwm.wanttopwm[i] - s_pwm.currpwm[i])
|
||||
-/ s_recv.gradual_time[i];
|
||||
371 6 if (s_pwm.every_change_10ms[i] < 1)
|
||||
372 6 {
|
||||
373 7 s_pwm.every_change_10ms[i] = 1;
|
||||
374 7 }
|
||||
375 6 }
|
||||
376 5
|
||||
377 5 if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
378 5 {
|
||||
379 6 s_pwm.every_change_10ms[i] = (float)(s_pwm.currpwm[i] - s_pwm.wanttopwm[i])
|
||||
-/ s_recv.gradual_time[i];
|
||||
380 6 if (s_pwm.every_change_10ms[i] < 1)
|
||||
381 6 {
|
||||
382 7 s_pwm.every_change_10ms[i] = 1;
|
||||
383 7 }
|
||||
384 6 }
|
||||
385 5 }
|
||||
386 4 }
|
||||
387 3
|
||||
388 3
|
||||
389 3 g_answer.short_answer_flag=0x01;
|
||||
390 3 break;
|
||||
391 3
|
||||
392 3
|
||||
393 3 //<2F><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>״̬
|
||||
394 3 case USART_CMD_SWITCH_STATUS:
|
||||
395 3 g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SWITCH_STATUS_A;
|
||||
396 3 if(debug)
|
||||
397 3 {
|
||||
398 4 PrintString1("switch state");
|
||||
399 4 }
|
||||
400 3
|
||||
401 3 for (i = 0; i < 8; i++)
|
||||
402 3 {
|
||||
403 4 if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
404 4 {
|
||||
405 5 if (g_Usart.recv_buffer[9 + i] == 0x01)
|
||||
406 5 {
|
||||
407 6 s_recv.key_status[i] = 0x01;
|
||||
408 6 //s_pwm.currvalue[i] = s_pwm.thenvalue[i];
|
||||
409 6 Open_Light(i);
|
||||
410 6 }
|
||||
411 5
|
||||
412 5 if (g_Usart.recv_buffer[9 + i] == 0x00)
|
||||
413 5 {
|
||||
414 6 //s_pwm.thenvalue[i] = s_pwm.currvalue[i];
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 8
|
||||
|
||||
415 6 Close_Light(i);
|
||||
416 6 s_recv.flag1[i] = 0;
|
||||
417 6 s_recv.flag2[i] = 0;
|
||||
418 6 s_recv.mode[i] = 2;
|
||||
419 6 s_recv.key_status[i] = 0x00;
|
||||
420 6 }
|
||||
421 5
|
||||
422 5 if (g_Usart.recv_buffer[9 + i] == 0x02)
|
||||
423 5 {
|
||||
424 6 if (s_recv.key_status[i] == 0x00)
|
||||
425 6 {
|
||||
426 7 s_recv.key_status[i] = 0x01;
|
||||
427 7 //s_pwm.currvalue[i] = s_pwm.thenvalue[i];
|
||||
428 7 Open_Light(i);
|
||||
429 7 continue;
|
||||
430 7 }
|
||||
431 6
|
||||
432 6 if (s_recv.key_status[i] == 0x01)
|
||||
433 6 {
|
||||
434 7 //s_pwm.thenvalue[i] = s_pwm.currvalue[i];
|
||||
435 7 Close_Light(i);
|
||||
436 7 s_recv.flag1[i] = 0;
|
||||
437 7 s_recv.flag2[i] = 0;
|
||||
438 7 s_recv.mode[i] = 2;
|
||||
439 7 s_recv.key_status[i] = 0x00;
|
||||
440 7 continue;
|
||||
441 7 }
|
||||
442 6 }
|
||||
443 5 }
|
||||
444 4 }
|
||||
445 3
|
||||
446 3
|
||||
447 3 for (i = 0; i < 4; i++)
|
||||
448 3 {
|
||||
449 4 if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
450 4 {
|
||||
451 5 if (g_Usart.recv_buffer[9 + 8 + i] == 0x01)
|
||||
452 5 {
|
||||
453 6 s_recv.key_status[i+8] = 0x01;
|
||||
454 6 //s_pwm.currvalue[i+8] = s_pwm.thenvalue[i];
|
||||
455 6 Open_Light(i+8);
|
||||
456 6 }
|
||||
457 5
|
||||
458 5 if (g_Usart.recv_buffer[9 +8 + i] == 0x00)
|
||||
459 5 {
|
||||
460 6 //s_pwm.thenvalue[i+8] = s_pwm.currvalue[i+8];
|
||||
461 6 Close_Light(i+8);
|
||||
462 6 s_recv.flag1[i+8] = 0;
|
||||
463 6 s_recv.flag2[i+8] = 0;
|
||||
464 6 s_recv.mode[i+8] = 2;
|
||||
465 6 s_recv.key_status[i+8] = 0x00;
|
||||
466 6 }
|
||||
467 5
|
||||
468 5 if (g_Usart.recv_buffer[9 + 8 + i] == 0x02)
|
||||
469 5 {
|
||||
470 6 if (s_recv.key_status[i+8] == 0x00)
|
||||
471 6 {
|
||||
472 7 s_recv.key_status[i+8] = 0x01;
|
||||
473 7 //s_pwm.currvalue[i+8] = s_pwm.thenvalue[i];
|
||||
474 7 Open_Light(i+8);
|
||||
475 7 continue;
|
||||
476 7 }
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 9
|
||||
|
||||
477 6
|
||||
478 6
|
||||
479 6 if (s_recv.key_status[i+8] == 0x01)
|
||||
480 6 {
|
||||
481 7 //s_pwm.thenvalue[i+8] = s_pwm.currvalue[i+8];
|
||||
482 7 Close_Light(i+8);
|
||||
483 7 s_recv.flag1[i+8] = 0;
|
||||
484 7 s_recv.flag2[i+8] = 0;
|
||||
485 7 s_recv.mode[i+8] = 2;
|
||||
486 7 s_recv.key_status[i+8] = 0x00;
|
||||
487 7 continue;
|
||||
488 7 }
|
||||
489 6 }
|
||||
490 5 }
|
||||
491 4 }
|
||||
492 3 g_answer.short_answer_flag=0x01;
|
||||
493 3 break;
|
||||
494 3 case USART_CMD_DEBUG_SET:
|
||||
495 3 g_answer.short_answer[UART_FMT_CMD]=USART_CMD_DEBUG_SET_A;
|
||||
496 3 if(debug)
|
||||
497 3 {
|
||||
498 4 PrintString1("debug");
|
||||
499 4 }
|
||||
500 3 debug = g_Usart.recv_buffer[7];
|
||||
501 3 g_answer.short_answer_flag=0x01;
|
||||
502 3 break;
|
||||
503 3 case Usart_CMD_Version:
|
||||
504 3 g_answer.version_answer[UART_FMT_CMD]=Usart_CMD_Version_A;
|
||||
505 3 g_answer.version_answer_flag=0x01;
|
||||
506 3 if(debug)
|
||||
507 3 {
|
||||
508 4 PrintString1("version");
|
||||
509 4 }
|
||||
510 3 break;
|
||||
511 3 }
|
||||
512 2 g_Usart.ok_flag=0;
|
||||
513 2 }
|
||||
514 1 }
|
||||
515
|
||||
516 void Usart_answer(void)
|
||||
517 {
|
||||
518 1 u8 i=0;
|
||||
519 1 u8 checksum=0;
|
||||
520 1 if(g_answer.long_answer_flag)
|
||||
521 1 {
|
||||
522 2 g_answer.long_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
523 2 g_answer.long_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
524 2 g_answer.long_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
525 2 g_answer.long_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
526 2 g_answer.long_answer[UART_FMT_LEN]=0x14;
|
||||
527 2 g_answer.long_answer[7] = s_recv.global_brightness;
|
||||
528 2 for(i=0;i<12;i++)
|
||||
529 2 {
|
||||
530 3 g_answer.long_answer[8+i] = s_pwm.currvalue[11-i];
|
||||
531 3 if(s_recv.key_status[i] == 0x01)
|
||||
532 3 {
|
||||
533 4 g_answer.long_answer[8+i] |= 0x80;
|
||||
534 4 }
|
||||
535 3 }
|
||||
536 2 checksum=sumfunc(g_answer.long_answer,0x14);
|
||||
537 2 g_answer.long_answer[UART_FMT_CKS]=checksum;
|
||||
538 2
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 10
|
||||
|
||||
539 2 Printbuffer3(g_answer.long_answer,0x14); //<2F><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ
|
||||
540 2
|
||||
541 2 if(debug)
|
||||
542 2 {
|
||||
543 3 // PrintString1("long answer");
|
||||
544 3 }
|
||||
545 2 g_answer.long_answer_flag=0;
|
||||
546 2 memset(g_Usart.recv_buffer,0,32);
|
||||
547 2 }
|
||||
548 1 if(g_answer.short_answer_flag)
|
||||
549 1 {
|
||||
550 2 g_answer.short_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
551 2 g_answer.short_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
552 2 g_answer.short_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
553 2 g_answer.short_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
554 2 g_answer.short_answer[UART_FMT_LEN]=0x07;
|
||||
555 2 checksum=sumfunc(g_answer.short_answer,0x07);
|
||||
556 2 g_answer.short_answer[UART_FMT_CKS]=checksum;
|
||||
557 2 Printbuffer3(g_answer.short_answer,0x07);
|
||||
558 2 if(debug)
|
||||
559 2 {
|
||||
560 3 PrintString1("short answer");
|
||||
561 3 }
|
||||
562 2
|
||||
563 2
|
||||
564 2 g_answer.short_answer_flag=0;
|
||||
565 2 memset(g_Usart.recv_buffer,0,32);
|
||||
566 2 }
|
||||
567 1
|
||||
568 1 if(g_answer.version_answer_flag)
|
||||
569 1 {
|
||||
570 2 g_answer.version_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
571 2 g_answer.version_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
572 2 g_answer.version_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
573 2 g_answer.version_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
574 2 g_answer.version_answer[UART_FMT_LEN]=0x09;
|
||||
575 2 g_answer.version_answer[UART_FMT_CMD+1]=Version_High;
|
||||
576 2 g_answer.version_answer[UART_FMT_CMD+2]=Version_Low;
|
||||
577 2
|
||||
578 2 checksum=sumfunc(g_answer.version_answer,0x09);
|
||||
579 2 g_answer.version_answer[UART_FMT_CKS]=checksum;
|
||||
580 2 Printbuffer3(g_answer.version_answer,0x09);
|
||||
581 2 if(debug)
|
||||
582 2 {
|
||||
583 3 PrintString1("version_answer");
|
||||
584 3 }
|
||||
585 2 g_answer.version_answer_flag=0;
|
||||
586 2 memset(g_Usart.recv_buffer,0,32);
|
||||
587 2 }
|
||||
588 1 memset(&g_answer,0,sizeof(g_answer));
|
||||
589 1 }
|
||||
590
|
||||
591 u8 sumfunc(u8* answer,u8 len)
|
||||
592 {
|
||||
593 1 u8 m = 0;
|
||||
594 1 u8 j;
|
||||
595 1 for (j = 0; j < len; j++)
|
||||
596 1 {
|
||||
597 2 if (5 == j) continue;
|
||||
598 2 m += *(answer+j);
|
||||
599 2 }
|
||||
600 1 return ~m;
|
||||
C51 COMPILER V9.01 UART_SET 12/15/2025 20:45:04 PAGE 11
|
||||
|
||||
601 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 4719 ----
|
||||
CONSTANT SIZE = 101 ----
|
||||
XDATA SIZE = 272 ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 1 7
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
60
Listings/WDT.lst
Normal file
60
Listings/WDT.lst
Normal file
@@ -0,0 +1,60 @@
|
||||
C51 COMPILER V9.01 WDT 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE WDT
|
||||
OBJECT MODULE PLACED IN .\Objects\WDT.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE WDT.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\WDT.l
|
||||
-st) OBJECT(.\Objects\WDT.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 /*---------------------------------------------------------------------*/
|
||||
2 /* --- STC MCU Limited ------------------------------------------------*/
|
||||
3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
4 /* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
7 /* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
9 /* --- QQ: 800003751 -------------------------------------------------*/
|
||||
10 /* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
11 /*---------------------------------------------------------------------*/
|
||||
12
|
||||
13 #include "WDT.h"
|
||||
14
|
||||
15 //========================================================================
|
||||
16 // <20><><EFBFBD><EFBFBD>: void WDT_Inilize(WDT_InitTypeDef *WDT)
|
||||
17 // <20><><EFBFBD><EFBFBD>: <20><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
18 // <20><><EFBFBD><EFBFBD>: WDT: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>WDT.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
19 // <20><><EFBFBD><EFBFBD>: none.
|
||||
20 // <20>汾: V1.0, 2020-09-16
|
||||
21 //========================================================================
|
||||
22 void WDT_Inilize(WDT_InitTypeDef *WDT)
|
||||
23 {
|
||||
24 1 if(WDT->WDT_Enable == ENABLE) WDT_CONTR = D_EN_WDT; //ʹ<>ܿ<EFBFBD><DCBF>Ź<EFBFBD>
|
||||
25 1
|
||||
26 1 WDT_PS_Set(WDT->WDT_PS); //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5> WDT_SCALE_2,WDT_SCALE_4,WDT_SCALE_8,WDT_SCALE_16,WDT
|
||||
-_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256
|
||||
27 1 if(WDT->WDT_IDLE_Mode == WDT_IDLE_STOP) WDT_CONTR &= ~0x08; //IDLEģʽֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
28 1 else WDT_CONTR |= 0x08; //IDLEģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
29 1 }
|
||||
30
|
||||
31 /********************* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD> *************************/
|
||||
32 void WDT_Clear (void)
|
||||
33 {
|
||||
34 1 WDT_CONTR |= D_CLR_WDT; // ι<><CEB9>
|
||||
35 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 45 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = ---- ----
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
183
Listings/key.lst
Normal file
183
Listings/key.lst
Normal file
@@ -0,0 +1,183 @@
|
||||
C51 COMPILER V9.01 KEY 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE KEY
|
||||
OBJECT MODULE PLACED IN .\Objects\key.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE key.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\key.l
|
||||
-st) OBJECT(.\Objects\key.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "key.h"
|
||||
2 #include "GPIO.h"
|
||||
3 #include "timer.h"
|
||||
4 #include "string.h"
|
||||
5 #include "pwm_control.h"
|
||||
6 KEY_t g_Key;
|
||||
7
|
||||
8 void Key_Init(void)
|
||||
9 {
|
||||
10 1 GPIO_InitTypeDef GPIO_InitStructure1; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
11 1 /***********************************1*******************************************/
|
||||
12 1 GPIO_InitStructure1.Pin = GPIO_Pin_4; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO 4
|
||||
13 1 GPIO_InitStructure1.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp
|
||||
14 1 GPIO_Inilize(GPIO_P4,&GPIO_InitStructure1); //<2F><>ʼ<EFBFBD><CABC>
|
||||
15 1 memset(&g_Key, 0, sizeof(g_Key));
|
||||
16 1 }
|
||||
17
|
||||
18 void Key_ScanTask(void)
|
||||
19 {
|
||||
20 1 u8 i;
|
||||
21 1 static u32 update_10ms = 0;
|
||||
22 1
|
||||
23 1 if (systick_1ms - update_10ms > 10)
|
||||
24 1 {
|
||||
25 2 update_10ms = systick_1ms;
|
||||
26 2
|
||||
27 2 for (i = 0; i < KEY_CHN_MAX; i++)
|
||||
28 2 {
|
||||
29 3 switch (g_Key.KEY_STA[i])
|
||||
30 3 {
|
||||
31 4 case KEY_STA_S0:
|
||||
32 4 if ( P44 == KEY_PRESS )
|
||||
33 4 {
|
||||
34 5 if (g_Key.delayCnt[i] < KEY_DELAY_COUNT)
|
||||
35 5 {
|
||||
36 6 g_Key.delayCnt[i]++;
|
||||
37 6 }
|
||||
38 5 else
|
||||
39 5 {
|
||||
40 6 g_Key.KEY_STA[i] = KEY_STA_S1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
41 6 g_Key.key_time[i] = 0;
|
||||
42 6 g_Key.delayCnt[i] = 0;
|
||||
43 6 }
|
||||
44 5 }
|
||||
45 4 else
|
||||
46 4 {
|
||||
47 5 g_Key.delayCnt[i] = 0;
|
||||
48 5 g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
49 5 g_Key.key_val[i] = KEY_VAL_NOT;
|
||||
50 5 }
|
||||
51 4 break;
|
||||
52 4 case KEY_STA_S1:
|
||||
53 4 g_Key.key_time[i] ++;
|
||||
54 4 if ( g_Key.key_time[i] < KEY_DELAY_COUNT_LONG )
|
||||
C51 COMPILER V9.01 KEY 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
55 4 {
|
||||
56 5 if ( P44 == KEY_LOOSEN ) //<2F>ɿ<EFBFBD>
|
||||
57 5 {
|
||||
58 6 g_Key.key_val[i] = KEY_VAL_SHORT_PRESS; //<2F>̰<EFBFBD><CCB0>ɿ<EFBFBD>
|
||||
59 6 g_Key.key_time[i] = 0;
|
||||
60 6 g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
61 6 }
|
||||
62 5 }
|
||||
63 4 else
|
||||
64 4 {
|
||||
65 5 g_Key.KEY_STA[i] = KEY_STA_S2;
|
||||
66 5 g_Key.key_time[i] = 0;
|
||||
67 5 g_Key.key_longPress[i] = KEY_VAL_SINGLE_LONG_PRESS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
68 5 g_Key.key_val[i] = KEY_VAL_CONT_LONG_PRESS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
69 5 }
|
||||
70 4 break;
|
||||
71 4
|
||||
72 4 case KEY_STA_S2:
|
||||
73 4 g_Key.key_longPress[i] = KEY_VAL_NOT;
|
||||
74 4 if ( P44 == KEY_LOOSEN )
|
||||
75 4 {
|
||||
76 5 g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
77 5 g_Key.key_val[i] = KEY_VAL_LONG_PRESS_LOOSEN; //<2F><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
|
||||
78 5 }
|
||||
79 4 break;
|
||||
80 4 }
|
||||
81 3 }
|
||||
82 2 }
|
||||
83 1 }
|
||||
84
|
||||
85
|
||||
86 void KEY_TEST(void)
|
||||
87 {
|
||||
88 1 u8 flag;
|
||||
89 1 if (g_Key.key_val[KEY_CH1] == KEY_VAL_SHORT_PRESS)
|
||||
90 1 {
|
||||
91 2 g_Key.key_val[KEY_CH1] = KEY_VAL_NOT;
|
||||
92 2 s_pwm.key_value++;
|
||||
93 2 switch (s_pwm.key_value)
|
||||
94 2 {
|
||||
95 3 case 1:
|
||||
96 3 s_pwm.currpwm[0] = 2000ul; //90%<25><><EFBFBD><EFBFBD>
|
||||
97 3 s_pwm.currvalue[0]=0x5A;
|
||||
98 3 break;
|
||||
99 3 case 2:
|
||||
100 3 s_pwm.currpwm[1] = 2000ul;
|
||||
101 3 s_pwm.currvalue[1]=0x5A;
|
||||
102 3 break;
|
||||
103 3 case 3:
|
||||
104 3 s_pwm.currpwm[2] = 2000ul;
|
||||
105 3 s_pwm.currvalue[2]=0x5A;
|
||||
106 3 break;
|
||||
107 3 case 4:
|
||||
108 3 s_pwm.currpwm[3] = 2000ul;
|
||||
109 3 s_pwm.currvalue[3]=0x5A;
|
||||
110 3 break;
|
||||
111 3 case 5:
|
||||
112 3 s_pwm.currpwm[4] = 2000ul;
|
||||
113 3 s_pwm.currvalue[4]=0x5A;
|
||||
114 3 break;
|
||||
115 3 case 6:
|
||||
116 3 s_pwm.currpwm[5] = 2000ul;
|
||||
C51 COMPILER V9.01 KEY 12/15/2025 20:45:04 PAGE 3
|
||||
|
||||
117 3 s_pwm.currvalue[5]=0x5A;
|
||||
118 3 break;
|
||||
119 3 case 7:
|
||||
120 3 s_pwm.currpwm[6] = 2000ul;
|
||||
121 3 s_pwm.currvalue[6]=0x5A;
|
||||
122 3 break;
|
||||
123 3 case 8:
|
||||
124 3 s_pwm.currpwm[7] = 2000ul;
|
||||
125 3 s_pwm.currvalue[7]=0x5A;
|
||||
126 3 break;
|
||||
127 3 case 9:
|
||||
128 3 s_pwm.currpwm[8] = 2000ul;
|
||||
129 3 s_pwm.currvalue[8]=0x5A;
|
||||
130 3 break;
|
||||
131 3 case 10:
|
||||
132 3 s_pwm.currpwm[9] = 2000ul;
|
||||
133 3 s_pwm.currvalue[9]=0x5A;
|
||||
134 3 break;
|
||||
135 3 case 11:
|
||||
136 3 s_pwm.currpwm[10] = 2000ul;
|
||||
137 3 s_pwm.currvalue[10]=0x5A;
|
||||
138 3 break;
|
||||
139 3 case 12:
|
||||
140 3 s_pwm.currpwm[11] = 2000ul;
|
||||
141 3 s_pwm.currvalue[11]=0x5A;
|
||||
142 3 break;
|
||||
143 3 case 13:
|
||||
144 3 for(flag=0;flag<12;flag++)
|
||||
145 3 {
|
||||
146 4 s_pwm.currpwm[flag] = PWM_MAX_VALUE;
|
||||
147 4 s_pwm.currvalue[flag]=0x00;
|
||||
148 4 }
|
||||
149 3 s_pwm.key_value = 0;
|
||||
150 3 break;
|
||||
151 3 default:
|
||||
152 3 break;
|
||||
153 3 }
|
||||
154 2 }
|
||||
155 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 553 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 10 2
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
162
Listings/main.lst
Normal file
162
Listings/main.lst
Normal file
@@ -0,0 +1,162 @@
|
||||
C51 COMPILER V9.01 MAIN 12/15/2025 20:45:03 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE MAIN
|
||||
OBJECT MODULE PLACED IN .\Objects\main.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\main
|
||||
-.lst) OBJECT(.\Objects\main.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "config.h"
|
||||
2 #include "gpio.h"
|
||||
3 #include "UART.h"
|
||||
4 #include "string.h"
|
||||
5 #include "UART_Set.h"
|
||||
6 #include "pwm_control.h"
|
||||
7 #include "Start_Init.h"
|
||||
8 #include "key.h"
|
||||
9 #include "WDT.h"
|
||||
10 /************* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> **************
|
||||
11
|
||||
12 <20><><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD><CCBB><EFBFBD>STC8H8K64UΪ<55><CEAA><EFBFBD><EFBFBD>оƬ<D0BE><C6AC>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>8<EFBFBD><38><EFBFBD>б<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ԣ<EFBFBD>STC8G<38><47>STC8Hϵ<48><CFB5>оƬ<D0BE><C6AC>ͨ<EFBFBD>òο<C3B2>.
|
||||
13
|
||||
14 ˫<><CBAB><EFBFBD><EFBFBD>ȫ˫<C8AB><CBAB><EFBFBD>жϷ<D0B6>ʽ<EFBFBD>շ<EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
15
|
||||
16 ͨ<><CDA8>PC<50><43>MCU<43><55><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, MCU<43>յ<EFBFBD><D5B5><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><DAB0>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ʣ<EFBFBD>115200,N,8,1.
|
||||
17
|
||||
18 ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UART.h ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UART1~UART4 <20><><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬͨ<CDAC><CDA8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ͨ<EFBFBD>š<EFBFBD>
|
||||
19
|
||||
20 <20>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>1Tģʽ(<28><><EFBFBD>ǵͲ<C7B5><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>12T)<29><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD><DFBE>ȡ<EFBFBD>
|
||||
21
|
||||
22 <20><><EFBFBD><EFBFBD>ʱ, ѡ<><D1A1>ʱ<EFBFBD><CAB1> 22.1184MHz (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"config.h"<22><><EFBFBD><EFBFBD>).
|
||||
23
|
||||
24
|
||||
25 /******************* IO<49><4F><EFBFBD>ú<EFBFBD><C3BA><EFBFBD> *******************/
|
||||
26
|
||||
27
|
||||
28 void GPIO1_config(void)
|
||||
29 {
|
||||
30 1 GPIO_InitTypeDef GPIO_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
31 1
|
||||
32 1 GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
33 1 GPIO_InitStructure.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O
|
||||
-UT_PP
|
||||
34 1 GPIO_Inilize(GPIO_P3,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
35 1 }
|
||||
36
|
||||
37 /*************** <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *****************/
|
||||
38 void UART1_config(void)
|
||||
39 {
|
||||
40 1 COMx_InitDefine COMx_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
41 1 COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART
|
||||
-_9bit_BRTx
|
||||
42 1 COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //ʹ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>, BRT_Timer1, BRT_Timer2 (ע<><D7A2>: <20><><EFBFBD><EFBFBD>2<EFBFBD>̶<EFBFBD>ʹ
|
||||
-<2D><>BRT_Timer2)
|
||||
43 1 COMx_InitStructure.UART_BaudRate = 115200; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, һ<><D2BB> 110 ~ 115200
|
||||
44 1 COMx_InitStructure.UART_RxEnable = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
45 1 COMx_InitStructure.BaudRateDouble = DISABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD>ʼӱ<CABC>, ENABLE<4C><45>DISABLE
|
||||
46 1 COMx_InitStructure.UART_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
47 1 COMx_InitStructure.UART_Priority = Priority_0; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priori
|
||||
-ty_2,Priority_3
|
||||
48 1 COMx_InitStructure.UART_P_SW = UART1_SW_P30_P31; //<2F>л<EFBFBD><D0BB>˿<EFBFBD>, UART1_SW_P30_P31,UART1_SW_P36_P37,UAR
|
||||
-T1_SW_P16_P17,UART1_SW_P43_P44
|
||||
49 1 UART_Configuration(UART1, &COMx_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 UART1,UART2,UART3,UART4
|
||||
C51 COMPILER V9.01 MAIN 12/15/2025 20:45:03 PAGE 2
|
||||
|
||||
50 1
|
||||
51 1 //PrintString1("STC8H8K64U UART1 Test Programme!\r\n"); //UART1<54><31><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
52 1 }
|
||||
53
|
||||
54 /********************WDT INT<4E><54><EFBFBD><EFBFBD> ********************/
|
||||
55 void WDT_config(void)
|
||||
56 {
|
||||
57 1 WDT_InitTypeDef WDT_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
58 1
|
||||
59 1 WDT_InitStructure.WDT_Enable = ENABLE; //<2F>ж<EFBFBD>ʹ<EFBFBD><CAB9> ENABLE<4C><45>DISABLE
|
||||
60 1 WDT_InitStructure.WDT_IDLE_Mode = WDT_IDLE_STOP; //IDLEģʽ<C4A3>Ƿ<EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD> WDT_IDLE_STOP,WDT_IDLE_RUN
|
||||
61 1 WDT_InitStructure.WDT_PS = WDT_SCALE_32; //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5> WDT_SCALE_2,WDT_SCALE_4,WDT
|
||||
-_SCALE_8,WDT_SCALE_16,WDT_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256
|
||||
62 1 WDT_Inilize(&WDT_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
63 1 }
|
||||
64
|
||||
65 u8 count_flag=0;
|
||||
66 void main(void)
|
||||
67 {
|
||||
68 1 GPIO_config();
|
||||
69 1 UART3_config();
|
||||
70 1 Start_Init();
|
||||
71 1 pwm_config();
|
||||
72 1 Timer2_Init_1ms();
|
||||
73 1 Key_Init();
|
||||
74 1 GPIO1_config();
|
||||
75 1 UART1_config();
|
||||
76 1 WDT_config(); //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>629ms<6D><73>λ
|
||||
77 1
|
||||
78 1 PCON &= ~POF; //<2F><><EFBFBD><EFBFBD>LVD<56>жϱ<D0B6>־λ
|
||||
79 1 RSTCFG = 0x41; //LVD:2.4V<EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD>λ
|
||||
80 1 EA = 1;
|
||||
81 1
|
||||
82 1 if(debug)
|
||||
83 1 {
|
||||
84 2 PrintString1("MCU Start");
|
||||
85 2 }
|
||||
86 1
|
||||
87 1 while (1)
|
||||
88 1 {
|
||||
89 2 WDT_Clear(); //<2F>幷
|
||||
90 2 count_flag++;
|
||||
91 2
|
||||
92 2 //Ϊ<>˱<EFBFBD>֤ij<D6A4><C4B3>ѹ2.2V<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
93 2 if(count_flag==1)
|
||||
94 2 {
|
||||
95 3 P10=1;
|
||||
96 3 }
|
||||
97 2 if(count_flag==8)
|
||||
98 2 {
|
||||
99 3 P10=0;
|
||||
100 3 }
|
||||
101 2 if(count_flag==10)
|
||||
102 2 {
|
||||
103 3 count_flag=0;
|
||||
104 3 }
|
||||
105 2
|
||||
106 2 Usart_judge_Data();
|
||||
107 2
|
||||
108 2 Usart_Deal_Data();
|
||||
109 2
|
||||
110 2 deal_command1();
|
||||
C51 COMPILER V9.01 MAIN 12/15/2025 20:45:03 PAGE 3
|
||||
|
||||
111 2
|
||||
112 2 deal_command2();
|
||||
113 2
|
||||
114 2 // checkpwm();
|
||||
115 2
|
||||
116 2 show_light();
|
||||
117 2
|
||||
118 2 Usart_answer();
|
||||
119 2
|
||||
120 2 Key_ScanTask();
|
||||
121 2
|
||||
122 2 KEY_TEST();
|
||||
123 2
|
||||
124 2 }
|
||||
125 1 }
|
||||
126
|
||||
127
|
||||
128
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 175 ----
|
||||
CONSTANT SIZE = 10 ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 1 17
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
421
Listings/pwm_control.lst
Normal file
421
Listings/pwm_control.lst
Normal file
@@ -0,0 +1,421 @@
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE PWM_CONTROL
|
||||
OBJECT MODULE PLACED IN .\Objects\pwm_control.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE pwm_control.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listin
|
||||
-gs\pwm_control.lst) OBJECT(.\Objects\pwm_control.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 #include "pwm_control.h"
|
||||
2 #include "GPIO.h"
|
||||
3 #include "STC8xxxx.h"
|
||||
4 #include "PWM15bit.h"
|
||||
5 #include "timer.h"
|
||||
6 #include "UART_Set.h"
|
||||
7 #include "string.h"
|
||||
8 S_PWM s_pwm;
|
||||
9 /*
|
||||
10 *1.<2E><><EFBFBD><EFBFBD>5.0/5.1<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||||
11 *2.<2E><>ʼ<EFBFBD><CABC>PWM<57><4D><EFBFBD><EFBFBD>
|
||||
12 *3.LED_DRV_12V_EN<45>õ<EFBFBD>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
13 */
|
||||
14 /******************* IO<49><4F><EFBFBD>ú<EFBFBD><C3BA><EFBFBD> *******************/
|
||||
15 void GPIO_config(void)
|
||||
16 {
|
||||
17 1 GPIO_InitTypeDef GPIO_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
18 1 /***********************************1*******************************************/
|
||||
19 1 GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
20 1 GPIO_InitStructure.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O
|
||||
-UT_PP
|
||||
21 1 GPIO_Inilize(GPIO_P5,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
22 1
|
||||
23 1 /***********************************2*******************************************/
|
||||
24 1 GPIO_InitStructure.Pin = GPIO_Pin_All; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
25 1 GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O
|
||||
-UT_PP
|
||||
26 1 GPIO_Inilize(GPIO_P0,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
27 1
|
||||
28 1 GPIO_InitStructure.Pin = GPIO_Pin_Left; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
29 1 GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O
|
||||
-UT_PP
|
||||
30 1 GPIO_Inilize(GPIO_P2,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
31 1
|
||||
32 1 /***********************************3*******************************************/
|
||||
33 1 GPIO_InitStructure.Pin = GPIO_Pin_0; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
34 1 GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_O
|
||||
-UT_PP
|
||||
35 1 GPIO_Inilize(GPIO_P1,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
36 1 }
|
||||
37
|
||||
38 void pwm_config(void)
|
||||
39 {
|
||||
40 1 u8 i;
|
||||
41 1 PWM15_InitTypeDef PWM15_InitStructure;
|
||||
42 1
|
||||
43 1 PWM15_InitStructure.PWM_Enable = ENABLE; //PWMʹ<4D><CAB9>, ENABLE, DISABLE
|
||||
44 1 PWM15_InitStructure.PWM_Period = 0x04E2; //PWM<57><4D><EFBFBD><EFBFBD>, 1250,Ƶ<><C6B5>Ϊ16khz
|
||||
45 1 PWM15_InitStructure.PWM_Clock_Sel = PWMn_CLK_SYS; //ʱ<><CAB1>Դѡ<D4B4><D1A1>, PWMn_CLK_SYS, PWMn_CLK_TM2
|
||||
46 1 PWM15_InitStructure.PWM_Clock_PS = 0; //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>(PS+1<><31>Ƶ), 0~15
|
||||
47 1 PWM15_InitStructure.PWM_Counter = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE, DISABLE
|
||||
48 1
|
||||
49 1 PWM15_Init(PWM0,&PWM15_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PWM0
|
||||
50 1 PWM15_Init(PWM2,&PWM15_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PWM2
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
51 1
|
||||
52 1 PWM15Duty(PWM00,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
53 1 PWM15Duty(PWM01,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
54 1 PWM15Duty(PWM02,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
55 1 PWM15Duty(PWM03,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
56 1 PWM15Duty(PWM04,initial_Val);
|
||||
57 1 PWM15Duty(PWM05,initial_Val);
|
||||
58 1 PWM15Duty(PWM06,initial_Val);
|
||||
59 1 PWM15Duty(PWM07,initial_Val);
|
||||
60 1
|
||||
61 1 PWM15Duty(PWM20,initial_Val);
|
||||
62 1 PWM15Duty(PWM21,initial_Val);
|
||||
63 1 PWM15Duty(PWM22,initial_Val);
|
||||
64 1 PWM15Duty(PWM23,initial_Val);
|
||||
65 1
|
||||
66 1 memset(&s_pwm,0,sizeof(s_pwm));
|
||||
67 1 for(i=0;i<12;i++)
|
||||
68 1 {
|
||||
69 2 s_pwm.currpwm[i]=initial_Val;
|
||||
70 2 }
|
||||
71 1 PWMChannelCtrl(PWM00,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
72 1 PWMChannelCtrl(PWM01,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
73 1 PWMChannelCtrl(PWM02,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
74 1 PWMChannelCtrl(PWM03,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
75 1 PWMChannelCtrl(PWM04,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
76 1 PWMChannelCtrl(PWM05,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
77 1 PWMChannelCtrl(PWM06,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
78 1 PWMChannelCtrl(PWM07,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
79 1
|
||||
80 1 PWMChannelCtrl(PWM20,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
81 1 PWMChannelCtrl(PWM21,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
82 1 PWMChannelCtrl(PWM22,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
83 1 PWMChannelCtrl(PWM23,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
-<2D><><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
84 1
|
||||
85 1 }
|
||||
86
|
||||
87
|
||||
88 //10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
89 void deal_command1(void)
|
||||
90 {
|
||||
91 1 int i=0;
|
||||
92 1 static u32 systick_command1 = 0;
|
||||
93 1
|
||||
94 1 if (systick_1ms - systick_command1 >= 10)
|
||||
95 1 {
|
||||
96 2 systick_command1 = systick_1ms;
|
||||
97 2 for (i = 0; i < 12; i++)
|
||||
98 2 {
|
||||
99 3 if (s_recv.flag1[i])
|
||||
100 3 {
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 3
|
||||
|
||||
101 4 if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
102 4 {
|
||||
103 5 //s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i];
|
||||
104 5 s_pwm.doublecurrpwm[i] += s_pwm.every_change_10ms[i];
|
||||
105 5 s_pwm.currpwm[i] = (u16)s_pwm.doublecurrpwm[i];
|
||||
106 5
|
||||
107 5 if(s_recv.global_brightness==0)
|
||||
108 5 {
|
||||
109 6 s_pwm.currvalue[i]=0;
|
||||
110 6 }
|
||||
111 5 else
|
||||
112 5 {
|
||||
113 6 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALU
|
||||
-E / s_recv.global_brightness;
|
||||
114 6 }
|
||||
115 5
|
||||
116 5 if ( s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
117 5 {
|
||||
118 6 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
119 6 }
|
||||
120 5 }
|
||||
121 4
|
||||
122 4
|
||||
123 4 //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4>ڵ<EFBFBD>ǰֵʱ
|
||||
124 4 if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
125 4 {
|
||||
126 5 //s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i];
|
||||
127 5 s_pwm.doublecurrpwm[i] -= s_pwm.every_change_10ms[i];
|
||||
128 5 s_pwm.currpwm[i] = (u16)s_pwm.doublecurrpwm[i];
|
||||
129 5
|
||||
130 5 if(s_recv.global_brightness==0)
|
||||
131 5 {
|
||||
132 6 s_pwm.currvalue[i]=0;
|
||||
133 6 }
|
||||
134 5 else
|
||||
135 5 {
|
||||
136 6 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_
|
||||
-brightness;
|
||||
137 6 }
|
||||
138 5
|
||||
139 5 if (s_pwm.currpwm[i] < s_pwm.wanttopwm[i] + s_pwm.every_change_10ms[i])
|
||||
140 5 {
|
||||
141 6 s_pwm.currpwm[i] = 0;
|
||||
142 6 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
143 6 }
|
||||
144 5 }
|
||||
145 4
|
||||
146 4
|
||||
147 4 if (s_pwm.wanttopwm[i] == s_pwm.currpwm[i])
|
||||
148 4 {
|
||||
149 5 s_pwm.currvalue[i] = s_recv.B_Ch[i];
|
||||
150 5 s_recv.flag1[i] = 0;
|
||||
151 5 }
|
||||
152 4 }
|
||||
153 3 }
|
||||
154 2 }
|
||||
155 1 }
|
||||
156
|
||||
157 void deal_command2(void)
|
||||
158 {
|
||||
159 1 int i=0;
|
||||
160 1 static u32 systick_command2 = 0;
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 4
|
||||
|
||||
161 1 if (systick_1ms - systick_command2 >= 10)
|
||||
162 1 {
|
||||
163 2 systick_command2 = systick_1ms;
|
||||
164 2 for (i = 0; i < 12; i++)
|
||||
165 2 {
|
||||
166 3 if (s_recv.flag2[i])
|
||||
167 3 {
|
||||
168 4 switch (s_recv.mode[i])
|
||||
169 4 {
|
||||
170 5 //<2F><><EFBFBD><EFBFBD>ֹͣģʽ
|
||||
171 5 case 0x00:
|
||||
172 5 //<2F><><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD>
|
||||
173 5 if (s_recv.forward[i] == 0x00)
|
||||
174 5 {
|
||||
175 6 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_min * PWM_MAX_VALUE * s_recv.global_brightness
|
||||
- / 100 / 100 * s_recv.key_status[i];
|
||||
176 6 s_pwm.currpwm[i] += s_recv.pwm_step[i];
|
||||
177 6 if(s_recv.global_brightness==0)
|
||||
178 6 {
|
||||
179 7 s_pwm.currvalue[i]=0;
|
||||
180 7 }
|
||||
181 6 else
|
||||
182 6 {
|
||||
183 7 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_re
|
||||
-cv.global_brightness;
|
||||
184 7 }
|
||||
185 6 if (s_pwm.currpwm[i] >= s_pwm.wanttopwm[i])
|
||||
186 6 {
|
||||
187 7 s_recv.flag2[i] = 0;
|
||||
188 7 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
189 7 s_pwm.currvalue[i] = s_recv.B_min; //<2F><><EFBFBD>ڻظ<DABB><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
190 7 }
|
||||
191 6 }
|
||||
192 5 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
193 5 if (s_recv.forward[i] == 0x01)
|
||||
194 5 {
|
||||
195 6 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_max * PWM_MAX_VALUE * s_recv.global_brightness
|
||||
- / 100 / 100 * s_recv.key_status[i];
|
||||
196 6 if (s_pwm.currpwm[i] <= s_pwm.wanttopwm[i] + s_recv.pwm_step[i])
|
||||
197 6 {
|
||||
198 7 s_recv.flag2[i] = 0;
|
||||
199 7 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
200 7 s_pwm.currvalue[i] = s_recv.B_max;
|
||||
201 7 }
|
||||
202 6 else
|
||||
203 6 {
|
||||
204 7 s_pwm.currpwm[i] -= s_recv.pwm_step[i];
|
||||
205 7 if(s_recv.global_brightness==0)
|
||||
206 7 {
|
||||
207 8 s_pwm.currvalue[i]=0;
|
||||
208 8 }
|
||||
209 7 else
|
||||
210 7 {
|
||||
211 8 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_b
|
||||
-rightness;
|
||||
212 8 }
|
||||
213 7 }
|
||||
214 6 }
|
||||
215 5 break;
|
||||
216 5
|
||||
217 5 //˫<><CBAB>ѭ<EFBFBD><D1AD>ģʽ
|
||||
218 5 case 0x01:
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 5
|
||||
|
||||
219 5 //<2F>ݼ<EFBFBD>
|
||||
220 5 if (s_recv.forward[i] == 0x00)
|
||||
221 5 {
|
||||
222 6 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_min * PWM_MAX_VALUE * s_recv.global_brightness
|
||||
- / 100 / 100 * s_recv.key_status[i];
|
||||
223 6 s_pwm.currpwm[i] += s_recv.pwm_step[i];
|
||||
224 6 if(s_recv.global_brightness==0)
|
||||
225 6 {
|
||||
226 7 s_pwm.currvalue[i]=0;
|
||||
227 7 }
|
||||
228 6 else
|
||||
229 6 {
|
||||
230 7 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_re
|
||||
-cv.global_brightness;
|
||||
231 7 }
|
||||
232 6 if (s_pwm.currpwm[i] >= s_pwm.wanttopwm[i])
|
||||
233 6 {
|
||||
234 7 s_recv.forward[i] = 0x01;
|
||||
235 7 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
236 7 s_pwm.currvalue[i] = s_recv.B_min; //<2F><><EFBFBD>ڻظ<DABB><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
237 7 }
|
||||
238 6 }
|
||||
239 5 //<2F><><EFBFBD><EFBFBD>
|
||||
240 5 if (s_recv.forward[i] == 0x01)
|
||||
241 5 {
|
||||
242 6 s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_max * PWM_MAX_VALUE * s_recv.global_brightness
|
||||
- / 100 / 100 * s_recv.key_status[i];
|
||||
243 6 if (s_pwm.currpwm[i] <= s_pwm.wanttopwm[i] + s_recv.pwm_step[i])
|
||||
244 6 {
|
||||
245 7 s_recv.forward[i] = 0x00;
|
||||
246 7 s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
247 7 s_pwm.currvalue[i] = s_recv.B_max;
|
||||
248 7 }
|
||||
249 6 else
|
||||
250 6 {
|
||||
251 7 s_pwm.currpwm[i] -= s_recv.pwm_step[i];
|
||||
252 7 if(s_recv.global_brightness==0)
|
||||
253 7 {
|
||||
254 8 s_pwm.currvalue[i]=0;
|
||||
255 8 }
|
||||
256 7 else
|
||||
257 7 {
|
||||
258 8 s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_b
|
||||
-rightness;
|
||||
259 8 }
|
||||
260 7 }
|
||||
261 6 }
|
||||
262 5 break;
|
||||
263 5 case 0x02:
|
||||
264 5 //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
265 5 s_recv.flag2[i] = 0;
|
||||
266 5 break;
|
||||
267 5 }
|
||||
268 4 }
|
||||
269 3 }
|
||||
270 2 }
|
||||
271 1 }
|
||||
272
|
||||
273
|
||||
274 //ֱ<>ӹص<D3B9><D8B5><EFBFBD>,<2C><><EFBFBD><EFBFBD>¼״̬
|
||||
275 void Close_Light(u8 i)
|
||||
276 {
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 6
|
||||
|
||||
277 1 s_pwm.currpwm[i]=20001ul; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>dz<EFBFBD><C7B3><EFBFBD><EFBFBD>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD>
|
||||
278 1 }
|
||||
279
|
||||
280 //<2F><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
281 void Open_Light(u8 pin)
|
||||
282 {
|
||||
283 1 s_pwm.currpwm[pin] = PWM_MAX_VALUE - s_pwm.currvalue[pin] * PWM_MAX_VALUE * s_recv.global_brightness / 10
|
||||
-0 / 100;
|
||||
284 1 }
|
||||
285
|
||||
286 void PWM_write(u8 i, u16 Val)
|
||||
287 {
|
||||
288 1 switch (i)
|
||||
289 1 {
|
||||
290 2 case 0:
|
||||
291 2 PWM15Duty(PWM07,Val);
|
||||
292 2 break;
|
||||
293 2 case 1:
|
||||
294 2 PWM15Duty(PWM06,Val);
|
||||
295 2 break;
|
||||
296 2 case 2:
|
||||
297 2 PWM15Duty(PWM05,Val);
|
||||
298 2 break;
|
||||
299 2 case 3:
|
||||
300 2 PWM15Duty(PWM04,Val);
|
||||
301 2 break;
|
||||
302 2 case 4:
|
||||
303 2 PWM15Duty(PWM03,Val);
|
||||
304 2 break;
|
||||
305 2 case 5:
|
||||
306 2 PWM15Duty(PWM02,Val);
|
||||
307 2 break;
|
||||
308 2 case 6:
|
||||
309 2 PWM15Duty(PWM01,Val);
|
||||
310 2 break;
|
||||
311 2 case 7:
|
||||
312 2 PWM15Duty(PWM00,Val);
|
||||
313 2 break;
|
||||
314 2 case 8:
|
||||
315 2 PWM15Duty(PWM23,Val);
|
||||
316 2 break;
|
||||
317 2 case 9:
|
||||
318 2 PWM15Duty(PWM22,Val);
|
||||
319 2 break;
|
||||
320 2 case 10:
|
||||
321 2 PWM15Duty(PWM21,Val);
|
||||
322 2 break;
|
||||
323 2 case 11:
|
||||
324 2 PWM15Duty(PWM20,Val);
|
||||
325 2 break;
|
||||
326 2 }
|
||||
327 1 }
|
||||
328 void show_light(void)
|
||||
329 {
|
||||
330 1 int i;
|
||||
331 1 for (i = 0; i < 12; i++)
|
||||
332 1 {
|
||||
333 2 if(s_pwm.currpwm[i]==20000ul)
|
||||
334 2 {
|
||||
335 3 Close_Light(i);
|
||||
336 3 }
|
||||
337 2 else
|
||||
C51 COMPILER V9.01 PWM_CONTROL 12/15/2025 20:45:04 PAGE 7
|
||||
|
||||
338 2 {
|
||||
339 3 PWM_write(i, s_pwm.currpwm[i]);
|
||||
340 3 }
|
||||
341 2 }
|
||||
342 1 }
|
||||
343
|
||||
344 //void checkpwm(void)
|
||||
345 //{
|
||||
346 // int i;
|
||||
347 // for (i = 0; i < 12; i++)
|
||||
348 // {
|
||||
349 // if ((s_recv.flag1[i] == 0) && (s_recv.flag2[i] == 0) && (s_recv.changeflag == 1))
|
||||
350 // {
|
||||
351 // if (s_pwm.wanttopwmflash[i] != s_pwm.currpwm[i])
|
||||
352 // {
|
||||
353 // s_pwm.currpwm[i] = s_pwm.wanttopwmflash[i];
|
||||
354 // }
|
||||
355 // }
|
||||
356 // }
|
||||
357 // s_recv.changeflag = 0;
|
||||
358 //}
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 3842 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = 241 ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 8 18
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
190
Listings/timer.lst
Normal file
190
Listings/timer.lst
Normal file
@@ -0,0 +1,190 @@
|
||||
C51 COMPILER V9.01 TIMER 12/15/2025 20:45:04 PAGE 1
|
||||
|
||||
|
||||
C51 COMPILER V9.01, COMPILATION OF MODULE TIMER
|
||||
OBJECT MODULE PLACED IN .\Objects\timer.obj
|
||||
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE timer.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listings\tim
|
||||
-er.lst) OBJECT(.\Objects\timer.obj)
|
||||
|
||||
line level source
|
||||
|
||||
1 /*---------------------------------------------------------------------*/
|
||||
2 /* --- STC MCU Limited ------------------------------------------------*/
|
||||
3 /* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
4 /* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
5 /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
6 /* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
7 /* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
8 /* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
9 /* --- QQ: 800003751 -------------------------------------------------*/
|
||||
10 /* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
11 /*---------------------------------------------------------------------*/
|
||||
12
|
||||
13 /************* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> **************
|
||||
14
|
||||
15 <20><><EFBFBD>ļ<EFBFBD>ΪSTC8ϵ<38>еĶ<D0B5>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>жϳ<D0B6><CFB3><EFBFBD>,<2C>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><DEB8>Լ<EFBFBD><D4BC><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>жϳ<D0B6><CFB3><EFBFBD>.
|
||||
16
|
||||
17 ******************************************/
|
||||
18
|
||||
19 #include "timer.h"
|
||||
20 u32 systick_1ms=0;
|
||||
21 /********************* Timer0<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
22 void timer0_int (void) interrupt TIMER0_VECTOR
|
||||
23 {
|
||||
24 1 P67 = ~P67;
|
||||
25 1 }
|
||||
26
|
||||
27 /********************* Timer1<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
28 void timer1_int (void) interrupt TIMER1_VECTOR
|
||||
29 {
|
||||
30 1 P66 = ~P66;
|
||||
31 1 }
|
||||
32
|
||||
33 /********************* Timer2<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
34 void timer2_int (void) interrupt TIMER2_VECTOR
|
||||
35 {
|
||||
36 1 systick_1ms++;
|
||||
37 1 }
|
||||
38
|
||||
39 /********************* Timer3<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
40 void timer3_int (void) interrupt TIMER3_VECTOR
|
||||
41 {
|
||||
42 1
|
||||
43 1 }
|
||||
44
|
||||
45 /********************* Timer4<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
46 void timer4_int (void) interrupt TIMER4_VECTOR
|
||||
47 {
|
||||
48 1 P63 = ~P63;
|
||||
49 1 }
|
||||
50
|
||||
51
|
||||
52 //========================================================================
|
||||
53 // <20><><EFBFBD><EFBFBD>: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
|
||||
54 // <20><><EFBFBD><EFBFBD>: <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
C51 COMPILER V9.01 TIMER 12/15/2025 20:45:04 PAGE 2
|
||||
|
||||
55 // <20><><EFBFBD><EFBFBD>: TIMx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>timer.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
56 // <20><><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0, <20>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1,<2C><><EFBFBD><EFBFBD>2.
|
||||
57 // <20>汾: V1.0, 2012-10-22
|
||||
58 //========================================================================
|
||||
59 u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
|
||||
60 {
|
||||
61 1 if(TIM > Timer4) return 1; //<2F>ղ<EFBFBD><D5B2><EFBFBD>
|
||||
62 1
|
||||
63 1 if(TIM == Timer0)
|
||||
64 1 {
|
||||
65 2 Timer0_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
66 2 if(TIMx->TIM_Interrupt == ENABLE) Timer0_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
67 2 else Timer0_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
68 2 if(TIMx->TIM_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
69 2 Timer0_Priority(TIMx->TIM_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_
|
||||
-3
|
||||
70 2
|
||||
71 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
72 2 TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //<2F><><EFBFBD><EFBFBD>ģʽ,0: 16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, 1: 16λ<36><CEBB>ʱ/<2F><><EFBFBD><EFBFBD>, 2: 8λ<38>Զ<EFBFBD><D4B6><EFBFBD>װ
|
||||
73 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer0_12T(); //12T
|
||||
74 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer0_1T(); //1T
|
||||
75 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer0_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
76 2 else Timer0_AsTimer(); //<2F><>ʱ
|
||||
77 2 if(TIMx->TIM_ClkOut == ENABLE) Timer0_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
78 2 else Timer0_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
79 2
|
||||
80 2 T0_Load(TIMx->TIM_Value);
|
||||
81 2 if(TIMx->TIM_Run == ENABLE) Timer0_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
82 2 return 0; //<2F>ɹ<EFBFBD>
|
||||
83 2 }
|
||||
84 1
|
||||
85 1 if(TIM == Timer1)
|
||||
86 1 {
|
||||
87 2 Timer1_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
88 2 if(TIMx->TIM_Interrupt == ENABLE) Timer1_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
89 2 else Timer1_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
90 2 if(TIMx->TIM_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
91 2 Timer1_Priority(TIMx->TIM_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_
|
||||
-3
|
||||
92 2 if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
93 2 TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //<2F><><EFBFBD><EFBFBD>ģʽ,0: 16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, 1: 16λ<36><CEBB>ʱ/<2F><><EFBFBD><EFBFBD>, 2: 8λ<38>Զ<EFBFBD><D4B6><EFBFBD>װ
|
||||
94 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer1_12T(); //12T
|
||||
95 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer1_1T(); //1T
|
||||
96 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer1_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
97 2 else Timer1_AsTimer(); //<2F><>ʱ
|
||||
98 2 if(TIMx->TIM_ClkOut == ENABLE) Timer1_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
99 2 else Timer1_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
100 2
|
||||
101 2 T1_Load(TIMx->TIM_Value);
|
||||
102 2 if(TIMx->TIM_Run == ENABLE) Timer1_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
103 2 return 0; //<2F>ɹ<EFBFBD>
|
||||
104 2 }
|
||||
105 1
|
||||
106 1 if(TIM == Timer2) //Timer2,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
107 1 {
|
||||
108 2 Timer2_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
109 2 if(TIMx->TIM_Interrupt == ENABLE) Timer2_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
110 2 else Timer2_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
111 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
112 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer2_12T(); //12T
|
||||
113 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer2_1T(); //1T
|
||||
114 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer2_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
C51 COMPILER V9.01 TIMER 12/15/2025 20:45:04 PAGE 3
|
||||
|
||||
115 2 else Timer2_AsTimer(); //<2F><>ʱ
|
||||
116 2 if(TIMx->TIM_ClkOut == ENABLE) Timer2_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
117 2 else Timer2_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
118 2
|
||||
119 2 T2_Load(TIMx->TIM_Value);
|
||||
120 2 if(TIMx->TIM_Run == ENABLE) Timer2_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
121 2 return 0; //<2F>ɹ<EFBFBD>
|
||||
122 2 }
|
||||
123 1
|
||||
124 1 if(TIM == Timer3) //Timer3,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
125 1 {
|
||||
126 2 Timer3_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
127 2 if(TIMx->TIM_Interrupt == ENABLE) Timer3_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
128 2 else Timer3_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
129 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
130 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer3_12T(); //12T
|
||||
131 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer3_1T(); //1T
|
||||
132 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer3_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
133 2 else Timer3_AsTimer(); //<2F><>ʱ
|
||||
134 2 if(TIMx->TIM_ClkOut == ENABLE) Timer3_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
135 2 else Timer3_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
136 2
|
||||
137 2 T3_Load(TIMx->TIM_Value);
|
||||
138 2 if(TIMx->TIM_Run == ENABLE) Timer3_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
139 2 return 0; //<2F>ɹ<EFBFBD>
|
||||
140 2 }
|
||||
141 1
|
||||
142 1 if(TIM == Timer4) //Timer3,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
143 1 {
|
||||
144 2 Timer4_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
145 2 if(TIMx->TIM_Interrupt == ENABLE) Timer4_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
146 2 else Timer4_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
147 2 if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
148 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer4_12T(); //12T
|
||||
149 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer4_1T(); //1T
|
||||
150 2 if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer4_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
151 2 else Timer4_AsTimer(); //<2F><>ʱ
|
||||
152 2 if(TIMx->TIM_ClkOut == ENABLE) Timer4_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
153 2 else Timer4_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
154 2
|
||||
155 2 T4_Load(TIMx->TIM_Value);
|
||||
156 2 if(TIMx->TIM_Run == ENABLE) Timer4_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
157 2 return 0; //<2F>ɹ<EFBFBD>
|
||||
158 2 }
|
||||
159 1 return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
160 1 }
|
||||
|
||||
|
||||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||||
CODE SIZE = 795 ----
|
||||
CONSTANT SIZE = ---- ----
|
||||
XDATA SIZE = ---- ----
|
||||
PDATA SIZE = ---- ----
|
||||
DATA SIZE = 4 ----
|
||||
IDATA SIZE = ---- ----
|
||||
BIT SIZE = ---- ----
|
||||
END OF MODULE INFORMATION.
|
||||
|
||||
|
||||
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
||||
BIN
Objects/BLV_C12_Dimm_V19
Normal file
BIN
Objects/BLV_C12_Dimm_V19
Normal file
Binary file not shown.
54
Objects/BLV_C12_Dimm_V19.build_log.htm
Normal file
54
Objects/BLV_C12_Dimm_V19.build_log.htm
Normal file
@@ -0,0 +1,54 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1><EFBFBD>Vision Build Log</h1>
|
||||
<h2>Tool Versions:</h2>
|
||||
IDE-Version: <20><>Vision V5.29.0.0
|
||||
Copyright (C) 2019 ARM Ltd and ARM Germany GmbH. All rights reserved.
|
||||
License Information: cc cc, cc, LIC=9W1BF-6PVU2-D80FM-XPSKK-ZUPXX-GN4UD
|
||||
|
||||
Tool Versions:
|
||||
Toolchain: PK51 Prof. Developers Kit Version: 9.01
|
||||
Toolchain Path: D:\Keil_v5\C51\BIN
|
||||
C Compiler: C51.exe V9.01
|
||||
Assembler: A51.exe V8.02
|
||||
Linker/Locator: BL51.exe V6.22
|
||||
Library Manager: LIB51.exe V4.24
|
||||
Hex Converter: OH51.exe V2.6
|
||||
CPU DLL: S8051.DLL V3.72
|
||||
Dialog DLL: DP51.DLL V2.59
|
||||
Target DLL: STCMON51.DLL V0, 1, 0, 17
|
||||
Dialog DLL: TP51.DLL V2.58
|
||||
|
||||
<h2>Project:</h2>
|
||||
E:\Git_Project_Sourcode\RCU_C12_Dimming\light_V19.uvproj
|
||||
Project File Date: 12/15/2025
|
||||
|
||||
<h2>Output:</h2>
|
||||
Rebuild target 'Target 1'
|
||||
compiling GPIO.c...
|
||||
compiling main.c...
|
||||
compiling UART.C...
|
||||
compiling UART_Set.c...
|
||||
compiling pwm_control.c...
|
||||
compiling Start_Init.c...
|
||||
compiling PWM15bit.c...
|
||||
compiling timer.c...
|
||||
compiling key.c...
|
||||
compiling WDT.c...
|
||||
linking...
|
||||
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
|
||||
SEGMENT: ?PR?_PRINTBUFFER1?UART
|
||||
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
|
||||
SEGMENT: ?PR?_PRINTSTRING3?UART
|
||||
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
|
||||
SEGMENT: ?PR?_QPWM15DUTY?PWM15BIT
|
||||
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
|
||||
SEGMENT: ?PR?_PWMLEVELSET?PWM15BIT
|
||||
Program Size: data=77.0 xdata=641 code=15470
|
||||
creating hex file from ".\Objects\BLV_C12_Dimm_V19"...
|
||||
".\Objects\BLV_C12_Dimm_V19" - 0 Error(s), 4 Warning(s).
|
||||
Build Time Elapsed: 00:00:01
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
1042
Objects/BLV_C12_Dimm_V19.hex
Normal file
1042
Objects/BLV_C12_Dimm_V19.hex
Normal file
File diff suppressed because it is too large
Load Diff
12
Objects/BLV_C12_Dimm_V19.lnp
Normal file
12
Objects/BLV_C12_Dimm_V19.lnp
Normal file
@@ -0,0 +1,12 @@
|
||||
".\Objects\GPIO.obj",
|
||||
".\Objects\main.obj",
|
||||
".\Objects\UART.obj",
|
||||
".\Objects\UART_Set.obj",
|
||||
".\Objects\pwm_control.obj",
|
||||
".\Objects\Start_Init.obj",
|
||||
".\Objects\PWM15bit.obj",
|
||||
".\Objects\timer.obj",
|
||||
".\Objects\key.obj",
|
||||
".\Objects\WDT.obj"
|
||||
TO ".\Objects\BLV_C12_Dimm_V19"
|
||||
PRINT(".\Listings\BLV_C12_Dimm_V19.m51") RAMSIZE(256)
|
||||
534
PWM15bit.c
Normal file
534
PWM15bit.c
Normal file
@@ -0,0 +1,534 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#include "PWM15bit.h"
|
||||
|
||||
u16 code PWMxCR[48] = {
|
||||
0xff14, /* PWM00CR */
|
||||
0xff1c, /* PWM01CR */
|
||||
0xff24, /* PWM02CR */
|
||||
0xff2c, /* PWM03CR */
|
||||
0xff34, /* PWM04CR */
|
||||
0xff3c, /* PWM05CR */
|
||||
0xff44, /* PWM06CR */
|
||||
0xff4c, /* PWM07CR */
|
||||
0xff64, /* PWM10CR */
|
||||
0xff6c, /* PWM11CR */
|
||||
0xff74, /* PWM12CR */
|
||||
0xff7c, /* PWM13CR */
|
||||
0xff84, /* PWM14CR */
|
||||
0xff8c, /* PWM15CR */
|
||||
0xff94, /* PWM16CR */
|
||||
0xff9c, /* PWM17CR */
|
||||
0xffb4, /* PWM20CR */
|
||||
0xffbc, /* PWM21CR */
|
||||
0xffc4, /* PWM22CR */
|
||||
0xffcc, /* PWM23CR */
|
||||
0xffd4, /* PWM24CR */
|
||||
0xffdc, /* PWM25CR */
|
||||
0xffe4, /* PWM26CR */
|
||||
0xffec, /* PWM27CR */
|
||||
0xfc14, /* PWM30CR */
|
||||
0xfc1c, /* PWM31CR */
|
||||
0xfc24, /* PWM32CR */
|
||||
0xfc2c, /* PWM33CR */
|
||||
0xfc34, /* PWM34CR */
|
||||
0xfc3c, /* PWM35CR */
|
||||
0xfc44, /* PWM36CR */
|
||||
0xfc4c, /* PWM37CR */
|
||||
0xfc64, /* PWM40CR */
|
||||
0xfc6c, /* PWM41CR */
|
||||
0xfc74, /* PWM42CR */
|
||||
0xfc7c, /* PWM43CR */
|
||||
0xfc84, /* PWM44CR */
|
||||
0xfc8c, /* PWM45CR */
|
||||
0xfc94, /* PWM46CR */
|
||||
0xfc9c, /* PWM47CR */
|
||||
0xfcb4, /* PWM50CR */
|
||||
0xfcbc, /* PWM51CR */
|
||||
0xfcc4, /* PWM52CR */
|
||||
0xfccc, /* PWM53CR */
|
||||
0xfcd4, /* PWM54CR */
|
||||
0xfcdc, /* PWM55CR */
|
||||
0xfce4, /* PWM56CR */
|
||||
0xfcec, /* PWM57CR */
|
||||
};
|
||||
|
||||
u16 code PWMxT1[48] = {
|
||||
0xff10, /* PWM00T1 */
|
||||
0xff18, /* PWM01T1 */
|
||||
0xff20, /* PWM02T1 */
|
||||
0xff28, /* PWM03T1 */
|
||||
0xff30, /* PWM04T1 */
|
||||
0xff38, /* PWM05T1 */
|
||||
0xff40, /* PWM06T1 */
|
||||
0xff48, /* PWM07T1 */
|
||||
0xff60, /* PWM10T1 */
|
||||
0xff68, /* PWM11T1 */
|
||||
0xff70, /* PWM12T1 */
|
||||
0xff78, /* PWM13T1 */
|
||||
0xff80, /* PWM14T1 */
|
||||
0xff88, /* PWM15T1 */
|
||||
0xff90, /* PWM16T1 */
|
||||
0xff98, /* PWM17T1 */
|
||||
0xffb0, /* PWM20T1 */
|
||||
0xffb8, /* PWM21T1 */
|
||||
0xffc0, /* PWM22T1 */
|
||||
0xffc8, /* PWM23T1 */
|
||||
0xffd0, /* PWM24T1 */
|
||||
0xffd8, /* PWM25T1 */
|
||||
0xffe0, /* PWM26T1 */
|
||||
0xffe8, /* PWM27T1 */
|
||||
0xfc10, /* PWM30T1 */
|
||||
0xfc18, /* PWM31T1 */
|
||||
0xfc20, /* PWM32T1 */
|
||||
0xfc28, /* PWM33T1 */
|
||||
0xfc30, /* PWM34T1 */
|
||||
0xfc38, /* PWM35T1 */
|
||||
0xfc40, /* PWM36T1 */
|
||||
0xfc48, /* PWM37T1 */
|
||||
0xfc60, /* PWM40T1 */
|
||||
0xfc68, /* PWM41T1 */
|
||||
0xfc70, /* PWM42T1 */
|
||||
0xfc78, /* PWM43T1 */
|
||||
0xfc80, /* PWM44T1 */
|
||||
0xfc88, /* PWM45T1 */
|
||||
0xfc90, /* PWM46T1 */
|
||||
0xfc98, /* PWM47T1 */
|
||||
0xfcb0, /* PWM50T1 */
|
||||
0xfcb8, /* PWM51T1 */
|
||||
0xfcc0, /* PWM52T1 */
|
||||
0xfcc8, /* PWM53T1 */
|
||||
0xfcd0, /* PWM54T1 */
|
||||
0xfcd8, /* PWM55T1 */
|
||||
0xfce0, /* PWM56T1 */
|
||||
0xfce8, /* PWM57T1 */
|
||||
};
|
||||
|
||||
u16 code PWMxT2[48] = {
|
||||
0xff12, /* PWM00T2 */
|
||||
0xff1a, /* PWM01T2 */
|
||||
0xff22, /* PWM02T2 */
|
||||
0xff2a, /* PWM03T2 */
|
||||
0xff32, /* PWM04T2 */
|
||||
0xff3a, /* PWM05T2 */
|
||||
0xff42, /* PWM06T2 */
|
||||
0xff4a, /* PWM07T2 */
|
||||
0xff62, /* PWM10T2 */
|
||||
0xff6a, /* PWM11T2 */
|
||||
0xff72, /* PWM12T2 */
|
||||
0xff7a, /* PWM13T2 */
|
||||
0xff82, /* PWM14T2 */
|
||||
0xff8a, /* PWM15T2 */
|
||||
0xff92, /* PWM16T2 */
|
||||
0xff9a, /* PWM17T2 */
|
||||
0xffb2, /* PWM20T2 */
|
||||
0xffba, /* PWM21T2 */
|
||||
0xffc2, /* PWM22T2 */
|
||||
0xffca, /* PWM23T2 */
|
||||
0xffd2, /* PWM24T2 */
|
||||
0xffda, /* PWM25T2 */
|
||||
0xffe2, /* PWM26T2 */
|
||||
0xffea, /* PWM27T2 */
|
||||
0xfc12, /* PWM30T2 */
|
||||
0xfc1a, /* PWM31T2 */
|
||||
0xfc22, /* PWM32T2 */
|
||||
0xfc2a, /* PWM33T2 */
|
||||
0xfc32, /* PWM34T2 */
|
||||
0xfc3a, /* PWM35T2 */
|
||||
0xfc42, /* PWM36T2 */
|
||||
0xfc4a, /* PWM37T2 */
|
||||
0xfc62, /* PWM40T2 */
|
||||
0xfc6a, /* PWM41T2 */
|
||||
0xfc72, /* PWM42T2 */
|
||||
0xfc7a, /* PWM43T2 */
|
||||
0xfc82, /* PWM44T2 */
|
||||
0xfc8a, /* PWM45T2 */
|
||||
0xfc92, /* PWM46T2 */
|
||||
0xfc9a, /* PWM47T2 */
|
||||
0xfcb2, /* PWM50T2 */
|
||||
0xfcba, /* PWM51T2 */
|
||||
0xfcc2, /* PWM52T2 */
|
||||
0xfcca, /* PWM53T2 */
|
||||
0xfcd2, /* PWM54T2 */
|
||||
0xfcda, /* PWM55T2 */
|
||||
0xfce2, /* PWM56T2 */
|
||||
0xfcea, /* PWM57T2 */
|
||||
};
|
||||
|
||||
u16 code PWMxHLD[48] = {
|
||||
0xff15, /* PWM00HLD */
|
||||
0xff1d, /* PWM01HLD */
|
||||
0xff25, /* PWM02HLD */
|
||||
0xff2d, /* PWM03HLD */
|
||||
0xff35, /* PWM04HLD */
|
||||
0xff3d, /* PWM05HLD */
|
||||
0xff45, /* PWM06HLD */
|
||||
0xff4d, /* PWM07HLD */
|
||||
0xff65, /* PWM10HLD */
|
||||
0xff6d, /* PWM11HLD */
|
||||
0xff75, /* PWM12HLD */
|
||||
0xff7d, /* PWM13HLD */
|
||||
0xff85, /* PWM14HLD */
|
||||
0xff8d, /* PWM15HLD */
|
||||
0xff95, /* PWM16HLD */
|
||||
0xff9d, /* PWM17HLD */
|
||||
0xffb5, /* PWM20HLD */
|
||||
0xffbd, /* PWM21HLD */
|
||||
0xffc5, /* PWM22HLD */
|
||||
0xffcd, /* PWM23HLD */
|
||||
0xffd5, /* PWM24HLD */
|
||||
0xffdd, /* PWM25HLD */
|
||||
0xffe5, /* PWM26HLD */
|
||||
0xffed, /* PWM27HLD */
|
||||
0xfc15, /* PWM30HLD */
|
||||
0xfc1d, /* PWM31HLD */
|
||||
0xfc25, /* PWM32HLD */
|
||||
0xfc2d, /* PWM33HLD */
|
||||
0xfc35, /* PWM34HLD */
|
||||
0xfc3d, /* PWM35HLD */
|
||||
0xfc45, /* PWM36HLD */
|
||||
0xfc4d, /* PWM37HLD */
|
||||
0xfc65, /* PWM40HLD */
|
||||
0xfc6d, /* PWM41HLD */
|
||||
0xfc75, /* PWM42HLD */
|
||||
0xfc7d, /* PWM43HLD */
|
||||
0xfc85, /* PWM44HLD */
|
||||
0xfc8d, /* PWM45HLD */
|
||||
0xfc95, /* PWM46HLD */
|
||||
0xfc9d, /* PWM47HLD */
|
||||
0xfcb5, /* PWM50HLD */
|
||||
0xfcbd, /* PWM51HLD */
|
||||
0xfcc5, /* PWM52HLD */
|
||||
0xfccd, /* PWM53HLD */
|
||||
0xfcd5, /* PWM54HLD */
|
||||
0xfcdd, /* PWM55HLD */
|
||||
0xfce5, /* PWM56HLD */
|
||||
0xfced, /* PWM57HLD */
|
||||
};
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: u8 PWMChannelCtrl(u8 PWM_id, u8 pwm_eno, u8 pwm_ini, u8 pwm_eni, u8 pwm_ent2i, u8 pwm_ent1i)
|
||||
// <20><><EFBFBD><EFBFBD>: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
// pwm_eno: pwm<77><6D><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, 0<><30>ΪGPIO, 1<><31>ΪPWM<57><4D><EFBFBD><EFBFBD>.
|
||||
// pwm_ini: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ, 0Ϊ<30>͵<EFBFBD>ƽ, 1Ϊ<31>ߵ<EFBFBD>ƽ.
|
||||
// pwm_eni: pwmͨ<6D><CDA8><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57>ж<EFBFBD>.
|
||||
// pwm_ent2i: pwmͨ<6D><CDA8><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>.
|
||||
// pwm_ent1i: pwmͨ<6D><CDA8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>, 0Ϊ<30>ر<EFBFBD>PWM<57><4D>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, 1Ϊʹ<CEAA><CAB9>PWM<57><4D>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
// <20>汾: V1.0, 2020-09-22
|
||||
//========================================================================
|
||||
u8 PWMChannelCtrl(u8 PWM_id, u8 pwm_eno, u8 pwm_ini, u8 pwm_eni, u8 pwm_ent2i, u8 pwm_ent1i)
|
||||
{
|
||||
u8 xdata *pPWMxCR;
|
||||
|
||||
if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
if(pwm_eno > 1) return 2; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
if(pwm_ini > 1) return 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
if(pwm_eni > 1) return 2; //<2F>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
if(pwm_ent2i > 1) return 2; //<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
if(pwm_ent1i > 1) return 2; //<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF>ƴ<EFBFBD><C6B4><EFBFBD>
|
||||
|
||||
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
pPWMxCR = (u8 *)PWMxCR[PWM_id];
|
||||
*pPWMxCR = (pwm_eno << 7) | (pwm_ini << 6) | (pwm_eni << 2)| (pwm_ent2i << 1)| pwm_ent1i;
|
||||
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: u8 PWMPeriodDuty(u8 PWM_id, u16 Period, u16 dutyL, u16 dutyH)
|
||||
// <20><><EFBFBD><EFBFBD>: PWM<57><4D><EFBFBD><EFBFBD>, ռ<>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
// dutyL: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, ȡֵ 0~0x7fff.
|
||||
// dutyH: pwm<77><6D><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>, ȡֵ 0~0x7fff.
|
||||
// <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
// <20>汾: V1.0, 2020-09-22
|
||||
//========================================================================
|
||||
u8 PWM15Duty(u8 PWM_id,u16 dutyL)
|
||||
{
|
||||
u16 xdata *pPWMxT1;
|
||||
u16 xdata *pPWMxT2;
|
||||
|
||||
if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
if(dutyL > 0x7fff) return 2; //<2F>͵<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
//if(dutyH > 0x7fff) return 2; //<2F>ߵ<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
|
||||
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
pPWMxT1 = (u16 *)PWMxT1[PWM_id];
|
||||
*pPWMxT1 = dutyL & 0x7fff;
|
||||
|
||||
pPWMxT2 = (u16 *)PWMxT2[PWM_id];
|
||||
*pPWMxT2 = 0x0000 & 0x7fff;
|
||||
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 qPWM15Duty(u8 PWM_id,u16 dutyL, u16 dutyH)
|
||||
{
|
||||
u16 xdata *pPWMxT1;
|
||||
u16 xdata *pPWMxT2;
|
||||
|
||||
if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
if(dutyL > 0x7fff) return 2; //<2F>͵<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
if(dutyH > 0x7fff) return 2; //<2F>ߵ<EFBFBD>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>
|
||||
|
||||
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
pPWMxT1 = (u16 *)PWMxT1[PWM_id];
|
||||
*pPWMxT1 = dutyL & 0x7fff;
|
||||
|
||||
pPWMxT2 = (u16 *)PWMxT2[PWM_id];
|
||||
*pPWMxT2 = dutyH & 0x7fff;
|
||||
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
return 0;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: u8 PWMOutputSet(u8 PWM_id, u8 pwm_hldl, u8 pwm_hldh)
|
||||
// <20><><EFBFBD><EFBFBD>: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: PWM_id: PWMͨ<4D><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ȡֵ 0~57
|
||||
// pwm_hldl: pwmǿ<6D><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>λ, 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 1ǿ<31><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ.
|
||||
// pwm_hldh: pwmǿ<6D><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>λ, 0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 1ǿ<31><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ.
|
||||
// <20><><EFBFBD><EFBFBD>: 0:<3A><>ȷ, 2:<3A><><EFBFBD><EFBFBD>.
|
||||
// <20>汾: V1.0, 2020-09-22
|
||||
//========================================================================
|
||||
u8 PWMLevelSet(u8 PWM_id, u8 pwm_hldl, u8 pwm_hldh)
|
||||
{
|
||||
u8 xdata *pPWMxHLD;
|
||||
|
||||
if(PWM_id > PWM57) return 2; //id<69><64><EFBFBD><EFBFBD>
|
||||
if(pwm_hldh > 1) return 2; //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
if(pwm_hldl > 1) return 2; //<2F><><EFBFBD><EFBFBD><EFBFBD>˵ij<CBB5>ʼ<EFBFBD><CABC>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
|
||||
|
||||
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
pPWMxHLD = (u8 *)PWMxHLD[PWM_id];
|
||||
*pPWMxHLD = (pwm_hldh << 1) | pwm_hldl;
|
||||
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM15_Init(u8 PWM_id, PWM15_InitTypeDef *PWMx)
|
||||
// <20><><EFBFBD><EFBFBD>: 15λ<35><CEBB>ǿ<EFBFBD><C7BF>PWM<57><4D>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: PWM_id: PWM<57><4D><EFBFBD><EFBFBD>. ȡֵ PWM0,PWM1,PWM2,PWM3,PWM4,PWM5
|
||||
// PWMx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>ͷ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-09-22
|
||||
//========================================================================
|
||||
void PWM15_Init(u8 PWM_id, PWM15_InitTypeDef *PWMx)
|
||||
{
|
||||
if(PWM_id > PWM5) return; //id<69><64><EFBFBD><EFBFBD>
|
||||
|
||||
EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չSFR(XSFR) */
|
||||
if(PWM_id == PWM0)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM0_Enable(); //ʹ<><CAB9>PWM0
|
||||
else PWM15_PWM0_Disable(); //<2F>ر<EFBFBD>PWM0
|
||||
PWM0_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM0C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter0_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter0_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
if(PWM_id == PWM1)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM1_Enable(); //ʹ<><CAB9>PWM1
|
||||
else PWM15_PWM1_Disable(); //<2F>ر<EFBFBD>PWM1
|
||||
PWM1_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM1C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter1_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter1_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
if(PWM_id == PWM2)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM2_Enable(); //ʹ<><CAB9>PWM2
|
||||
else PWM15_PWM2_Disable(); //<2F>ر<EFBFBD>PWM2
|
||||
PWM2_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM2C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter2_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter2_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
if(PWM_id == PWM3)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM3_Enable(); //ʹ<><CAB9>PWM3
|
||||
else PWM15_PWM3_Disable(); //<2F>ر<EFBFBD>PWM3
|
||||
PWM3_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM3C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter3_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter3_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
if(PWM_id == PWM4)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM4_Enable(); //ʹ<><CAB9>PWM4
|
||||
else PWM15_PWM4_Disable(); //<2F>ر<EFBFBD>PWM4
|
||||
PWM4_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM4C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter4_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter4_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
if(PWM_id == PWM5)
|
||||
{
|
||||
if(PWMx->PWM_Enable == ENABLE) PWM15_PWM5_Enable(); //ʹ<><CAB9>PWM5
|
||||
else PWM15_PWM5_Disable(); //<2F>ر<EFBFBD>PWM5
|
||||
PWM5_PS_Set(PWMx->PWM_Clock_PS); //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
PWM5C = PWMx->PWM_Period & 0x7fff;
|
||||
if(PWMx->PWM_Counter == ENABLE) PWM15_Counter5_Enable(); //ʹ<>ܼ<EFBFBD><DCBC><EFBFBD><EFBFBD><EFBFBD>
|
||||
else PWM15_Counter5_Disable(); //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
EAXRAM(); /* MOVX A,@DPTR/MOVX @DPTR,Aָ<41><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>չRAM(XRAM) */
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM0_Handler (void) interrupt PWM0_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM0<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
void PWM0_Handler (void) interrupt PWM0_VECTOR
|
||||
{
|
||||
char store;
|
||||
store = P_SW2;
|
||||
P_SW2 |= 0x80;
|
||||
|
||||
if(PWMCFG01 & 0x08) //PWM0<4D>ж<EFBFBD>
|
||||
{
|
||||
PWMCFG01 &= ~0x08; //<2F><>PWM0<4D>жϱ<D0B6>־
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(PWM0IF)
|
||||
{
|
||||
PWM0IF = 0;
|
||||
P27 = ~P27;
|
||||
}
|
||||
P_SW2 = store;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM1_Handler (void) interrupt PWM1_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM1<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
void PWM1_Handler (void) interrupt PWM1_VECTOR
|
||||
{
|
||||
char store;
|
||||
store = P_SW2;
|
||||
P_SW2 |= 0x80;
|
||||
|
||||
if(PWMCFG01 & 0x80) //PWM1<4D>ж<EFBFBD>
|
||||
{
|
||||
PWMCFG01 &= ~0x80; //<2F><>PWM1<4D>жϱ<D0B6>־
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(PWM1IF)
|
||||
{
|
||||
PWM1IF = 0;
|
||||
P26 = ~P26;
|
||||
}
|
||||
P_SW2 = store;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM2_Handler (void) interrupt PWM2_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM2<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
void PWM2_Handler (void) interrupt PWM2_VECTOR
|
||||
{
|
||||
char store;
|
||||
store = P_SW2;
|
||||
P_SW2 |= 0x80;
|
||||
|
||||
if(PWMCFG23 & 0x08) //PWM2<4D>ж<EFBFBD>
|
||||
{
|
||||
PWMCFG23 &= ~0x08; //<2F><>PWM2<4D>жϱ<D0B6>־
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(PWM2IF)
|
||||
{
|
||||
PWM2IF = 0;
|
||||
P25 = ~P25;
|
||||
}
|
||||
P_SW2 = store;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM3_Handler (void) interrupt PWM3_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM3<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
void PWM3_Handler (void) interrupt PWM3_VECTOR
|
||||
{
|
||||
char store;
|
||||
store = P_SW2;
|
||||
P_SW2 |= 0x80;
|
||||
|
||||
if(PWMCFG23 & 0x80) //PWM3<4D>ж<EFBFBD>
|
||||
{
|
||||
PWMCFG23 &= ~0x80; //<2F><>PWM3<4D>жϱ<D0B6>־
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(PWM3IF)
|
||||
{
|
||||
PWM3IF = 0;
|
||||
P24 = ~P24;
|
||||
}
|
||||
P_SW2 = store;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM4_Handler (void) interrupt PWM4_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM4<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
void PWM4_Handler (void) interrupt PWM4_VECTOR
|
||||
{
|
||||
char store;
|
||||
store = P_SW2;
|
||||
P_SW2 |= 0x80;
|
||||
|
||||
if(PWMCFG45 & 0x08) //PWM4<4D>ж<EFBFBD>
|
||||
{
|
||||
PWMCFG45 &= ~0x08; //<2F><>PWM4<4D>жϱ<D0B6>־
|
||||
// TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
if(PWM4IF)
|
||||
{
|
||||
PWM4IF = 0;
|
||||
P23 = ~P23;
|
||||
}
|
||||
P_SW2 = store;
|
||||
}
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void PWM5_Handler (void) interrupt PWM5_VECTOR
|
||||
// <20><><EFBFBD><EFBFBD>: PWM5<4D>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: None
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-10-13
|
||||
//========================================================================
|
||||
//void PWM5_Handler (void) interrupt PWM5_VECTOR //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD><C5B3><EFBFBD>31<33><31><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϺ<D0B6><CFBA><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//{
|
||||
// if(PWMCFG45 & 0x80) //PWM5<4D>ж<EFBFBD>
|
||||
// {
|
||||
// PWMCFG45 &= ~0x80; //<2F><>PWM5<4D>жϱ<D0B6>־
|
||||
// // TODO: <20>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
// }
|
||||
//}
|
||||
94
PWM15bit.h
Normal file
94
PWM15bit.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __PWM15BIT_H
|
||||
#define __PWM15BIT_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define PWM0 0
|
||||
#define PWM1 1
|
||||
#define PWM2 2
|
||||
#define PWM3 3
|
||||
#define PWM4 4
|
||||
#define PWM5 5
|
||||
|
||||
#define PWM00 0
|
||||
#define PWM01 1
|
||||
#define PWM02 2
|
||||
#define PWM03 3
|
||||
#define PWM04 4
|
||||
#define PWM05 5
|
||||
#define PWM06 6
|
||||
#define PWM07 7
|
||||
#define PWM10 8
|
||||
#define PWM11 9
|
||||
#define PWM12 10
|
||||
#define PWM13 11
|
||||
#define PWM14 12
|
||||
#define PWM15 13
|
||||
#define PWM16 14
|
||||
#define PWM17 15
|
||||
#define PWM20 16
|
||||
#define PWM21 17
|
||||
#define PWM22 18
|
||||
#define PWM23 19
|
||||
#define PWM24 20
|
||||
#define PWM25 21
|
||||
#define PWM26 22
|
||||
#define PWM27 23
|
||||
#define PWM30 24
|
||||
#define PWM31 25
|
||||
#define PWM32 26
|
||||
#define PWM33 27
|
||||
#define PWM34 28
|
||||
#define PWM35 29
|
||||
#define PWM36 30
|
||||
#define PWM37 31
|
||||
#define PWM40 32
|
||||
#define PWM41 33
|
||||
#define PWM42 34
|
||||
#define PWM43 35
|
||||
#define PWM44 36
|
||||
#define PWM45 37
|
||||
#define PWM46 38
|
||||
#define PWM47 39
|
||||
#define PWM50 40
|
||||
#define PWM51 41
|
||||
#define PWM52 42
|
||||
#define PWM53 43
|
||||
#define PWM54 44
|
||||
#define PWM55 45
|
||||
#define PWM56 46
|
||||
#define PWM57 47
|
||||
|
||||
#define PWMn_CLK_SYS 0
|
||||
#define PWMn_CLK_TM2 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 PWM_Enable; //PWMʹ<4D><CAB9>, ENABLE, DISABLE
|
||||
|
||||
u8 PWM_Interrupt; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE, DISABLE
|
||||
u8 PWM_Counter; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE, DISABLE
|
||||
u8 PWM_Clock_Sel; //ʱ<><CAB1>Դѡ<D4B4><D1A1>, PWMn_CLK_SYS, PWMn_CLK_TM2
|
||||
u8 PWM_Clock_PS; //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>, 0~15
|
||||
u16 PWM_Period; //PWM<57><4D><EFBFBD><EFBFBD>, 0~0x7fff
|
||||
} PWM15_InitTypeDef;
|
||||
|
||||
void PWM15_Init(u8 PWM_id, PWM15_InitTypeDef *PWMx);
|
||||
u8 PWMChannelCtrl(u8 PWM_id, u8 pwm_eno, u8 pwm_ini, u8 pwm_eni, u8 pwm_ent2i, u8 pwm_ent1i);
|
||||
u8 PWM15Duty(u8 PWM_id,u16 dutyL);
|
||||
u8 PWMLevelSet(u8 PWM_id, u8 pwm_hldl, u8 pwm_hldh);
|
||||
u8 qPWM15Duty(u8 PWM_id,u16 dutyL, u16 dutyH);
|
||||
#endif
|
||||
|
||||
57
Readme.md
Normal file
57
Readme.md
Normal file
@@ -0,0 +1,57 @@
|
||||
### 项目名称:RCU_C12_Dimming
|
||||
|
||||
### 协议文档:..\RCU-Cx\Document\BLV-BUS-485协议文档
|
||||
|
||||
### 共享路径:..\RCU-Cx\Reference\BLV_C12_CH12_Source_Code
|
||||
|
||||
|
||||
|
||||
# 版本说明
|
||||
|
||||
|
||||
|
||||
#### 2025-12-15 修改人:曹聪 类型:解决BUG
|
||||
|
||||
问题描述:调光时间一样的情况下,调光亮与调光灭的实际调光时间不一致
|
||||
|
||||
```c
|
||||
/* 问题点:在于pwm_control.c文件中的deal_command1函数处理上
|
||||
|
||||
s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i];
|
||||
s_pwm.doublecurrpwm[i] += s_pwm.every_change_10ms[i];
|
||||
s_pwm.currpwm[i] = (u16)s_pwm.doublecurrpwm[i];
|
||||
|
||||
其中:
|
||||
currpwm 是当前PWM对应的寄存器值(整数)
|
||||
doublecurrpwm 是用于计算PWM步进后的值(浮点数)
|
||||
此逻辑导致用于计算PWM步进后的浮点数,直接丢失小数部分,然后用于下一次运算;导致PWM增加的步进值与降低的步进值不同,从而导致实际调光时间不一致
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### V18之前版本说明如下:
|
||||
|
||||
- V18 2024-09-27
|
||||
|
||||
修改内容:解决全局亮度设置时变量溢出导致亮度不能调节问题。
|
||||
|
||||
- V17 杨鸿锋
|
||||
|
||||
修改内容:全局亮度设置增加渐变
|
||||
|
||||
- V16 2024-05-06 曹聪
|
||||
|
||||
修改内容:修改调光频率导致循环调光时间过短问题 - 调整后与之前循环调光渐变时间差不多(最慢的时候 10S左右)
|
||||
|
||||
- V15
|
||||
|
||||
修改了pwm调光的频率,调成16khz,解决了低频主机啸叫的问题
|
||||
|
||||
- V14
|
||||
|
||||
修改串口接收,最终发布版本
|
||||
|
||||
- 以下版本说明全是开发临时记录
|
||||
2748
STC8xxxx.H
Normal file
2748
STC8xxxx.H
Normal file
File diff suppressed because it is too large
Load Diff
39
Start_Init.c
Normal file
39
Start_Init.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "STC8xxxx.h"
|
||||
#include "Start_Init.h"
|
||||
#include "string.h"
|
||||
#include "UART_Set.h"
|
||||
#include "timer.h"
|
||||
#include "pwm_control.h"
|
||||
|
||||
void Start_Init(void)
|
||||
{
|
||||
u8 i;
|
||||
memset(&g_Usart,0,sizeof(g_Usart));
|
||||
memset(&s_recv, 0, sizeof(s_recv));
|
||||
memset(&g_answer,0,sizeof(g_answer));
|
||||
g_Usart.lastsn=0xFF;
|
||||
s_recv.B_min = 0;
|
||||
s_recv.B_max = 100;
|
||||
s_recv.global_brightness = 100;
|
||||
|
||||
for(i=0;i<12;i++)
|
||||
{
|
||||
s_recv.pwm_step[i] = 1;
|
||||
s_recv.key_status[i] = 1;
|
||||
s_recv.gradual_time[i] = 300;
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><>ʱ<EFBFBD><CAB1>2<EFBFBD><32>1ms<6D><73>ʱ
|
||||
void Timer2_Init_1ms(void)
|
||||
{
|
||||
TIM_InitTypeDef TIM_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
TIM_InitStructure.TIM_Mode = TIM_16BitAutoReload; //ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ, TIM_16BitAutoReload,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask
|
||||
TIM_InitStructure.TIM_Priority = Priority_3; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
TIM_InitStructure.TIM_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE. (ע<><D7A2>: Timer2<72>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>жϹ̶<CFB9>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>)
|
||||
TIM_InitStructure.TIM_ClkSource = TIM_CLOCK_12T; //ָ<><D6B8>ʱ<EFBFBD><CAB1>Դ, TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
|
||||
TIM_InitStructure.TIM_ClkOut = DISABLE; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
TIM_InitStructure.TIM_Value = 63693UL; //<2F><>ֵ,<2C><>ʱΪ1ms
|
||||
TIM_InitStructure.TIM_Run = ENABLE; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>, ENABLE<4C><45>DISABLE
|
||||
Timer_Inilize(Timer2,&TIM_InitStructure); //<2F><>ʼ<EFBFBD><CABC>Timer2 Timer0,Timer1,Timer2,Timer3,Timer4
|
||||
}
|
||||
6
Start_Init.h
Normal file
6
Start_Init.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef START_INIT_H
|
||||
#define START_INIT_H
|
||||
|
||||
void Start_Init(void);
|
||||
void Timer2_Init_1ms(void);
|
||||
#endif
|
||||
484
UART.C
Normal file
484
UART.C
Normal file
@@ -0,0 +1,484 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#include "UART.h"
|
||||
#include "timer.h"
|
||||
|
||||
#ifdef UART1
|
||||
COMx_Define COM1;
|
||||
u8 xdata TX1_Buffer[COM_TX1_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX1_Buffer[COM_RX1_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART2
|
||||
COMx_Define COM2;
|
||||
u8 xdata TX2_Buffer[COM_TX2_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX2_Buffer[COM_RX2_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART3
|
||||
COMx_Define COM3;
|
||||
u8 xdata TX3_Buffer[COM_TX3_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX3_Buffer[COM_RX3_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART4
|
||||
COMx_Define COM4;
|
||||
u8 xdata TX4_Buffer[COM_TX4_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
u8 xdata RX4_Buffer[COM_RX4_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
|
||||
u8 UART_Configuration(u8 UARTx, COMx_InitDefine *COMx)
|
||||
{
|
||||
u8 i;
|
||||
u32 j;
|
||||
|
||||
#ifdef UART1
|
||||
if(UARTx == UART1)
|
||||
{
|
||||
COM1.id = 1;
|
||||
COM1.TX_read = 0;
|
||||
COM1.TX_write = 0;
|
||||
COM1.B_TX_busy = 0;
|
||||
COM1.RX_Cnt = 0;
|
||||
COM1.RX_TimeOut = 0;
|
||||
COM1.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX1_Lenth; i++) TX1_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX1_Lenth; i++) RX1_Buffer[i] = 0;
|
||||
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART1_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
if(COMx->UART_Mode > UART_9bit_BRTx) return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
SCON = (SCON & 0x3f) | COMx->UART_Mode;
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
if(COMx->UART_BRT_Use == BRT_Timer1)
|
||||
{
|
||||
TR1 = 0;
|
||||
AUXR &= ~0x01; //S1 BRT Use Timer1;
|
||||
TMOD &= ~(1<<6); //Timer1 set As Timer
|
||||
TMOD &= ~0x30; //Timer1_16bitAutoReload;
|
||||
AUXR |= (1<<6); //Timer1 set as 1T mode
|
||||
TH1 = (u8)(j>>8);
|
||||
TL1 = (u8)j;
|
||||
ET1 = 0; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
TMOD &= ~0x40; //<2F><>ʱ
|
||||
INT_CLKO &= ~0x02; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
TR1 = 1;
|
||||
}
|
||||
else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
{
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
AUXR |= 0x01; //S1 BRT Use Timer2;
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
else if(COMx->UART_Mode == UART_ShiftRight)
|
||||
{
|
||||
if(COMx->BaudRateDouble == ENABLE) AUXR |= (1<<5); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/2
|
||||
else AUXR &= ~(1<<5); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/12
|
||||
}
|
||||
else if(COMx->UART_Mode == UART_9bit) //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk*2^SMOD/64
|
||||
{
|
||||
if(COMx->BaudRateDouble == ENABLE) PCON |= (1<<7); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/32
|
||||
else PCON &= ~(1<<7); //<2F>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SysClk/64
|
||||
}
|
||||
if(COMx->UART_Interrupt == ENABLE) ES = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else ES = 0; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) REN = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else REN = 0; //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW1 = (P_SW1 & 0x3f) | (COMx->UART_P_SW & 0xc0); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef UART2
|
||||
if(UARTx == UART2)
|
||||
{
|
||||
COM2.id = 2;
|
||||
COM2.TX_read = 0;
|
||||
COM2.TX_write = 0;
|
||||
COM2.B_TX_busy = 0;
|
||||
COM2.RX_Cnt = 0;
|
||||
COM2.RX_TimeOut = 0;
|
||||
COM2.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX2_Lenth; i++) TX2_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX2_Lenth; i++) RX2_Buffer[i] = 0;
|
||||
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) ||(COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART2_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
if(COMx->UART_Mode == UART_9bit_BRTx) S2CON |= (1<<7); //9bit
|
||||
else S2CON &= ~(1<<7); //8bit
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
if(COMx->UART_Interrupt == ENABLE) IE2 |= 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else IE2 &= ~1; //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) S2CON |= (1<<4); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else S2CON &= ~(1<<4); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW2 = (P_SW2 & ~1) | (COMx->UART_P_SW & 0x01); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef UART3
|
||||
if(UARTx == UART3)
|
||||
{
|
||||
COM3.id = 3;
|
||||
COM3.TX_read = 0;
|
||||
COM3.TX_write = 0;
|
||||
COM3.B_TX_busy = 0;
|
||||
COM3.RX_Cnt = 0;
|
||||
COM3.RX_TimeOut = 0;
|
||||
COM3.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX3_Lenth; i++) TX3_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX3_Lenth; i++) RX3_Buffer[i] = 0;
|
||||
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART3_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
if(COMx->UART_Mode == UART_9bit_BRTx) S3_9bit(); //9bit
|
||||
else S3_8bit(); //8bit
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
if(COMx->UART_BRT_Use == BRT_Timer3)
|
||||
{
|
||||
S3_BRT_UseTimer3(); //S3 BRT Use Timer3;
|
||||
TH3 = (u8)(j>>8);
|
||||
TL3 = (u8)j;
|
||||
T4T3M &= 0xf0;
|
||||
T4T3M |= 0x0a; //Timer3 set As Timer, 1T mode, Start timer3
|
||||
}
|
||||
else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
{
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
S3_BRT_UseTimer2(); //S3 BRT Use Timer2;
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
if(COMx->UART_Interrupt == ENABLE) S3_Int_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else S3_Int_Disable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) S3_RX_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else S3_RX_Disable(); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW2 = (P_SW2 & ~2) | (COMx->UART_P_SW & 0x02); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef UART4
|
||||
if(UARTx == UART4)
|
||||
{
|
||||
COM4.id = 3;
|
||||
COM4.TX_read = 0;
|
||||
COM4.TX_write = 0;
|
||||
COM4.B_TX_busy = 0;
|
||||
COM4.RX_Cnt = 0;
|
||||
COM4.RX_TimeOut = 0;
|
||||
COM4.B_RX_OK = 0;
|
||||
for(i=0; i<COM_TX4_Lenth; i++) TX4_Buffer[i] = 0;
|
||||
for(i=0; i<COM_RX4_Lenth; i++) RX4_Buffer[i] = 0;
|
||||
|
||||
if((COMx->UART_Mode == UART_9bit_BRTx) || (COMx->UART_Mode == UART_8bit_BRTx)) //<2F>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(COMx->UART_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
UART4_Priority(COMx->UART_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
if(COMx->UART_Mode == UART_9bit_BRTx) S4_9bit(); //9bit
|
||||
else S4_8bit(); //8bit
|
||||
j = (MAIN_Fosc / 4) / COMx->UART_BaudRate; //<2F><>1T<31><54><EFBFBD><EFBFBD>
|
||||
if(j >= 65536UL) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
j = 65536UL - j;
|
||||
if(COMx->UART_BRT_Use == BRT_Timer4)
|
||||
{
|
||||
S4_BRT_UseTimer4(); //S4 BRT Use Timer4;
|
||||
TH4 = (u8)(j>>8);
|
||||
TL4 = (u8)j;
|
||||
T4T3M &= 0x0f;
|
||||
T4T3M |= 0xa0; //Timer4 set As Timer, 1T mode, Start timer4
|
||||
}
|
||||
else if(COMx->UART_BRT_Use == BRT_Timer2)
|
||||
{
|
||||
AUXR &= ~(1<<4); //Timer stop
|
||||
S4_BRT_UseTimer2(); //S4 BRT Use Timer2;
|
||||
AUXR &= ~(1<<3); //Timer2 set As Timer
|
||||
AUXR |= (1<<2); //Timer2 set as 1T mode
|
||||
TH2 = (u8)(j>>8);
|
||||
TL2 = (u8)j;
|
||||
IE2 &= ~(1<<2); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
AUXR |= (1<<4); //Timer run enable
|
||||
}
|
||||
else return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
else return 2; //ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
|
||||
if(COMx->UART_Interrupt == ENABLE) S4_Int_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else S4_Int_Disable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(COMx->UART_RxEnable == ENABLE) S4_RX_Enable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else S4_RX_Disable(); //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||||
P_SW2 = (P_SW2 & ~4) | (COMx->UART_P_SW & 0x04); //<2F>л<EFBFBD>IO
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
/********************* UART1 <20><><EFBFBD><EFBFBD> ************************/
|
||||
#ifdef UART1
|
||||
void TX1_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX1_Buffer[COM1.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM1.TX_write >= COM_TX1_Lenth) COM1.TX_write = 0;
|
||||
|
||||
if(COM1.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM1.B_TX_busy = 1; //<2F><>־æ
|
||||
TI = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString1(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX1_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
void Printbuffer1(u8 *puts,u8 len)
|
||||
{
|
||||
u8 i;
|
||||
for (i=0; i<len;i++) TX1_write2buff(puts[i]);
|
||||
}
|
||||
|
||||
u8 recv_start_flag=0;
|
||||
u32 recv_time=0;
|
||||
void UART1_int (void) interrupt UART1_VECTOR
|
||||
{
|
||||
static u8 stage=0;
|
||||
u8 dat;
|
||||
if(RI)
|
||||
{
|
||||
RI = 0;
|
||||
recv_start_flag=1;
|
||||
recv_time=systick_1ms;
|
||||
|
||||
if(COM1.B_RX_OK == 0)
|
||||
{
|
||||
dat=SBUF;
|
||||
if(COM1.RX_Cnt >= COM_RX1_Lenth) COM1.RX_Cnt = 0;
|
||||
if(dat=='D') //<2F><><EFBFBD><EFBFBD>10<31><30>'D',<2C><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>
|
||||
{
|
||||
stage++;
|
||||
}
|
||||
else
|
||||
{
|
||||
stage=0;
|
||||
}
|
||||
if(stage==10)
|
||||
{
|
||||
IAP_CONTR=0x60;
|
||||
}
|
||||
RX1_Buffer[COM1.RX_Cnt++] = SBUF;
|
||||
COM1.RX_TimeOut = TimeOutSet1;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI)
|
||||
{
|
||||
TI = 0;
|
||||
if(COM1.TX_read != COM1.TX_write)
|
||||
{
|
||||
SBUF = TX1_Buffer[COM1.TX_read];
|
||||
if(++COM1.TX_read >= COM_TX1_Lenth) COM1.TX_read = 0;
|
||||
}
|
||||
else COM1.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* UART2 <20><><EFBFBD><EFBFBD> ************************/
|
||||
#ifdef UART2
|
||||
void TX2_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX2_Buffer[COM2.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM2.TX_write >= COM_TX2_Lenth) COM2.TX_write = 0;
|
||||
|
||||
if(COM2.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM2.B_TX_busy = 1; //<2F><>־æ
|
||||
SET_TI2(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString2(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX2_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void UART2_int (void) interrupt UART2_VECTOR
|
||||
{
|
||||
if(RI2)
|
||||
{
|
||||
CLR_RI2();
|
||||
if(COM2.B_RX_OK == 0)
|
||||
{
|
||||
if(COM2.RX_Cnt >= COM_RX2_Lenth) COM2.RX_Cnt = 0;
|
||||
RX2_Buffer[COM2.RX_Cnt++] = S2BUF;
|
||||
COM2.RX_TimeOut = TimeOutSet2;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI2)
|
||||
{
|
||||
CLR_TI2();
|
||||
if(COM2.TX_read != COM2.TX_write)
|
||||
{
|
||||
S2BUF = TX2_Buffer[COM2.TX_read];
|
||||
if(++COM2.TX_read >= COM_TX2_Lenth) COM2.TX_read = 0;
|
||||
}
|
||||
else COM2.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* UART3 <20><><EFBFBD><EFBFBD> ************************/
|
||||
#ifdef UART3
|
||||
void TX3_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX3_Buffer[COM3.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM3.TX_write >= COM_TX3_Lenth) COM3.TX_write = 0;
|
||||
|
||||
if(COM3.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM3.B_TX_busy = 1; //<2F><>־æ
|
||||
SET_TI3(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString3(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX3_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void Printbuffer3(u8 *puts,u8 len)
|
||||
{
|
||||
u8 i;
|
||||
for (i=0; i<len;i++) TX3_write2buff(*puts++); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void UART3_int (void) interrupt UART3_VECTOR
|
||||
{
|
||||
if(RI3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
|
||||
{
|
||||
recv_start_flag=1;
|
||||
recv_time=systick_1ms;
|
||||
CLR_RI3();
|
||||
if(COM3.B_RX_OK == 0)
|
||||
{
|
||||
if(COM3.RX_Cnt >= COM_RX3_Lenth) COM3.RX_Cnt = 0;
|
||||
RX3_Buffer[COM3.RX_Cnt++] = S3BUF;
|
||||
COM3.RX_TimeOut = TimeOutSet3;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI3) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
|
||||
{
|
||||
CLR_TI3();
|
||||
if(COM3.TX_read != COM3.TX_write)
|
||||
{
|
||||
S3BUF = TX3_Buffer[COM3.TX_read];
|
||||
if(++COM3.TX_read >= COM_TX3_Lenth) COM3.TX_read = 0;
|
||||
}
|
||||
else COM3.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************* UART4 <20><><EFBFBD><EFBFBD> ************************/
|
||||
#ifdef UART4
|
||||
void TX4_write2buff(u8 dat) //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
{
|
||||
TX4_Buffer[COM4.TX_write] = dat; //װ<><D7B0><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
if(++COM4.TX_write >= COM_TX4_Lenth) COM4.TX_write = 0;
|
||||
|
||||
if(COM4.B_TX_busy == 0) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
COM4.B_TX_busy = 1; //<2F><>־æ
|
||||
SET_TI4(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
void PrintString4(u8 *puts)
|
||||
{
|
||||
for (; *puts != 0; puts++) TX4_write2buff(*puts); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9>0<EFBFBD><30><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
void UART4_int (void) interrupt UART4_VECTOR
|
||||
{
|
||||
if(RI4)
|
||||
{
|
||||
CLR_RI4();
|
||||
if(COM4.B_RX_OK == 0)
|
||||
{
|
||||
if(COM4.RX_Cnt >= COM_RX4_Lenth) COM4.RX_Cnt = 0;
|
||||
RX4_Buffer[COM4.RX_Cnt++] = S4BUF;
|
||||
COM4.RX_TimeOut = TimeOutSet4;
|
||||
}
|
||||
}
|
||||
|
||||
if(TI4)
|
||||
{
|
||||
CLR_TI4();
|
||||
if(COM4.TX_read != COM4.TX_write)
|
||||
{
|
||||
S4BUF = TX4_Buffer[COM4.TX_read];
|
||||
if(++COM4.TX_read >= COM_TX4_Lenth) COM4.TX_read = 0;
|
||||
}
|
||||
else COM4.B_TX_busy = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************** <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *****************/
|
||||
void UART3_config(void)
|
||||
{
|
||||
COMx_InitDefine COMx_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
|
||||
COMx_InitStructure.UART_BRT_Use = BRT_Timer3; //ʹ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>, BRT_Timer2, BRT_Timer3 (ע<><D7A2>: <20><><EFBFBD><EFBFBD>2<EFBFBD>̶<EFBFBD>ʹ<EFBFBD><CAB9>BRT_Timer2)
|
||||
COMx_InitStructure.UART_BaudRate = 115200; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 110 ~ 115200
|
||||
COMx_InitStructure.UART_RxEnable = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
COMx_InitStructure.UART_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
COMx_InitStructure.UART_Priority = Priority_0; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
COMx_InitStructure.UART_P_SW = UART3_SW_P50_P51; //<2F>л<EFBFBD><D0BB>˿<EFBFBD>, UART3_SW_P00_P01,UART3_SW_P50_P51
|
||||
UART_Configuration(UART3, &COMx_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3 UART1,UART2,UART3,UART4
|
||||
|
||||
//PrintString3("STC8 UART3 Test Programme!\r\n"); //UART3<54><33><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
}
|
||||
138
UART.h
Normal file
138
UART.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __UART_H
|
||||
#define __UART_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define UART1 1
|
||||
//#define UART2 2
|
||||
#define UART3 3
|
||||
//#define UART4 4
|
||||
|
||||
#ifdef UART1
|
||||
#define COM_TX1_Lenth 32
|
||||
#define COM_RX1_Lenth 32
|
||||
#endif
|
||||
#ifdef UART2
|
||||
#define COM_TX2_Lenth 128
|
||||
#define COM_RX2_Lenth 128
|
||||
#endif
|
||||
#ifdef UART3
|
||||
#define COM_TX3_Lenth 32 //32<33><32><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define COM_RX3_Lenth 32
|
||||
#endif
|
||||
#ifdef UART4
|
||||
#define COM_TX4_Lenth 128
|
||||
#define COM_RX4_Lenth 128
|
||||
#endif
|
||||
|
||||
#define UART_ShiftRight 0 //ͬ<><CDAC><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
|
||||
#define UART_8bit_BRTx (1<<6) //8λ<38><CEBB><EFBFBD><EFBFBD>,<2C>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
#define UART_9bit (2<<6) //9λ<39><CEBB><EFBFBD><EFBFBD>,<2C>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define UART_9bit_BRTx (3<<6) //9λ<39><CEBB><EFBFBD><EFBFBD>,<2C>ɱ䲨<C9B1><E4B2A8><EFBFBD><EFBFBD>
|
||||
|
||||
#define UART1_SW_P30_P31 0
|
||||
#define UART1_SW_P36_P37 (1<<6)
|
||||
#define UART1_SW_P16_P17 (2<<6)
|
||||
#define UART1_SW_P43_P44 (3<<6)
|
||||
#define UART2_SW_P10_P11 0
|
||||
#define UART2_SW_P46_P47 1
|
||||
#define UART3_SW_P00_P01 0
|
||||
#define UART3_SW_P50_P51 2
|
||||
#define UART4_SW_P02_P03 0
|
||||
#define UART4_SW_P52_P53 4
|
||||
|
||||
|
||||
#define TimeOutSet1 5
|
||||
#define TimeOutSet2 5
|
||||
#define TimeOutSet3 5
|
||||
#define TimeOutSet4 5
|
||||
|
||||
#define BRT_Timer1 1
|
||||
#define BRT_Timer2 2
|
||||
#define BRT_Timer3 3
|
||||
#define BRT_Timer4 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 id; //<2F><><EFBFBD>ں<EFBFBD>
|
||||
|
||||
u8 TX_read; //<2F><><EFBFBD>Ͷ<EFBFBD>ָ<EFBFBD><D6B8>
|
||||
u8 TX_write; //<2F><><EFBFBD><EFBFBD>дָ<D0B4><D6B8>
|
||||
u8 B_TX_busy; //æ<><C3A6>־
|
||||
|
||||
u8 RX_Cnt; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֽڼ<D6BD><DABC><EFBFBD>
|
||||
u8 RX_TimeOut; //<2F><><EFBFBD>ճ<EFBFBD>ʱ
|
||||
u8 B_RX_OK; //<2F><><EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD><EFBFBD>
|
||||
} COMx_Define;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 UART_Mode; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
|
||||
u8 UART_BRT_Use; //ʹ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>, BRT_Timer1,BRT_Timer2
|
||||
u32 UART_BaudRate; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE,DISABLE
|
||||
u8 Morecommunicate; //<2F><><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>, ENABLE,DISABLE
|
||||
u8 UART_RxEnable; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE,DISABLE
|
||||
u8 BaudRateDouble; //<2F><><EFBFBD><EFBFBD><EFBFBD>ʼӱ<CABC>, ENABLE,DISABLE
|
||||
u8 UART_Interrupt; //<2F>жϿ<D0B6><CFBF><EFBFBD>, ENABLE,DISABLE
|
||||
u8 UART_Priority; //<2F><><EFBFBD>ȼ<EFBFBD>, Priority_0,Priority_1,Priority_2,Priority_3
|
||||
u8 UART_P_SW; //<2F>л<EFBFBD><D0BB>˿<EFBFBD>, UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
|
||||
} COMx_InitDefine;
|
||||
|
||||
#ifdef UART1
|
||||
extern COMx_Define COM1;
|
||||
extern u8 xdata TX1_Buffer[COM_TX1_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern u8 xdata RX1_Buffer[COM_RX1_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART2
|
||||
extern COMx_Define COM2;
|
||||
extern u8 xdata TX2_Buffer[COM_TX2_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern u8 xdata RX2_Buffer[COM_RX2_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART3
|
||||
extern COMx_Define COM3;
|
||||
extern u8 xdata TX3_Buffer[COM_TX3_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern u8 xdata RX3_Buffer[COM_RX3_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
#ifdef UART4
|
||||
extern COMx_Define COM4;
|
||||
extern u8 xdata TX4_Buffer[COM_TX4_Lenth]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
extern u8 xdata RX4_Buffer[COM_RX4_Lenth]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
|
||||
#endif
|
||||
|
||||
u8 UART_Configuration(u8 UARTx, COMx_InitDefine *COMx);
|
||||
#ifdef UART1
|
||||
void TX1_write2buff(u8 dat); //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
void PrintString1(u8 *puts);
|
||||
void Printbuffer1(u8 *puts,u8 len);
|
||||
#endif
|
||||
#ifdef UART2
|
||||
void TX2_write2buff(u8 dat); //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
void PrintString2(u8 *puts);
|
||||
#endif
|
||||
#ifdef UART3
|
||||
void TX3_write2buff(u8 dat); //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
void PrintString3(u8 *puts);
|
||||
void Printbuffer3(u8 *puts,u8 len);
|
||||
#endif
|
||||
#ifdef UART4
|
||||
void TX4_write2buff(u8 dat); //д<>뷢<EFBFBD>ͻ<EFBFBD><CDBB>壬ָ<E5A3AC><D6B8>+1
|
||||
void PrintString4(u8 *puts);
|
||||
#endif
|
||||
|
||||
void UART3_config(void);
|
||||
extern u8 recv_start_flag;
|
||||
extern u32 recv_time;
|
||||
#endif
|
||||
|
||||
601
UART_Set.c
Normal file
601
UART_Set.c
Normal file
@@ -0,0 +1,601 @@
|
||||
#include "UART_Set.h"
|
||||
#include "UART.h"
|
||||
#include "pwm_control.h"
|
||||
#include "string.h"
|
||||
#include "config.h"
|
||||
#include "timer.h"
|
||||
#include "STC8xxxx.h"
|
||||
#include "PWM15bit.h"
|
||||
|
||||
G_Usart g_Usart;
|
||||
G_answer g_answer;
|
||||
S_recv s_recv;
|
||||
|
||||
u8 debug = 0x00;
|
||||
|
||||
|
||||
/*
|
||||
<EFBFBD>жϽ<EFBFBD><EFBFBD>յ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ϸ<EFBFBD>
|
||||
*/
|
||||
void Usart_judge_Data(void)
|
||||
{
|
||||
u8 len = 0;
|
||||
u8 i, sum;
|
||||
sum = 0;
|
||||
g_Usart.ok_flag = 0;
|
||||
|
||||
if((recv_start_flag==1)&&(systick_1ms-recv_time>8))
|
||||
{
|
||||
recv_start_flag=0;
|
||||
#if DEBUG_
|
||||
{
|
||||
for(i=0;i<COM1.RX_Cnt;i++)
|
||||
{
|
||||
g_Usart.recv_buffer[i]=RX1_Buffer[i];
|
||||
}
|
||||
COM1.RX_Cnt = 0;
|
||||
memset(RX1_Buffer,0,sizeof(RX1_Buffer));
|
||||
}
|
||||
#else
|
||||
{
|
||||
len = COM3.RX_Cnt;
|
||||
for(i=0;i<COM3.RX_Cnt;i++)
|
||||
{
|
||||
g_Usart.recv_buffer[i]=RX3_Buffer[i];
|
||||
}
|
||||
COM3.RX_Cnt = 0;
|
||||
memset(RX3_Buffer,0,sizeof(RX3_Buffer));
|
||||
// if(debug) Printbuffer1(g_Usart.recv_buffer,11);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < g_Usart.recv_buffer[UART_FMT_LEN]; i++)
|
||||
{
|
||||
sum += g_Usart.recv_buffer[i];
|
||||
}
|
||||
if (sum == 0xff)
|
||||
{
|
||||
if(len == g_Usart.recv_buffer[UART_FMT_LEN])
|
||||
{
|
||||
if ((g_Usart.recv_buffer[UART_FMT_ADDR_RX] == ADDR_RX) && (g_Usart.recv_buffer[UART_FMT_DEV_TYPE] == DEV_TYPE))
|
||||
{
|
||||
g_Usart.Sn = g_Usart.recv_buffer[UART_FMT_TYPE]&0x0F;
|
||||
|
||||
if ((g_Usart.recv_buffer[UART_FMT_TYPE] & 0x40) == 0x00) //<2F><><EFBFBD>кż<D0BA><C5BC>飬<EFBFBD><EFBFBD>
|
||||
{
|
||||
g_Usart.ok_flag = 1; //<2F><EFBFBD><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
else //<2F><><EFBFBD>к<EFBFBD>Ϊ<EFBFBD>ط<EFBFBD><D8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>øı<C3B8><C4B1><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
{
|
||||
if (g_Usart.Sn == g_Usart.lastsn)
|
||||
{
|
||||
g_Usart.ok_flag = 0;
|
||||
g_answer.short_answer[UART_FMT_CMD]=0xF0;
|
||||
g_answer.short_answer_flag=0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Usart.ok_flag = 1;
|
||||
}
|
||||
}
|
||||
g_Usart.lastsn = g_Usart.Sn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Usart_Deal_Data(void)
|
||||
{
|
||||
u8 i;
|
||||
if(g_Usart.ok_flag)
|
||||
{
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("data ok");
|
||||
}
|
||||
switch(g_Usart.recv_buffer[UART_FMT_CMD])
|
||||
{
|
||||
//<2F><>ѯ״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
||||
case USART_CMD_QUEST:
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("ask");
|
||||
}
|
||||
g_answer.long_answer[UART_FMT_CMD]=USART_CMD_QUEST_A;
|
||||
g_answer.long_answer_flag=0x01;
|
||||
break;
|
||||
//<2F><><EFBFBD>ðٷֱ<D9B7><D6B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
case USART_CMD_SET_BRIGHTNESS:
|
||||
g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SET_BRIGHTNESS_A;
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("percent");
|
||||
}
|
||||
//<2F><>һ<EFBFBD><D2BB>ʹ<EFBFBD><CAB9>λ
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
{
|
||||
s_recv.flag1[i] = 1;
|
||||
s_recv.flag2[i] = 0;
|
||||
s_recv.B_Ch[i] = g_Usart.recv_buffer[21 - i];
|
||||
|
||||
if (s_recv.B_Ch[i] < s_recv.B_min)
|
||||
{
|
||||
s_recv.B_Ch[i] = s_recv.B_min;
|
||||
}
|
||||
|
||||
if (s_recv.B_Ch[i] > s_recv.B_max)
|
||||
{
|
||||
s_recv.B_Ch[i] = s_recv.B_max;
|
||||
}
|
||||
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_Ch[i] * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
|
||||
s_recv.gradual_time[i] = g_Usart.recv_buffer[9] * 10; /*<2A><><EFBFBD>յĽ<D5B5><C4BD><EFBFBD>ʱ<EFBFBD><CAB1>*/
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
*/
|
||||
if (s_recv.gradual_time[i] == 0)
|
||||
{
|
||||
s_recv.gradual_time[i] = 1;
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = (float)(s_pwm.wanttopwm[i] - s_pwm.currpwm[i]) / s_recv.gradual_time[i];
|
||||
if (s_pwm.every_change_10ms[i] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = (float)(s_pwm.currpwm[i] - s_pwm.wanttopwm[i]) / s_recv.gradual_time[i];
|
||||
if (s_pwm.every_change_10ms[i] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//<2F>ڶ<EFBFBD><DAB6><EFBFBD>ʹ<EFBFBD><CAB9>λ
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
{
|
||||
s_recv.flag1[i+8] = 1;
|
||||
s_recv.flag2[i+8] = 0;
|
||||
s_recv.B_Ch[i+8] = g_Usart.recv_buffer[13 - i];
|
||||
|
||||
if (s_recv.B_Ch[i+8] < s_recv.B_min)
|
||||
{
|
||||
s_recv.B_Ch[i+8] = s_recv.B_min;
|
||||
}
|
||||
|
||||
if (s_recv.B_Ch[i+8] > s_recv.B_max)
|
||||
{
|
||||
s_recv.B_Ch[i+8] = s_recv.B_max;
|
||||
}
|
||||
|
||||
s_pwm.wanttopwm[i+8] = PWM_MAX_VALUE - s_recv.B_Ch[i+8] * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i+8];
|
||||
s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
|
||||
s_recv.gradual_time[i+8] = g_Usart.recv_buffer[9] * 10; /*<2A><><EFBFBD>յĽ<D5B5><C4BD><EFBFBD>ʱ<EFBFBD><CAB1>*/
|
||||
|
||||
/*
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
*/
|
||||
if (s_recv.gradual_time[i+8] == 0)
|
||||
{
|
||||
s_recv.gradual_time[i+8] = 1;
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
if (s_pwm.wanttopwm[i+8] > s_pwm.currpwm[i+8])
|
||||
{
|
||||
s_pwm.every_change_10ms[i+8] = (float)(s_pwm.wanttopwm[i+8] - s_pwm.currpwm[i+8]) / s_recv.gradual_time[i+8];
|
||||
if (s_pwm.every_change_10ms[i+8] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i+8] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (s_pwm.wanttopwm[i+8] < s_pwm.currpwm[i+8])
|
||||
{
|
||||
s_pwm.every_change_10ms[i+8] = (float)(s_pwm.currpwm[i+8] - s_pwm.wanttopwm[i+8]) / s_recv.gradual_time[i+8];
|
||||
if (s_pwm.every_change_10ms[i+8] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i+8] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_answer.short_answer_flag=0x01;
|
||||
break;
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>ѭ<EFBFBD><D1AD>
|
||||
case USART_CMD_SET_MODE:
|
||||
g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SET_MODE_A;
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("change light");
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
{
|
||||
s_recv.flag1[i] = 0;
|
||||
s_recv.flag2[i] = 1;
|
||||
s_recv.mode[i] = g_Usart.recv_buffer[9];
|
||||
s_recv.pwm_step[i] = g_Usart.recv_buffer[11];
|
||||
|
||||
if (s_recv.mode[i] == 0x00)
|
||||
{
|
||||
if (g_Usart.recv_buffer[10] == 0x00)
|
||||
{
|
||||
s_recv.forward[i] = 0;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[10] == 0x01)
|
||||
{
|
||||
s_recv.forward[i] = 1;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[10] == 0x02) //<2F><>ת
|
||||
{
|
||||
if (s_recv.forward[i] == 0x01)
|
||||
{
|
||||
s_recv.forward[i] = 0x00;
|
||||
continue; // Ϊ<><CEAA>ֹ<EFBFBD><D6B9>ת֮<D7AA><D6AE>ֱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
|
||||
}
|
||||
|
||||
if (s_recv.forward[i] == 0x00)
|
||||
{
|
||||
s_recv.forward[i] = 0x01;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
{
|
||||
s_recv.flag1[i+8] = 0;
|
||||
s_recv.flag2[i+8] = 1;
|
||||
s_recv.mode[i+8] = g_Usart.recv_buffer[9];
|
||||
s_recv.pwm_step[i+8] = g_Usart.recv_buffer[11];
|
||||
|
||||
if (s_recv.mode[i+8] == 0x00)
|
||||
{
|
||||
if (g_Usart.recv_buffer[10] == 0x00)
|
||||
{
|
||||
s_recv.forward[i+8] = 0;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[10] == 0x01)
|
||||
{
|
||||
s_recv.forward[i+8] = 1;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[10] == 0x02) //<2F><>ת
|
||||
{
|
||||
if (s_recv.forward[i+8] == 0x01)
|
||||
{
|
||||
s_recv.forward[i+8] = 0x00;
|
||||
continue; // Ϊ<><CEAA>ֹ<EFBFBD><D6B9>ת֮<D7AA><D6AE>ֱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
|
||||
}
|
||||
|
||||
if (s_recv.forward[i+8] == 0x00)
|
||||
{
|
||||
s_recv.forward[i+8] = 0x01;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g_answer.short_answer_flag=0x01;
|
||||
break;
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
case USART_CMD_ALL_BRIGHTNESS:
|
||||
g_answer.short_answer[UART_FMT_CMD]=USART_CMD_ALL_BRIGHTNESS_A;
|
||||
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("global light");
|
||||
}
|
||||
|
||||
// s_recv.changeflag = 1;
|
||||
if (g_Usart.recv_buffer[7] & (1 << 5)) //ȫ<>ֿɵ<D6BF><C9B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
s_recv.B_min = g_Usart.recv_buffer[10];
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if ( s_pwm.currvalue[i] < s_recv.B_min)
|
||||
{
|
||||
s_pwm.currvalue[i] = s_recv.B_min;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[7] & (1 << 6)) //ȫ<>ֿɵ<D6BF><C9B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
s_recv.B_max = g_Usart.recv_buffer[9];
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if ( s_pwm.currvalue[i] > s_recv.B_max)
|
||||
{
|
||||
s_pwm.currvalue[i] = s_recv.B_max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[7] & (1 << 7)) //ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
s_recv.global_brightness = g_Usart.recv_buffer[8];
|
||||
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
// s_pwm.wanttopwmflash[i] = PWM_MAX_VALUE - s_pwm.currvalue[i] * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
|
||||
s_recv.flag1[i] = 1;
|
||||
s_recv.flag2[i] = 0;
|
||||
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_Ch[i] * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i]; //<2F><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
if(s_pwm.wanttopwm[i] > PWM_MAX_VALUE)
|
||||
{
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE;
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>10ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>ֵ*/
|
||||
if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = (float)(s_pwm.wanttopwm[i] - s_pwm.currpwm[i]) / s_recv.gradual_time[i];
|
||||
if (s_pwm.every_change_10ms[i] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = (float)(s_pwm.currpwm[i] - s_pwm.wanttopwm[i]) / s_recv.gradual_time[i];
|
||||
if (s_pwm.every_change_10ms[i] < 1)
|
||||
{
|
||||
s_pwm.every_change_10ms[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g_answer.short_answer_flag=0x01;
|
||||
break;
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>״̬
|
||||
case USART_CMD_SWITCH_STATUS:
|
||||
g_answer.short_answer[UART_FMT_CMD]=USART_CMD_SWITCH_STATUS_A;
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("switch state");
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[7] & (1 << i))
|
||||
{
|
||||
if (g_Usart.recv_buffer[9 + i] == 0x01)
|
||||
{
|
||||
s_recv.key_status[i] = 0x01;
|
||||
//s_pwm.currvalue[i] = s_pwm.thenvalue[i];
|
||||
Open_Light(i);
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[9 + i] == 0x00)
|
||||
{
|
||||
//s_pwm.thenvalue[i] = s_pwm.currvalue[i];
|
||||
Close_Light(i);
|
||||
s_recv.flag1[i] = 0;
|
||||
s_recv.flag2[i] = 0;
|
||||
s_recv.mode[i] = 2;
|
||||
s_recv.key_status[i] = 0x00;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[9 + i] == 0x02)
|
||||
{
|
||||
if (s_recv.key_status[i] == 0x00)
|
||||
{
|
||||
s_recv.key_status[i] = 0x01;
|
||||
//s_pwm.currvalue[i] = s_pwm.thenvalue[i];
|
||||
Open_Light(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s_recv.key_status[i] == 0x01)
|
||||
{
|
||||
//s_pwm.thenvalue[i] = s_pwm.currvalue[i];
|
||||
Close_Light(i);
|
||||
s_recv.flag1[i] = 0;
|
||||
s_recv.flag2[i] = 0;
|
||||
s_recv.mode[i] = 2;
|
||||
s_recv.key_status[i] = 0x00;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (g_Usart.recv_buffer[8] & (1 << i))
|
||||
{
|
||||
if (g_Usart.recv_buffer[9 + 8 + i] == 0x01)
|
||||
{
|
||||
s_recv.key_status[i+8] = 0x01;
|
||||
//s_pwm.currvalue[i+8] = s_pwm.thenvalue[i];
|
||||
Open_Light(i+8);
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[9 +8 + i] == 0x00)
|
||||
{
|
||||
//s_pwm.thenvalue[i+8] = s_pwm.currvalue[i+8];
|
||||
Close_Light(i+8);
|
||||
s_recv.flag1[i+8] = 0;
|
||||
s_recv.flag2[i+8] = 0;
|
||||
s_recv.mode[i+8] = 2;
|
||||
s_recv.key_status[i+8] = 0x00;
|
||||
}
|
||||
|
||||
if (g_Usart.recv_buffer[9 + 8 + i] == 0x02)
|
||||
{
|
||||
if (s_recv.key_status[i+8] == 0x00)
|
||||
{
|
||||
s_recv.key_status[i+8] = 0x01;
|
||||
//s_pwm.currvalue[i+8] = s_pwm.thenvalue[i];
|
||||
Open_Light(i+8);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (s_recv.key_status[i+8] == 0x01)
|
||||
{
|
||||
//s_pwm.thenvalue[i+8] = s_pwm.currvalue[i+8];
|
||||
Close_Light(i+8);
|
||||
s_recv.flag1[i+8] = 0;
|
||||
s_recv.flag2[i+8] = 0;
|
||||
s_recv.mode[i+8] = 2;
|
||||
s_recv.key_status[i+8] = 0x00;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g_answer.short_answer_flag=0x01;
|
||||
break;
|
||||
case USART_CMD_DEBUG_SET:
|
||||
g_answer.short_answer[UART_FMT_CMD]=USART_CMD_DEBUG_SET_A;
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("debug");
|
||||
}
|
||||
debug = g_Usart.recv_buffer[7];
|
||||
g_answer.short_answer_flag=0x01;
|
||||
break;
|
||||
case Usart_CMD_Version:
|
||||
g_answer.version_answer[UART_FMT_CMD]=Usart_CMD_Version_A;
|
||||
g_answer.version_answer_flag=0x01;
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("version");
|
||||
}
|
||||
break;
|
||||
}
|
||||
g_Usart.ok_flag=0;
|
||||
}
|
||||
}
|
||||
|
||||
void Usart_answer(void)
|
||||
{
|
||||
u8 i=0;
|
||||
u8 checksum=0;
|
||||
if(g_answer.long_answer_flag)
|
||||
{
|
||||
g_answer.long_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
g_answer.long_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
g_answer.long_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
g_answer.long_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
g_answer.long_answer[UART_FMT_LEN]=0x14;
|
||||
g_answer.long_answer[7] = s_recv.global_brightness;
|
||||
for(i=0;i<12;i++)
|
||||
{
|
||||
g_answer.long_answer[8+i] = s_pwm.currvalue[11-i];
|
||||
if(s_recv.key_status[i] == 0x01)
|
||||
{
|
||||
g_answer.long_answer[8+i] |= 0x80;
|
||||
}
|
||||
}
|
||||
checksum=sumfunc(g_answer.long_answer,0x14);
|
||||
g_answer.long_answer[UART_FMT_CKS]=checksum;
|
||||
|
||||
Printbuffer3(g_answer.long_answer,0x14); //<2F><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ
|
||||
|
||||
if(debug)
|
||||
{
|
||||
// PrintString1("long answer");
|
||||
}
|
||||
g_answer.long_answer_flag=0;
|
||||
memset(g_Usart.recv_buffer,0,32);
|
||||
}
|
||||
if(g_answer.short_answer_flag)
|
||||
{
|
||||
g_answer.short_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
g_answer.short_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
g_answer.short_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
g_answer.short_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
g_answer.short_answer[UART_FMT_LEN]=0x07;
|
||||
checksum=sumfunc(g_answer.short_answer,0x07);
|
||||
g_answer.short_answer[UART_FMT_CKS]=checksum;
|
||||
Printbuffer3(g_answer.short_answer,0x07);
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("short answer");
|
||||
}
|
||||
|
||||
|
||||
g_answer.short_answer_flag=0;
|
||||
memset(g_Usart.recv_buffer,0,32);
|
||||
}
|
||||
|
||||
if(g_answer.version_answer_flag)
|
||||
{
|
||||
g_answer.version_answer[UART_FMT_ADDR_TX]=ADDR_RX;
|
||||
g_answer.version_answer[UART_FMT_TYPE]=g_Usart.Sn;
|
||||
g_answer.version_answer[UART_FMT_DEV_TYPE]=DEV_TYPE;
|
||||
g_answer.version_answer[UART_FMT_ADDR_RX]=g_Usart.recv_buffer[UART_FMT_ADDR_TX];
|
||||
g_answer.version_answer[UART_FMT_LEN]=0x09;
|
||||
g_answer.version_answer[UART_FMT_CMD+1]=Version_High;
|
||||
g_answer.version_answer[UART_FMT_CMD+2]=Version_Low;
|
||||
|
||||
checksum=sumfunc(g_answer.version_answer,0x09);
|
||||
g_answer.version_answer[UART_FMT_CKS]=checksum;
|
||||
Printbuffer3(g_answer.version_answer,0x09);
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("version_answer");
|
||||
}
|
||||
g_answer.version_answer_flag=0;
|
||||
memset(g_Usart.recv_buffer,0,32);
|
||||
}
|
||||
memset(&g_answer,0,sizeof(g_answer));
|
||||
}
|
||||
|
||||
u8 sumfunc(u8* answer,u8 len)
|
||||
{
|
||||
u8 m = 0;
|
||||
u8 j;
|
||||
for (j = 0; j < len; j++)
|
||||
{
|
||||
if (5 == j) continue;
|
||||
m += *(answer+j);
|
||||
}
|
||||
return ~m;
|
||||
}
|
||||
100
UART_Set.h
Normal file
100
UART_Set.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef _UART_SET_H
|
||||
#define _UART_SET_H
|
||||
#include "STC8xxxx.h"
|
||||
#define USART_CMD_QUEST 0x20
|
||||
#define USART_CMD_SET_BRIGHTNESS 0x21
|
||||
#define USART_CMD_SET_MODE 0x22
|
||||
#define USART_CMD_ALL_BRIGHTNESS 0x23
|
||||
#define USART_CMD_SWITCH_STATUS 0x24
|
||||
#define USART_CMD_DEBUG_SET 0x25 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>㹻<EFBFBD>Ҳ<EFBFBD><D2B2>ÿ<EFBFBD><C3BF>ƣ<EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>
|
||||
#define Usart_CMD_Version 0x26
|
||||
|
||||
#define USART_TEST_MODE 0xE0
|
||||
#define USART_TEST_DATA 0xE1
|
||||
|
||||
#define USART_CMD_QUEST_A 0x30
|
||||
#define USART_CMD_SET_BRIGHTNESS_A 0x31
|
||||
#define USART_CMD_SET_MODE_A 0x32
|
||||
#define USART_CMD_ALL_BRIGHTNESS_A 0x33
|
||||
#define USART_CMD_SWITCH_STATUS_A 0x34
|
||||
#define USART_CMD_DEBUG_SET_A 0x35
|
||||
#define Usart_CMD_Version_A 0x36
|
||||
|
||||
#define USART_TEST_MODE_A 0xF0
|
||||
#define USART_TEST_DATA_A 0xF1
|
||||
|
||||
#define ADDR_RX 0x01 //C12_CH12<31>ĵ<EFBFBD>ַ
|
||||
#define DEV_TYPE 0x03
|
||||
|
||||
#define Version_High 0x13 //<2F><><EFBFBD><EFBFBD><EFBFBD>汾
|
||||
#define Version_Low 0x00
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_FMT_ADDR_TX = 0x00,
|
||||
UART_FMT_TYPE,
|
||||
UART_FMT_DEV_TYPE,
|
||||
UART_FMT_ADDR_RX,
|
||||
UART_FMT_LEN,
|
||||
UART_FMT_CKS,
|
||||
UART_FMT_CMD,
|
||||
} UART_FMT_e;
|
||||
|
||||
typedef struct Usart
|
||||
{
|
||||
u8 lastsn;
|
||||
u8 Sn;
|
||||
u8 ok_flag;
|
||||
u8 recv_buffer[32];
|
||||
}xdata G_Usart;
|
||||
|
||||
typedef struct answer
|
||||
{
|
||||
u8 short_answer[7];
|
||||
u8 long_answer[20];
|
||||
u8 long_answer_flag;
|
||||
u8 short_answer_flag;
|
||||
u8 version_answer_flag;
|
||||
u8 version_answer[9];
|
||||
}xdata G_answer;
|
||||
|
||||
//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ݵĽṹ<C4BD><E1B9B9>
|
||||
/*
|
||||
* <20>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʹ<EFBFBD>ܱ<EFBFBD>־λ
|
||||
* flag1ָ<31><D6B8><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x21
|
||||
* flag2ָ<32><D6B8><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>0x22
|
||||
* <20><><EFBFBD><EFBFBD><DFBB>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
u16 flag1[12];
|
||||
u16 flag2[12];
|
||||
|
||||
//0x21
|
||||
u16 gradual_time[12];
|
||||
u16 B_Ch[12];
|
||||
|
||||
//0x22
|
||||
u16 mode[12];
|
||||
u16 forward[12];
|
||||
u16 pwm_step[12];
|
||||
|
||||
//0x23
|
||||
u16 global_brightness;
|
||||
u16 B_max;
|
||||
u16 B_min;
|
||||
// u16 changeflag;
|
||||
|
||||
//0x24
|
||||
u16 key_status[12];
|
||||
}xdata S_recv;
|
||||
|
||||
extern S_recv s_recv;
|
||||
extern G_answer g_answer;
|
||||
extern G_Usart g_Usart;
|
||||
void Usart_Deal_Data(void);
|
||||
void Usart_judge_Data(void);
|
||||
void Usart_answer(void);
|
||||
u8 sumfunc(u8* answer,u8 len);
|
||||
extern u8 debug;
|
||||
#endif
|
||||
35
WDT.c
Normal file
35
WDT.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#include "WDT.h"
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: void WDT_Inilize(WDT_InitTypeDef *WDT)
|
||||
// <20><><EFBFBD><EFBFBD>: <20><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: WDT: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>WDT.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: none.
|
||||
// <20>汾: V1.0, 2020-09-16
|
||||
//========================================================================
|
||||
void WDT_Inilize(WDT_InitTypeDef *WDT)
|
||||
{
|
||||
if(WDT->WDT_Enable == ENABLE) WDT_CONTR = D_EN_WDT; //ʹ<>ܿ<EFBFBD><DCBF>Ź<EFBFBD>
|
||||
|
||||
WDT_PS_Set(WDT->WDT_PS); //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5> WDT_SCALE_2,WDT_SCALE_4,WDT_SCALE_8,WDT_SCALE_16,WDT_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256
|
||||
if(WDT->WDT_IDLE_Mode == WDT_IDLE_STOP) WDT_CONTR &= ~0x08; //IDLEģʽֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
else WDT_CONTR |= 0x08; //IDLEģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
/********************* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD> *************************/
|
||||
void WDT_Clear (void)
|
||||
{
|
||||
WDT_CONTR |= D_CLR_WDT; // ι<><CEB9>
|
||||
}
|
||||
40
WDT.h
Normal file
40
WDT.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __WDT_H
|
||||
#define __WDT_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define WDT_IDLE_STOP 0
|
||||
#define WDT_IDLE_RUN 1
|
||||
|
||||
#define WDT_SCALE_2 0 /* WDT Timeout=(12*32768*SCALE)/SYSclk */
|
||||
#define WDT_SCALE_4 1
|
||||
#define WDT_SCALE_8 2
|
||||
#define WDT_SCALE_16 3
|
||||
#define WDT_SCALE_32 4
|
||||
#define WDT_SCALE_64 5
|
||||
#define WDT_SCALE_128 6
|
||||
#define WDT_SCALE_256 7
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 WDT_Enable; //<2F><><EFBFBD>Ź<EFBFBD>ʹ<EFBFBD><CAB9> ENABLE,DISABLE
|
||||
u8 WDT_IDLE_Mode; //IDLEģʽֹͣ<CDA3><D6B9><EFBFBD><EFBFBD> WDT_IDLE_STOP,WDT_IDLE_RUN
|
||||
u8 WDT_PS; //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5> WDT_SCALE_2,WDT_SCALE_4,WDT_SCALE_8,WDT_SCALE_16,WDT_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256
|
||||
} WDT_InitTypeDef;
|
||||
|
||||
void WDT_Inilize(WDT_InitTypeDef *WDT);
|
||||
void WDT_Clear (void);
|
||||
|
||||
#endif
|
||||
19
config.h
Normal file
19
config.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef __CONFIG_H
|
||||
#define __CONFIG_H
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
#define MAIN_Fosc 22118400L //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
//#define MAIN_Fosc 12000000L //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
//#define MAIN_Fosc 11059200L //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
//#define MAIN_Fosc 5529600L //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
//#define MAIN_Fosc 24000000L //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
#define STC8Gxx //STC8Gϵ<47><CFB5>
|
||||
|
||||
/*********************************************************/
|
||||
#define DEBUG_ 0
|
||||
#include "STC8xxxx.H"
|
||||
|
||||
|
||||
#endif
|
||||
155
key.c
Normal file
155
key.c
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "key.h"
|
||||
#include "GPIO.h"
|
||||
#include "timer.h"
|
||||
#include "string.h"
|
||||
#include "pwm_control.h"
|
||||
KEY_t g_Key;
|
||||
|
||||
void Key_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure1; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
/***********************************1*******************************************/
|
||||
GPIO_InitStructure1.Pin = GPIO_Pin_4; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO 4
|
||||
GPIO_InitStructure1.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp
|
||||
GPIO_Inilize(GPIO_P4,&GPIO_InitStructure1); //<2F><>ʼ<EFBFBD><CABC>
|
||||
memset(&g_Key, 0, sizeof(g_Key));
|
||||
}
|
||||
|
||||
void Key_ScanTask(void)
|
||||
{
|
||||
u8 i;
|
||||
static u32 update_10ms = 0;
|
||||
|
||||
if (systick_1ms - update_10ms > 10)
|
||||
{
|
||||
update_10ms = systick_1ms;
|
||||
|
||||
for (i = 0; i < KEY_CHN_MAX; i++)
|
||||
{
|
||||
switch (g_Key.KEY_STA[i])
|
||||
{
|
||||
case KEY_STA_S0:
|
||||
if ( P44 == KEY_PRESS )
|
||||
{
|
||||
if (g_Key.delayCnt[i] < KEY_DELAY_COUNT)
|
||||
{
|
||||
g_Key.delayCnt[i]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Key.KEY_STA[i] = KEY_STA_S1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
g_Key.key_time[i] = 0;
|
||||
g_Key.delayCnt[i] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Key.delayCnt[i] = 0;
|
||||
g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
g_Key.key_val[i] = KEY_VAL_NOT;
|
||||
}
|
||||
break;
|
||||
case KEY_STA_S1:
|
||||
g_Key.key_time[i] ++;
|
||||
if ( g_Key.key_time[i] < KEY_DELAY_COUNT_LONG )
|
||||
{
|
||||
if ( P44 == KEY_LOOSEN ) //<2F>ɿ<EFBFBD>
|
||||
{
|
||||
g_Key.key_val[i] = KEY_VAL_SHORT_PRESS; //<2F>̰<EFBFBD><CCB0>ɿ<EFBFBD>
|
||||
g_Key.key_time[i] = 0;
|
||||
g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Key.KEY_STA[i] = KEY_STA_S2;
|
||||
g_Key.key_time[i] = 0;
|
||||
g_Key.key_longPress[i] = KEY_VAL_SINGLE_LONG_PRESS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
g_Key.key_val[i] = KEY_VAL_CONT_LONG_PRESS; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_STA_S2:
|
||||
g_Key.key_longPress[i] = KEY_VAL_NOT;
|
||||
if ( P44 == KEY_LOOSEN )
|
||||
{
|
||||
g_Key.KEY_STA[i] = KEY_STA_S0;
|
||||
g_Key.key_val[i] = KEY_VAL_LONG_PRESS_LOOSEN; //<2F><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KEY_TEST(void)
|
||||
{
|
||||
u8 flag;
|
||||
if (g_Key.key_val[KEY_CH1] == KEY_VAL_SHORT_PRESS)
|
||||
{
|
||||
g_Key.key_val[KEY_CH1] = KEY_VAL_NOT;
|
||||
s_pwm.key_value++;
|
||||
switch (s_pwm.key_value)
|
||||
{
|
||||
case 1:
|
||||
s_pwm.currpwm[0] = 2000ul; //90%<25><><EFBFBD><EFBFBD>
|
||||
s_pwm.currvalue[0]=0x5A;
|
||||
break;
|
||||
case 2:
|
||||
s_pwm.currpwm[1] = 2000ul;
|
||||
s_pwm.currvalue[1]=0x5A;
|
||||
break;
|
||||
case 3:
|
||||
s_pwm.currpwm[2] = 2000ul;
|
||||
s_pwm.currvalue[2]=0x5A;
|
||||
break;
|
||||
case 4:
|
||||
s_pwm.currpwm[3] = 2000ul;
|
||||
s_pwm.currvalue[3]=0x5A;
|
||||
break;
|
||||
case 5:
|
||||
s_pwm.currpwm[4] = 2000ul;
|
||||
s_pwm.currvalue[4]=0x5A;
|
||||
break;
|
||||
case 6:
|
||||
s_pwm.currpwm[5] = 2000ul;
|
||||
s_pwm.currvalue[5]=0x5A;
|
||||
break;
|
||||
case 7:
|
||||
s_pwm.currpwm[6] = 2000ul;
|
||||
s_pwm.currvalue[6]=0x5A;
|
||||
break;
|
||||
case 8:
|
||||
s_pwm.currpwm[7] = 2000ul;
|
||||
s_pwm.currvalue[7]=0x5A;
|
||||
break;
|
||||
case 9:
|
||||
s_pwm.currpwm[8] = 2000ul;
|
||||
s_pwm.currvalue[8]=0x5A;
|
||||
break;
|
||||
case 10:
|
||||
s_pwm.currpwm[9] = 2000ul;
|
||||
s_pwm.currvalue[9]=0x5A;
|
||||
break;
|
||||
case 11:
|
||||
s_pwm.currpwm[10] = 2000ul;
|
||||
s_pwm.currvalue[10]=0x5A;
|
||||
break;
|
||||
case 12:
|
||||
s_pwm.currpwm[11] = 2000ul;
|
||||
s_pwm.currvalue[11]=0x5A;
|
||||
break;
|
||||
case 13:
|
||||
for(flag=0;flag<12;flag++)
|
||||
{
|
||||
s_pwm.currpwm[flag] = PWM_MAX_VALUE;
|
||||
s_pwm.currvalue[flag]=0x00;
|
||||
}
|
||||
s_pwm.key_value = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
key.h
Normal file
50
key.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef KEY_H
|
||||
#define KEY_H
|
||||
#include "STC8xxxx.h"
|
||||
#define DELAY_TIME 10
|
||||
|
||||
#define KEY_DELAY_COUNT 2
|
||||
#define KEY_DELAY_COUNT_LONG 100
|
||||
#define KEY_PRESS 0
|
||||
#define KEY_LOOSEN 1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_CH1,
|
||||
KEY_CHN_MAX,
|
||||
}KEY_CHN_e;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_STA_S0 = 0,
|
||||
KEY_STA_S1 = 1,
|
||||
KEY_STA_S2 = 2,
|
||||
}KEY_STA_e;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_VAL_NOT, //û<><C3BB><EFBFBD><EFBFBD>
|
||||
KEY_VAL_SHORT_PRESS, //<2F><><EFBFBD><EFBFBD>
|
||||
KEY_VAL_CONT_LONG_PRESS, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
KEY_VAL_SINGLE_LONG_PRESS, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
KEY_VAL_LONG_PRESS_LOOSEN, //<2F><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
|
||||
}KEY_VAL_e;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 Key_pin[KEY_CHN_MAX];
|
||||
u8 KEY_STA[KEY_CHN_MAX];
|
||||
u8 key_val[KEY_CHN_MAX]; //0:û<><C3BB><EFBFBD><EFBFBD>, 1:<3A>̰<EFBFBD><CCB0>ɿ<EFBFBD>, 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3:<3A><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
|
||||
u8 key_longPress[KEY_CHN_MAX]; //0:û<><C3BB><EFBFBD><EFBFBD>, 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
u8 key_time[KEY_CHN_MAX];
|
||||
u8 delayCnt[KEY_CHN_MAX];
|
||||
}KEY_t;
|
||||
|
||||
|
||||
void Key_Init(void);
|
||||
void Key_ScanTask(void);
|
||||
void KEY_TEST(void);
|
||||
|
||||
extern KEY_t g_Key;
|
||||
|
||||
#endif
|
||||
1923
light_V19.uvgui.cc
Normal file
1923
light_V19.uvgui.cc
Normal file
File diff suppressed because one or more lines are too long
293
light_V19.uvopt
Normal file
293
light_V19.uvopt
Normal file
@@ -0,0 +1,293 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_opt.xsd">
|
||||
|
||||
<SchemaVersion>1.0</SchemaVersion>
|
||||
|
||||
<Header>### uVision Project, (C) Keil Software</Header>
|
||||
|
||||
<Extensions>
|
||||
<cExt>*.c</cExt>
|
||||
<aExt>*.s*; *.src; *.a*</aExt>
|
||||
<oExt>*.obj; *.o</oExt>
|
||||
<lExt>*.lib</lExt>
|
||||
<tExt>*.txt; *.h; *.inc</tExt>
|
||||
<pExt>*.plm</pExt>
|
||||
<CppX>*.cpp</CppX>
|
||||
<nMigrate>0</nMigrate>
|
||||
</Extensions>
|
||||
|
||||
<DaveTm>
|
||||
<dwLowDateTime>0</dwLowDateTime>
|
||||
<dwHighDateTime>0</dwHighDateTime>
|
||||
</DaveTm>
|
||||
|
||||
<Target>
|
||||
<TargetName>Target 1</TargetName>
|
||||
<ToolsetNumber>0x0</ToolsetNumber>
|
||||
<ToolsetName>MCS-51</ToolsetName>
|
||||
<TargetOption>
|
||||
<CLK51>35000000</CLK51>
|
||||
<OPTTT>
|
||||
<gFlags>1</gFlags>
|
||||
<BeepAtEnd>1</BeepAtEnd>
|
||||
<RunSim>1</RunSim>
|
||||
<RunTarget>0</RunTarget>
|
||||
<RunAbUc>0</RunAbUc>
|
||||
</OPTTT>
|
||||
<OPTHX>
|
||||
<HexSelection>0</HexSelection>
|
||||
<FlashByte>65535</FlashByte>
|
||||
<HexRangeLowAddress>0</HexRangeLowAddress>
|
||||
<HexRangeHighAddress>0</HexRangeHighAddress>
|
||||
<HexOffset>0</HexOffset>
|
||||
</OPTHX>
|
||||
<OPTLEX>
|
||||
<PageWidth>120</PageWidth>
|
||||
<PageLength>65</PageLength>
|
||||
<TabStop>8</TabStop>
|
||||
<ListingPath>.\Listings\</ListingPath>
|
||||
</OPTLEX>
|
||||
<ListingPage>
|
||||
<CreateCListing>1</CreateCListing>
|
||||
<CreateAListing>1</CreateAListing>
|
||||
<CreateLListing>1</CreateLListing>
|
||||
<CreateIListing>0</CreateIListing>
|
||||
<AsmCond>1</AsmCond>
|
||||
<AsmSymb>1</AsmSymb>
|
||||
<AsmXref>0</AsmXref>
|
||||
<CCond>1</CCond>
|
||||
<CCode>0</CCode>
|
||||
<CListInc>0</CListInc>
|
||||
<CSymb>0</CSymb>
|
||||
<LinkerCodeListing>0</LinkerCodeListing>
|
||||
</ListingPage>
|
||||
<OPTXL>
|
||||
<LMap>1</LMap>
|
||||
<LComments>1</LComments>
|
||||
<LGenerateSymbols>1</LGenerateSymbols>
|
||||
<LLibSym>1</LLibSym>
|
||||
<LLines>1</LLines>
|
||||
<LLocSym>1</LLocSym>
|
||||
<LPubSym>1</LPubSym>
|
||||
<LXref>0</LXref>
|
||||
<LExpSel>0</LExpSel>
|
||||
</OPTXL>
|
||||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>0</CpuCode>
|
||||
<DebugOpt>
|
||||
<uSim>0</uSim>
|
||||
<uTrg>1</uTrg>
|
||||
<sLdApp>1</sLdApp>
|
||||
<sGomain>1</sGomain>
|
||||
<sRbreak>1</sRbreak>
|
||||
<sRwatch>1</sRwatch>
|
||||
<sRmem>1</sRmem>
|
||||
<sRfunc>1</sRfunc>
|
||||
<sRbox>1</sRbox>
|
||||
<tLdApp>1</tLdApp>
|
||||
<tGomain>0</tGomain>
|
||||
<tRbreak>1</tRbreak>
|
||||
<tRwatch>1</tRwatch>
|
||||
<tRmem>1</tRmem>
|
||||
<tRfunc>0</tRfunc>
|
||||
<tRbox>1</tRbox>
|
||||
<tRtrace>0</tRtrace>
|
||||
<sRSysVw>1</sRSysVw>
|
||||
<tRSysVw>1</tRSysVw>
|
||||
<sRunDeb>0</sRunDeb>
|
||||
<sLrtime>0</sLrtime>
|
||||
<bEvRecOn>1</bEvRecOn>
|
||||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>9</nTsel>
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
<sDlgDll></sDlgDll>
|
||||
<sDlgPa></sDlgPa>
|
||||
<sIfile></sIfile>
|
||||
<tDll></tDll>
|
||||
<tDllPa></tDllPa>
|
||||
<tDlgDll></tDlgDll>
|
||||
<tDlgPa></tDlgPa>
|
||||
<tIfile></tIfile>
|
||||
<pMon>BIN\STCMON51.DLL</pMon>
|
||||
</DebugOpt>
|
||||
<Breakpoint/>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
<DebugFlag>
|
||||
<trace>0</trace>
|
||||
<periodic>0</periodic>
|
||||
<aLwin>0</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
<aPa>0</aPa>
|
||||
<viewmode>0</viewmode>
|
||||
<vrSel>0</vrSel>
|
||||
<aSym>0</aSym>
|
||||
<aTbox>0</aTbox>
|
||||
<AscS1>0</AscS1>
|
||||
<AscS2>0</AscS2>
|
||||
<AscS3>0</AscS3>
|
||||
<aSer3>0</aSer3>
|
||||
<eProf>0</eProf>
|
||||
<aLa>0</aLa>
|
||||
<aPa1>0</aPa1>
|
||||
<AscS4>0</AscS4>
|
||||
<aSer4>0</aSer4>
|
||||
<StkLoc>0</StkLoc>
|
||||
<TrcWin>0</TrcWin>
|
||||
<newCpu>0</newCpu>
|
||||
<uProt>0</uProt>
|
||||
</DebugFlag>
|
||||
<LintExecutable></LintExecutable>
|
||||
<LintConfigFile></LintConfigFile>
|
||||
<bLintAuto>0</bLintAuto>
|
||||
<bAutoGenD>0</bAutoGenD>
|
||||
<LntExFlags>0</LntExFlags>
|
||||
<pMisraName></pMisraName>
|
||||
<pszMrule></pszMrule>
|
||||
<pSingCmds></pSingCmds>
|
||||
<pMultCmds></pMultCmds>
|
||||
<pMisraNamep></pMisraNamep>
|
||||
<pszMrulep></pszMrulep>
|
||||
<pSingCmdsp></pSingCmdsp>
|
||||
<pMultCmdsp></pMultCmdsp>
|
||||
</TargetOption>
|
||||
</Target>
|
||||
|
||||
<Group>
|
||||
<GroupName>Source Group 1</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>1</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\GPIO.c</PathWithFileName>
|
||||
<FilenameWithoutPath>GPIO.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>2</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\main.c</PathWithFileName>
|
||||
<FilenameWithoutPath>main.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\UART.C</PathWithFileName>
|
||||
<FilenameWithoutPath>UART.C</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\UART_Set.c</PathWithFileName>
|
||||
<FilenameWithoutPath>UART_Set.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\pwm_control.c</PathWithFileName>
|
||||
<FilenameWithoutPath>pwm_control.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Start_Init.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Start_Init.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\PWM15bit.c</PathWithFileName>
|
||||
<FilenameWithoutPath>PWM15bit.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\timer.c</PathWithFileName>
|
||||
<FilenameWithoutPath>timer.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\key.c</PathWithFileName>
|
||||
<FilenameWithoutPath>key.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\WDT.c</PathWithFileName>
|
||||
<FilenameWithoutPath>WDT.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
</ProjectOpt>
|
||||
435
light_V19.uvproj
Normal file
435
light_V19.uvproj
Normal file
@@ -0,0 +1,435 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_proj.xsd">
|
||||
|
||||
<SchemaVersion>1.1</SchemaVersion>
|
||||
|
||||
<Header>### uVision Project, (C) Keil Software</Header>
|
||||
|
||||
<Targets>
|
||||
<Target>
|
||||
<TargetName>Target 1</TargetName>
|
||||
<ToolsetNumber>0x0</ToolsetNumber>
|
||||
<ToolsetName>MCS-51</ToolsetName>
|
||||
<uAC6>0</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
<Device>STC8G2K64S4 Series</Device>
|
||||
<Vendor>STC</Vendor>
|
||||
<Cpu>IRAM(0-0xFF) XRAM(0-0x07FF) IROM(0-0xFFF8) CLOCK(35000000) MODP2</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
<StartupFile>"LIB\STARTUP.A51" ("Standard 8051 Startup Code")</StartupFile>
|
||||
<FlashDriverDll></FlashDriverDll>
|
||||
<DeviceId>63332</DeviceId>
|
||||
<RegisterFile>STC8.H</RegisterFile>
|
||||
<MemoryEnv></MemoryEnv>
|
||||
<Cmp></Cmp>
|
||||
<Asm></Asm>
|
||||
<Linker></Linker>
|
||||
<OHString></OHString>
|
||||
<InfinionOptionDll></InfinionOptionDll>
|
||||
<SLE66CMisc></SLE66CMisc>
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile></SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath>D:\keil_v5\C51\BIN\</BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
<LibPath></LibPath>
|
||||
<RegisterFilePath></RegisterFilePath>
|
||||
<DBRegisterFilePath>STC\</DBRegisterFilePath>
|
||||
<TargetStatus>
|
||||
<Error>0</Error>
|
||||
<ExitCodeStop>0</ExitCodeStop>
|
||||
<ButtonStop>0</ButtonStop>
|
||||
<NotGenerated>0</NotGenerated>
|
||||
<InvalidFlash>1</InvalidFlash>
|
||||
</TargetStatus>
|
||||
<OutputDirectory>.\Objects\</OutputDirectory>
|
||||
<OutputName>BLV_C12_Dimm_V19</OutputName>
|
||||
<CreateExecutable>1</CreateExecutable>
|
||||
<CreateLib>0</CreateLib>
|
||||
<CreateHexFile>1</CreateHexFile>
|
||||
<DebugInformation>1</DebugInformation>
|
||||
<BrowseInformation>1</BrowseInformation>
|
||||
<ListingPath>.\Listings\</ListingPath>
|
||||
<HexFormatSelection>0</HexFormatSelection>
|
||||
<Merge32K>0</Merge32K>
|
||||
<CreateBatchFile>0</CreateBatchFile>
|
||||
<BeforeCompile>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopU1X>0</nStopU1X>
|
||||
<nStopU2X>0</nStopU2X>
|
||||
</BeforeCompile>
|
||||
<BeforeMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopB1X>0</nStopB1X>
|
||||
<nStopB2X>0</nStopB2X>
|
||||
</BeforeMake>
|
||||
<AfterMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopA1X>0</nStopA1X>
|
||||
<nStopA2X>0</nStopA2X>
|
||||
</AfterMake>
|
||||
<SelectedForBatchBuild>0</SelectedForBatchBuild>
|
||||
<SVCSIdString></SVCSIdString>
|
||||
</TargetCommonOption>
|
||||
<CommonProperty>
|
||||
<UseCPPCompiler>0</UseCPPCompiler>
|
||||
<RVCTCodeConst>0</RVCTCodeConst>
|
||||
<RVCTZI>0</RVCTZI>
|
||||
<RVCTOtherData>0</RVCTOtherData>
|
||||
<ModuleSelection>0</ModuleSelection>
|
||||
<IncludeInBuild>1</IncludeInBuild>
|
||||
<AlwaysBuild>0</AlwaysBuild>
|
||||
<GenerateAssemblyFile>0</GenerateAssemblyFile>
|
||||
<AssembleAssemblyFile>0</AssembleAssemblyFile>
|
||||
<PublicsOnly>0</PublicsOnly>
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
<BankNo>65535</BankNo>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>S8051.DLL</SimDllName>
|
||||
<SimDllArguments></SimDllArguments>
|
||||
<SimDlgDll>DP51.DLL</SimDlgDll>
|
||||
<SimDlgDllArguments>-pDP8051</SimDlgDllArguments>
|
||||
<TargetDllName>S8051.DLL</TargetDllName>
|
||||
<TargetDllArguments></TargetDllArguments>
|
||||
<TargetDlgDll>TP51.DLL</TargetDlgDll>
|
||||
<TargetDlgDllArguments>-p51</TargetDlgDllArguments>
|
||||
</DllOption>
|
||||
<DebugOption>
|
||||
<OPTHX>
|
||||
<HexSelection>0</HexSelection>
|
||||
<HexRangeLowAddress>0</HexRangeLowAddress>
|
||||
<HexRangeHighAddress>0</HexRangeHighAddress>
|
||||
<HexOffset>0</HexOffset>
|
||||
<Oh166RecLen>16</Oh166RecLen>
|
||||
</OPTHX>
|
||||
<Simulator>
|
||||
<UseSimulator>0</UseSimulator>
|
||||
<LoadApplicationAtStartup>1</LoadApplicationAtStartup>
|
||||
<RunToMain>1</RunToMain>
|
||||
<RestoreBreakpoints>1</RestoreBreakpoints>
|
||||
<RestoreWatchpoints>1</RestoreWatchpoints>
|
||||
<RestoreMemoryDisplay>1</RestoreMemoryDisplay>
|
||||
<RestoreFunctions>1</RestoreFunctions>
|
||||
<RestoreToolbox>1</RestoreToolbox>
|
||||
<LimitSpeedToRealTime>0</LimitSpeedToRealTime>
|
||||
<RestoreSysVw>1</RestoreSysVw>
|
||||
</Simulator>
|
||||
<Target>
|
||||
<UseTarget>1</UseTarget>
|
||||
<LoadApplicationAtStartup>1</LoadApplicationAtStartup>
|
||||
<RunToMain>0</RunToMain>
|
||||
<RestoreBreakpoints>1</RestoreBreakpoints>
|
||||
<RestoreWatchpoints>1</RestoreWatchpoints>
|
||||
<RestoreMemoryDisplay>1</RestoreMemoryDisplay>
|
||||
<RestoreFunctions>0</RestoreFunctions>
|
||||
<RestoreToolbox>1</RestoreToolbox>
|
||||
<RestoreTracepoints>0</RestoreTracepoints>
|
||||
<RestoreSysVw>1</RestoreSysVw>
|
||||
</Target>
|
||||
<RunDebugAfterBuild>0</RunDebugAfterBuild>
|
||||
<TargetSelection>9</TargetSelection>
|
||||
<SimDlls>
|
||||
<CpuDll></CpuDll>
|
||||
<CpuDllArguments></CpuDllArguments>
|
||||
<PeripheralDll></PeripheralDll>
|
||||
<PeripheralDllArguments></PeripheralDllArguments>
|
||||
<InitializationFile></InitializationFile>
|
||||
</SimDlls>
|
||||
<TargetDlls>
|
||||
<CpuDll></CpuDll>
|
||||
<CpuDllArguments></CpuDllArguments>
|
||||
<PeripheralDll></PeripheralDll>
|
||||
<PeripheralDllArguments></PeripheralDllArguments>
|
||||
<InitializationFile></InitializationFile>
|
||||
<Driver>BIN\STCMON51.DLL</Driver>
|
||||
</TargetDlls>
|
||||
</DebugOption>
|
||||
<Utilities>
|
||||
<Flash1>
|
||||
<UseTargetDll>1</UseTargetDll>
|
||||
<UseExternalTool>0</UseExternalTool>
|
||||
<RunIndependent>0</RunIndependent>
|
||||
<UpdateFlashBeforeDebugging>0</UpdateFlashBeforeDebugging>
|
||||
<Capability>0</Capability>
|
||||
<DriverSelection>-1</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>0</bUseTDR>
|
||||
<Flash2></Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<Target51>
|
||||
<Target51Misc>
|
||||
<MemoryModel>0</MemoryModel>
|
||||
<RTOS>0</RTOS>
|
||||
<RomSize>2</RomSize>
|
||||
<DataHold>0</DataHold>
|
||||
<XDataHold>0</XDataHold>
|
||||
<UseOnchipRom>0</UseOnchipRom>
|
||||
<UseOnchipArithmetic>0</UseOnchipArithmetic>
|
||||
<UseMultipleDPTR>0</UseMultipleDPTR>
|
||||
<UseOnchipXram>0</UseOnchipXram>
|
||||
<HadIRAM>1</HadIRAM>
|
||||
<HadXRAM>1</HadXRAM>
|
||||
<HadIROM>1</HadIROM>
|
||||
<Moda2>0</Moda2>
|
||||
<Moddp2>0</Moddp2>
|
||||
<Modp2>1</Modp2>
|
||||
<Mod517dp>0</Mod517dp>
|
||||
<Mod517au>0</Mod517au>
|
||||
<Mode2>0</Mode2>
|
||||
<useCB>0</useCB>
|
||||
<useXB>0</useXB>
|
||||
<useL251>0</useL251>
|
||||
<useA251>0</useA251>
|
||||
<Mx51>0</Mx51>
|
||||
<ModC812>0</ModC812>
|
||||
<ModCont>0</ModCont>
|
||||
<Lp51>0</Lp51>
|
||||
<useXBS>0</useXBS>
|
||||
<ModDA>0</ModDA>
|
||||
<ModAB2>0</ModAB2>
|
||||
<Mx51P>0</Mx51P>
|
||||
<hadXRAM2>0</hadXRAM2>
|
||||
<uocXram2>0</uocXram2>
|
||||
<hadXRAM3>0</hadXRAM3>
|
||||
<ModC2>0</ModC2>
|
||||
<ModH2>0</ModH2>
|
||||
<Mdu_R515>0</Mdu_R515>
|
||||
<Mdu_F120>0</Mdu_F120>
|
||||
<Psoc>0</Psoc>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<hadIROM3>0</hadIROM3>
|
||||
<ModSmx2>0</ModSmx2>
|
||||
<cBanks>0</cBanks>
|
||||
<xBanks>0</xBanks>
|
||||
<OnChipMemories>
|
||||
<RCB>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0xffff</Size>
|
||||
</RCB>
|
||||
<RXB>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</RXB>
|
||||
<Ocm1>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm1>
|
||||
<Ocm2>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm2>
|
||||
<Ocm3>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm3>
|
||||
<Ocr1>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocr1>
|
||||
<Ocr2>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocr2>
|
||||
<Ocr3>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocr3>
|
||||
<IRO>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0xfff9</Size>
|
||||
</IRO>
|
||||
<IRA>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x100</Size>
|
||||
</IRA>
|
||||
<XRA>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x800</Size>
|
||||
</XRA>
|
||||
<XRA512>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</XRA512>
|
||||
<IROM512>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</IROM512>
|
||||
<XRA513>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</XRA513>
|
||||
<IROM513>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</IROM513>
|
||||
</OnChipMemories>
|
||||
</Target51Misc>
|
||||
<C51>
|
||||
<RegisterColoring>0</RegisterColoring>
|
||||
<VariablesInOrder>0</VariablesInOrder>
|
||||
<IntegerPromotion>1</IntegerPromotion>
|
||||
<uAregs>0</uAregs>
|
||||
<UseInterruptVector>1</UseInterruptVector>
|
||||
<Fuzzy>3</Fuzzy>
|
||||
<Optimize>8</Optimize>
|
||||
<WarningLevel>2</WarningLevel>
|
||||
<SizeSpeed>1</SizeSpeed>
|
||||
<ObjectExtend>1</ObjectExtend>
|
||||
<ACallAJmp>0</ACallAJmp>
|
||||
<InterruptVectorAddress>0</InterruptVectorAddress>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath></IncludePath>
|
||||
</VariousControls>
|
||||
</C51>
|
||||
<Ax51>
|
||||
<UseMpl>0</UseMpl>
|
||||
<UseStandard>1</UseStandard>
|
||||
<UseCase>0</UseCase>
|
||||
<UseMod51>0</UseMod51>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath></IncludePath>
|
||||
</VariousControls>
|
||||
</Ax51>
|
||||
<Lx51>
|
||||
<useFile>0</useFile>
|
||||
<linkonly>0</linkonly>
|
||||
<UseMemoryFromTarget>1</UseMemoryFromTarget>
|
||||
<CaseSensitiveSymbols>0</CaseSensitiveSymbols>
|
||||
<WarningLevel>2</WarningLevel>
|
||||
<DataOverlaying>1</DataOverlaying>
|
||||
<OverlayString></OverlayString>
|
||||
<MiscControls></MiscControls>
|
||||
<DisableWarningNumbers></DisableWarningNumbers>
|
||||
<LinkerCmdFile></LinkerCmdFile>
|
||||
<Assign></Assign>
|
||||
<ReserveString></ReserveString>
|
||||
<CClasses></CClasses>
|
||||
<UserClasses></UserClasses>
|
||||
<CSection></CSection>
|
||||
<UserSection></UserSection>
|
||||
<CodeBaseAddress></CodeBaseAddress>
|
||||
<XDataBaseAddress></XDataBaseAddress>
|
||||
<PDataBaseAddress></PDataBaseAddress>
|
||||
<BitBaseAddress></BitBaseAddress>
|
||||
<DataBaseAddress></DataBaseAddress>
|
||||
<IDataBaseAddress></IDataBaseAddress>
|
||||
<Precede></Precede>
|
||||
<Stack></Stack>
|
||||
<CodeSegmentName></CodeSegmentName>
|
||||
<XDataSegmentName></XDataSegmentName>
|
||||
<BitSegmentName></BitSegmentName>
|
||||
<DataSegmentName></DataSegmentName>
|
||||
<IDataSegmentName></IDataSegmentName>
|
||||
</Lx51>
|
||||
</Target51>
|
||||
</TargetOption>
|
||||
<Groups>
|
||||
<Group>
|
||||
<GroupName>Source Group 1</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>GPIO.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\GPIO.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>main.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\main.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>UART.C</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\UART.C</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>UART_Set.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\UART_Set.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>pwm_control.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\pwm_control.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Start_Init.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\Start_Init.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>PWM15bit.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\PWM15bit.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>timer.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>key.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\key.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>WDT.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\WDT.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
</Target>
|
||||
</Targets>
|
||||
|
||||
</Project>
|
||||
128
main.c
Normal file
128
main.c
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "config.h"
|
||||
#include "gpio.h"
|
||||
#include "UART.h"
|
||||
#include "string.h"
|
||||
#include "UART_Set.h"
|
||||
#include "pwm_control.h"
|
||||
#include "Start_Init.h"
|
||||
#include "key.h"
|
||||
#include "WDT.h"
|
||||
/************* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> **************
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD><EFBFBD><EFBFBD>STC8H8K64UΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>оƬ<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>STC8G<EFBFBD><EFBFBD>STC8Hϵ<EFBFBD><EFBFBD>оƬ<EFBFBD><EFBFBD>ͨ<EFBFBD>òο<EFBFBD>.
|
||||
|
||||
˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ˫<EFBFBD><EFBFBD><EFBFBD>жϷ<EFBFBD>ʽ<EFBFBD>շ<EFBFBD>ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
ͨ<EFBFBD><EFBFBD>PC<EFBFBD><EFBFBD>MCU<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, MCU<43>յ<EFBFBD><D5B5><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><DAB0>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ĭ<>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD>ʣ<EFBFBD>115200,N,8,1.
|
||||
|
||||
ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UART.h ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UART1~UART4 <20><><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬͨ<CDAC><CDA8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ͨ<EFBFBD>š<EFBFBD>
|
||||
|
||||
<EFBFBD>ö<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>1Tģʽ(<28><><EFBFBD>ǵͲ<C7B5><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>12T)<29><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƶ<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD><DFBE>ȡ<EFBFBD>
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ, ѡ<><D1A1>ʱ<EFBFBD><CAB1> 22.1184MHz (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"config.h"<22><><EFBFBD><EFBFBD>).
|
||||
|
||||
|
||||
/******************* IO<49><4F><EFBFBD>ú<EFBFBD><C3BA><EFBFBD> *******************/
|
||||
|
||||
|
||||
void GPIO1_config(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
|
||||
GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
GPIO_InitStructure.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
}
|
||||
|
||||
/*************** <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *****************/
|
||||
void UART1_config(void)
|
||||
{
|
||||
COMx_InitDefine COMx_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
|
||||
COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //ʹ<>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>, BRT_Timer1, BRT_Timer2 (ע<><D7A2>: <20><><EFBFBD><EFBFBD>2<EFBFBD>̶<EFBFBD>ʹ<EFBFBD><CAB9>BRT_Timer2)
|
||||
COMx_InitStructure.UART_BaudRate = 115200; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, һ<><D2BB> 110 ~ 115200
|
||||
COMx_InitStructure.UART_RxEnable = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
COMx_InitStructure.BaudRateDouble = DISABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD>ʼӱ<CABC>, ENABLE<4C><45>DISABLE
|
||||
COMx_InitStructure.UART_Interrupt = ENABLE; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>, ENABLE<4C><45>DISABLE
|
||||
COMx_InitStructure.UART_Priority = Priority_0; //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
COMx_InitStructure.UART_P_SW = UART1_SW_P30_P31; //<2F>л<EFBFBD><D0BB>˿<EFBFBD>, UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
|
||||
UART_Configuration(UART1, &COMx_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 UART1,UART2,UART3,UART4
|
||||
|
||||
//PrintString1("STC8H8K64U UART1 Test Programme!\r\n"); //UART1<54><31><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
}
|
||||
|
||||
/********************WDT INT<4E><54><EFBFBD><EFBFBD> ********************/
|
||||
void WDT_config(void)
|
||||
{
|
||||
WDT_InitTypeDef WDT_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
|
||||
WDT_InitStructure.WDT_Enable = ENABLE; //<2F>ж<EFBFBD>ʹ<EFBFBD><CAB9> ENABLE<4C><45>DISABLE
|
||||
WDT_InitStructure.WDT_IDLE_Mode = WDT_IDLE_STOP; //IDLEģʽ<C4A3>Ƿ<EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD> WDT_IDLE_STOP,WDT_IDLE_RUN
|
||||
WDT_InitStructure.WDT_PS = WDT_SCALE_32; //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>ʱ<EFBFBD><CAB1>ʱ<EFBFBD>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5> WDT_SCALE_2,WDT_SCALE_4,WDT_SCALE_8,WDT_SCALE_16,WDT_SCALE_32,WDT_SCALE_64,WDT_SCALE_128,WDT_SCALE_256
|
||||
WDT_Inilize(&WDT_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
}
|
||||
|
||||
u8 count_flag=0;
|
||||
void main(void)
|
||||
{
|
||||
GPIO_config();
|
||||
UART3_config();
|
||||
Start_Init();
|
||||
pwm_config();
|
||||
Timer2_Init_1ms();
|
||||
Key_Init();
|
||||
GPIO1_config();
|
||||
UART1_config();
|
||||
WDT_config(); //<2F><><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>629ms<6D><73>λ
|
||||
|
||||
PCON &= ~POF; //<2F><><EFBFBD><EFBFBD>LVD<56>жϱ<D0B6>־λ
|
||||
RSTCFG = 0x41; //LVD:2.4V<EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD>λ
|
||||
EA = 1;
|
||||
|
||||
if(debug)
|
||||
{
|
||||
PrintString1("MCU Start");
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
WDT_Clear(); //<2F>幷
|
||||
count_flag++;
|
||||
|
||||
//Ϊ<>˱<EFBFBD>֤ij<D6A4><C4B3>ѹ2.2V<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(count_flag==1)
|
||||
{
|
||||
P10=1;
|
||||
}
|
||||
if(count_flag==8)
|
||||
{
|
||||
P10=0;
|
||||
}
|
||||
if(count_flag==10)
|
||||
{
|
||||
count_flag=0;
|
||||
}
|
||||
|
||||
Usart_judge_Data();
|
||||
|
||||
Usart_Deal_Data();
|
||||
|
||||
deal_command1();
|
||||
|
||||
deal_command2();
|
||||
|
||||
// checkpwm();
|
||||
|
||||
show_light();
|
||||
|
||||
Usart_answer();
|
||||
|
||||
Key_ScanTask();
|
||||
|
||||
KEY_TEST();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
358
pwm_control.c
Normal file
358
pwm_control.c
Normal file
@@ -0,0 +1,358 @@
|
||||
#include "pwm_control.h"
|
||||
#include "GPIO.h"
|
||||
#include "STC8xxxx.h"
|
||||
#include "PWM15bit.h"
|
||||
#include "timer.h"
|
||||
#include "UART_Set.h"
|
||||
#include "string.h"
|
||||
S_PWM s_pwm;
|
||||
/*
|
||||
*1.<2E><><EFBFBD><EFBFBD>5.0/5.1<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||||
*2.<2E><>ʼ<EFBFBD><CABC>PWM<57><4D><EFBFBD><EFBFBD>
|
||||
*3.LED_DRV_12V_EN<45>õ<EFBFBD>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
/******************* IO<49><4F><EFBFBD>ú<EFBFBD><C3BA><EFBFBD> *******************/
|
||||
void GPIO_config(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure; //<2F>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>
|
||||
/***********************************1*******************************************/
|
||||
GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
GPIO_InitStructure.Mode = GPIO_PullUp; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
GPIO_Inilize(GPIO_P5,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
|
||||
/***********************************2*******************************************/
|
||||
GPIO_InitStructure.Pin = GPIO_Pin_All; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
GPIO_Inilize(GPIO_P0,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
|
||||
GPIO_InitStructure.Pin = GPIO_Pin_Left; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
GPIO_Inilize(GPIO_P2,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
|
||||
/***********************************3*******************************************/
|
||||
GPIO_InitStructure.Pin = GPIO_Pin_0; //ָ<><D6B8>Ҫ<EFBFBD><D2AA>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>IO, GPIO_Pin_0 ~ GPIO_Pin_7
|
||||
GPIO_InitStructure.Mode = GPIO_OUT_PP; //ָ<><D6B8>IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
|
||||
GPIO_Inilize(GPIO_P1,&GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>
|
||||
}
|
||||
|
||||
void pwm_config(void)
|
||||
{
|
||||
u8 i;
|
||||
PWM15_InitTypeDef PWM15_InitStructure;
|
||||
|
||||
PWM15_InitStructure.PWM_Enable = ENABLE; //PWMʹ<4D><CAB9>, ENABLE, DISABLE
|
||||
PWM15_InitStructure.PWM_Period = 0x04E2; //PWM<57><4D><EFBFBD><EFBFBD>, 1250,Ƶ<><C6B5>Ϊ16khz
|
||||
PWM15_InitStructure.PWM_Clock_Sel = PWMn_CLK_SYS; //ʱ<><CAB1>Դѡ<D4B4><D1A1>, PWMn_CLK_SYS, PWMn_CLK_TM2
|
||||
PWM15_InitStructure.PWM_Clock_PS = 0; //ϵͳʱ<CDB3>ӷ<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>(PS+1<><31>Ƶ), 0~15
|
||||
PWM15_InitStructure.PWM_Counter = ENABLE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, ENABLE, DISABLE
|
||||
|
||||
PWM15_Init(PWM0,&PWM15_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PWM0
|
||||
PWM15_Init(PWM2,&PWM15_InitStructure); //<2F><>ʼ<EFBFBD><CABC>PWM2
|
||||
|
||||
PWM15Duty(PWM00,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
PWM15Duty(PWM01,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
PWM15Duty(PWM02,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
PWM15Duty(PWM03,initial_Val); //PWM_ID, <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽλ<C6BD><CEBB>, <20><><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽλ<C6BD><CEBB>
|
||||
PWM15Duty(PWM04,initial_Val);
|
||||
PWM15Duty(PWM05,initial_Val);
|
||||
PWM15Duty(PWM06,initial_Val);
|
||||
PWM15Duty(PWM07,initial_Val);
|
||||
|
||||
PWM15Duty(PWM20,initial_Val);
|
||||
PWM15Duty(PWM21,initial_Val);
|
||||
PWM15Duty(PWM22,initial_Val);
|
||||
PWM15Duty(PWM23,initial_Val);
|
||||
|
||||
memset(&s_pwm,0,sizeof(s_pwm));
|
||||
for(i=0;i<12;i++)
|
||||
{
|
||||
s_pwm.currpwm[i]=initial_Val;
|
||||
}
|
||||
PWMChannelCtrl(PWM00,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM01,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM02,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM03,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM04,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM05,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM06,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM07,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
|
||||
PWMChannelCtrl(PWM20,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM21,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM22,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
PWMChannelCtrl(PWM23,ENABLE,1,DISABLE,DISABLE,DISABLE); //PWM_ID, <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>, <20><>ʼ<EFBFBD><CABC>ƽ, PWM<57>ж<EFBFBD>, <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>, <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
|
||||
}
|
||||
|
||||
|
||||
//10ms<6D><73><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
void deal_command1(void)
|
||||
{
|
||||
int i=0;
|
||||
static u32 systick_command1 = 0;
|
||||
|
||||
if (systick_1ms - systick_command1 >= 10)
|
||||
{
|
||||
systick_command1 = systick_1ms;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (s_recv.flag1[i])
|
||||
{
|
||||
if (s_pwm.wanttopwm[i] > s_pwm.currpwm[i])
|
||||
{
|
||||
//s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i];
|
||||
s_pwm.doublecurrpwm[i] += s_pwm.every_change_10ms[i];
|
||||
s_pwm.currpwm[i] = (u16)s_pwm.doublecurrpwm[i];
|
||||
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
|
||||
if ( s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4>ڵ<EFBFBD>ǰֵʱ
|
||||
if (s_pwm.wanttopwm[i] < s_pwm.currpwm[i])
|
||||
{
|
||||
//s_pwm.doublecurrpwm[i] = s_pwm.currpwm[i];
|
||||
s_pwm.doublecurrpwm[i] -= s_pwm.every_change_10ms[i];
|
||||
s_pwm.currpwm[i] = (u16)s_pwm.doublecurrpwm[i];
|
||||
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
|
||||
if (s_pwm.currpwm[i] < s_pwm.wanttopwm[i] + s_pwm.every_change_10ms[i])
|
||||
{
|
||||
s_pwm.currpwm[i] = 0;
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (s_pwm.wanttopwm[i] == s_pwm.currpwm[i])
|
||||
{
|
||||
s_pwm.currvalue[i] = s_recv.B_Ch[i];
|
||||
s_recv.flag1[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deal_command2(void)
|
||||
{
|
||||
int i=0;
|
||||
static u32 systick_command2 = 0;
|
||||
if (systick_1ms - systick_command2 >= 10)
|
||||
{
|
||||
systick_command2 = systick_1ms;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if (s_recv.flag2[i])
|
||||
{
|
||||
switch (s_recv.mode[i])
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>ֹͣģʽ
|
||||
case 0x00:
|
||||
//<2F><><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD>
|
||||
if (s_recv.forward[i] == 0x00)
|
||||
{
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_min * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
s_pwm.currpwm[i] += s_recv.pwm_step[i];
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
if (s_pwm.currpwm[i] >= s_pwm.wanttopwm[i])
|
||||
{
|
||||
s_recv.flag2[i] = 0;
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
s_pwm.currvalue[i] = s_recv.B_min; //<2F><><EFBFBD>ڻظ<DABB><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (s_recv.forward[i] == 0x01)
|
||||
{
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_max * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
if (s_pwm.currpwm[i] <= s_pwm.wanttopwm[i] + s_recv.pwm_step[i])
|
||||
{
|
||||
s_recv.flag2[i] = 0;
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
s_pwm.currvalue[i] = s_recv.B_max;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currpwm[i] -= s_recv.pwm_step[i];
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//˫<><CBAB>ѭ<EFBFBD><D1AD>ģʽ
|
||||
case 0x01:
|
||||
//<2F>ݼ<EFBFBD>
|
||||
if (s_recv.forward[i] == 0x00)
|
||||
{
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_min * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
s_pwm.currpwm[i] += s_recv.pwm_step[i];
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
if (s_pwm.currpwm[i] >= s_pwm.wanttopwm[i])
|
||||
{
|
||||
s_recv.forward[i] = 0x01;
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
s_pwm.currvalue[i] = s_recv.B_min; //<2F><><EFBFBD>ڻظ<DABB><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
if (s_recv.forward[i] == 0x01)
|
||||
{
|
||||
s_pwm.wanttopwm[i] = PWM_MAX_VALUE - s_recv.B_max * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100 * s_recv.key_status[i];
|
||||
if (s_pwm.currpwm[i] <= s_pwm.wanttopwm[i] + s_recv.pwm_step[i])
|
||||
{
|
||||
s_recv.forward[i] = 0x00;
|
||||
s_pwm.currpwm[i] = s_pwm.wanttopwm[i];
|
||||
s_pwm.currvalue[i] = s_recv.B_max;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currpwm[i] -= s_recv.pwm_step[i];
|
||||
if(s_recv.global_brightness==0)
|
||||
{
|
||||
s_pwm.currvalue[i]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_pwm.currvalue[i] = (PWM_MAX_VALUE - s_pwm.currpwm[i]) * 100 * 100 / PWM_MAX_VALUE / s_recv.global_brightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x02:
|
||||
//ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
s_recv.flag2[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ֱ<>ӹص<D3B9><D8B5><EFBFBD>,<2C><><EFBFBD><EFBFBD>¼״̬
|
||||
void Close_Light(u8 i)
|
||||
{
|
||||
s_pwm.currpwm[i]=20001ul; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>dz<EFBFBD><C7B3><EFBFBD><EFBFBD>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
//<2F><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void Open_Light(u8 pin)
|
||||
{
|
||||
s_pwm.currpwm[pin] = PWM_MAX_VALUE - s_pwm.currvalue[pin] * PWM_MAX_VALUE * s_recv.global_brightness / 100 / 100;
|
||||
}
|
||||
|
||||
void PWM_write(u8 i, u16 Val)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
PWM15Duty(PWM07,Val);
|
||||
break;
|
||||
case 1:
|
||||
PWM15Duty(PWM06,Val);
|
||||
break;
|
||||
case 2:
|
||||
PWM15Duty(PWM05,Val);
|
||||
break;
|
||||
case 3:
|
||||
PWM15Duty(PWM04,Val);
|
||||
break;
|
||||
case 4:
|
||||
PWM15Duty(PWM03,Val);
|
||||
break;
|
||||
case 5:
|
||||
PWM15Duty(PWM02,Val);
|
||||
break;
|
||||
case 6:
|
||||
PWM15Duty(PWM01,Val);
|
||||
break;
|
||||
case 7:
|
||||
PWM15Duty(PWM00,Val);
|
||||
break;
|
||||
case 8:
|
||||
PWM15Duty(PWM23,Val);
|
||||
break;
|
||||
case 9:
|
||||
PWM15Duty(PWM22,Val);
|
||||
break;
|
||||
case 10:
|
||||
PWM15Duty(PWM21,Val);
|
||||
break;
|
||||
case 11:
|
||||
PWM15Duty(PWM20,Val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void show_light(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 12; i++)
|
||||
{
|
||||
if(s_pwm.currpwm[i]==20000ul)
|
||||
{
|
||||
Close_Light(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
PWM_write(i, s_pwm.currpwm[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//void checkpwm(void)
|
||||
//{
|
||||
// int i;
|
||||
// for (i = 0; i < 12; i++)
|
||||
// {
|
||||
// if ((s_recv.flag1[i] == 0) && (s_recv.flag2[i] == 0) && (s_recv.changeflag == 1))
|
||||
// {
|
||||
// if (s_pwm.wanttopwmflash[i] != s_pwm.currpwm[i])
|
||||
// {
|
||||
// s_pwm.currpwm[i] = s_pwm.wanttopwmflash[i];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// s_recv.changeflag = 0;
|
||||
//}
|
||||
51
pwm_control.h
Normal file
51
pwm_control.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef PWM_CONTROL_H
|
||||
#define PWM_CONTROL_H
|
||||
|
||||
#include "STC8xxxx.h"
|
||||
|
||||
#define PWM_MAX_VALUE 1250ul
|
||||
#define initial_Val 1251ul
|
||||
/*
|
||||
#define LED_DRV_CH1 P07
|
||||
#define LED_DRV_CH2 P06
|
||||
#define LED_DRV_CH3 P05
|
||||
#define LED_DRV_CH4 P04
|
||||
#define LED_DRV_CH5 P03
|
||||
#define LED_DRV_CH6 P02
|
||||
#define LED_DRV_CH7 P01
|
||||
#define LED_DRV_CH8 P00
|
||||
#define LED_DRV_CH9 P23
|
||||
#define LED_DRV_CH10 P22
|
||||
#define LED_DRV_CH11 P21
|
||||
#define LED_DRV_CH12 P20
|
||||
*/
|
||||
#define LED_DRV_12V_EN P10
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16 currpwm[12];
|
||||
u16 thenvalue[12];
|
||||
float doublecurrpwm[12];
|
||||
u16 wanttopwm[12];
|
||||
u16 currvalue[12]; //<2F><>ǰ<EFBFBD>ٷֱ<D9B7>ֵ
|
||||
u16 changetime[12];
|
||||
u16 wanttovalue[12];
|
||||
float every_change_10ms[12];
|
||||
// u16 wanttopwmflash[12];
|
||||
u8 key_value;
|
||||
}xdata S_PWM;
|
||||
|
||||
extern S_PWM s_pwm;
|
||||
|
||||
void Close_Light(u8 pin);
|
||||
void Open_Light(u8 pin);
|
||||
void PWM_write(u8 i, u16 pwm);
|
||||
void deal_command1(void);
|
||||
void deal_command2(void);
|
||||
void show_light(void);
|
||||
void checkpwm(void);
|
||||
|
||||
void GPIO_config(void);
|
||||
void pwm_config(void);
|
||||
|
||||
#endif
|
||||
160
timer.c
Normal file
160
timer.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/************* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5> **************
|
||||
|
||||
<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ΪSTC8ϵ<EFBFBD>еĶ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϳ<EFBFBD><EFBFBD><EFBFBD>,<2C>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><DEB8>Լ<EFBFBD><D4BC><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>жϳ<D0B6><CFB3><EFBFBD>.
|
||||
|
||||
******************************************/
|
||||
|
||||
#include "timer.h"
|
||||
u32 systick_1ms=0;
|
||||
/********************* Timer0<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
void timer0_int (void) interrupt TIMER0_VECTOR
|
||||
{
|
||||
P67 = ~P67;
|
||||
}
|
||||
|
||||
/********************* Timer1<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
void timer1_int (void) interrupt TIMER1_VECTOR
|
||||
{
|
||||
P66 = ~P66;
|
||||
}
|
||||
|
||||
/********************* Timer2<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
void timer2_int (void) interrupt TIMER2_VECTOR
|
||||
{
|
||||
systick_1ms++;
|
||||
}
|
||||
|
||||
/********************* Timer3<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
void timer3_int (void) interrupt TIMER3_VECTOR
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/********************* Timer4<72>жϺ<D0B6><CFBA><EFBFBD>************************/
|
||||
void timer4_int (void) interrupt TIMER4_VECTOR
|
||||
{
|
||||
P63 = ~P63;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// <20><><EFBFBD><EFBFBD>: u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
|
||||
// <20><><EFBFBD><EFBFBD>: <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: TIMx: <20>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>,<2C><><EFBFBD>ο<EFBFBD>timer.h<><68><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>.
|
||||
// <20><><EFBFBD><EFBFBD>: <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0, <20>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1,<2C><><EFBFBD><EFBFBD>2.
|
||||
// <20>汾: V1.0, 2012-10-22
|
||||
//========================================================================
|
||||
u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx)
|
||||
{
|
||||
if(TIM > Timer4) return 1; //<2F>ղ<EFBFBD><D5B2><EFBFBD>
|
||||
|
||||
if(TIM == Timer0)
|
||||
{
|
||||
Timer0_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
if(TIMx->TIM_Interrupt == ENABLE) Timer0_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else Timer0_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(TIMx->TIM_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
Timer0_Priority(TIMx->TIM_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
|
||||
if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //<2F><><EFBFBD><EFBFBD>ģʽ,0: 16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, 1: 16λ<36><CEBB>ʱ/<2F><><EFBFBD><EFBFBD>, 2: 8λ<38>Զ<EFBFBD><D4B6><EFBFBD>װ
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer0_12T(); //12T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer0_1T(); //1T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer0_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
else Timer0_AsTimer(); //<2F><>ʱ
|
||||
if(TIMx->TIM_ClkOut == ENABLE) Timer0_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
else Timer0_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
T0_Load(TIMx->TIM_Value);
|
||||
if(TIMx->TIM_Run == ENABLE) Timer0_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
|
||||
if(TIM == Timer1)
|
||||
{
|
||||
Timer1_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
if(TIMx->TIM_Interrupt == ENABLE) Timer1_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else Timer1_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(TIMx->TIM_Priority > Priority_3) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
Timer1_Priority(TIMx->TIM_Priority); //ָ<><D6B8><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>(<28>͵<EFBFBD><CDB5><EFBFBD>) Priority_0,Priority_1,Priority_2,Priority_3
|
||||
if(TIMx->TIM_Mode >= TIM_16BitAutoReloadNoMask) return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
TMOD = (TMOD & ~0x30) | TIMx->TIM_Mode; //<2F><><EFBFBD><EFBFBD>ģʽ,0: 16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, 1: 16λ<36><CEBB>ʱ/<2F><><EFBFBD><EFBFBD>, 2: 8λ<38>Զ<EFBFBD><D4B6><EFBFBD>װ
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer1_12T(); //12T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer1_1T(); //1T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer1_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
else Timer1_AsTimer(); //<2F><>ʱ
|
||||
if(TIMx->TIM_ClkOut == ENABLE) Timer1_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
else Timer1_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
T1_Load(TIMx->TIM_Value);
|
||||
if(TIMx->TIM_Run == ENABLE) Timer1_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
|
||||
if(TIM == Timer2) //Timer2,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
{
|
||||
Timer2_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
if(TIMx->TIM_Interrupt == ENABLE) Timer2_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else Timer2_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer2_12T(); //12T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer2_1T(); //1T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer2_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
else Timer2_AsTimer(); //<2F><>ʱ
|
||||
if(TIMx->TIM_ClkOut == ENABLE) Timer2_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
else Timer2_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
T2_Load(TIMx->TIM_Value);
|
||||
if(TIMx->TIM_Run == ENABLE) Timer2_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
|
||||
if(TIM == Timer3) //Timer3,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
{
|
||||
Timer3_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
if(TIMx->TIM_Interrupt == ENABLE) Timer3_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else Timer3_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer3_12T(); //12T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer3_1T(); //1T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer3_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
else Timer3_AsTimer(); //<2F><>ʱ
|
||||
if(TIMx->TIM_ClkOut == ENABLE) Timer3_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
else Timer3_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
T3_Load(TIMx->TIM_Value);
|
||||
if(TIMx->TIM_Run == ENABLE) Timer3_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
|
||||
if(TIM == Timer4) //Timer3,<2C>̶<EFBFBD>Ϊ16λ<36>Զ<EFBFBD><D4B6><EFBFBD>װ, <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||||
{
|
||||
Timer4_Stop(); //ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||||
if(TIMx->TIM_Interrupt == ENABLE) Timer4_InterruptEnable(); //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
else Timer4_InterruptDisable(); //<2F><>ֹ<EFBFBD>ж<EFBFBD>
|
||||
if(TIMx->TIM_ClkSource > TIM_CLOCK_Ext) return 2;
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_12T) Timer4_12T(); //12T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_1T) Timer4_1T(); //1T
|
||||
if(TIMx->TIM_ClkSource == TIM_CLOCK_Ext) Timer4_AsCounter(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
|
||||
else Timer4_AsTimer(); //<2F><>ʱ
|
||||
if(TIMx->TIM_ClkOut == ENABLE) Timer4_CLKO_Enable(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
else Timer4_CLKO_Disable(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
T4_Load(TIMx->TIM_Value);
|
||||
if(TIMx->TIM_Run == ENABLE) Timer4_Run(); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||||
return 0; //<2F>ɹ<EFBFBD>
|
||||
}
|
||||
return 2; //<2F><><EFBFBD><EFBFBD>
|
||||
}
|
||||
47
timer.h
Normal file
47
timer.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* --- STC MCU Limited ------------------------------------------------*/
|
||||
/* --- STC 1T Series MCU Demo Programme -------------------------------*/
|
||||
/* --- Mobile: (86)13922805190 ----------------------------------------*/
|
||||
/* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
|
||||
/* --- Tel: 86-0513-55012928,55012929,55012966 ------------------------*/
|
||||
/* --- Web: www.STCMCU.com --------------------------------------------*/
|
||||
/* --- Web: www.STCMCUDATA.com ---------------------------------------*/
|
||||
/* --- QQ: 800003751 -------------------------------------------------*/
|
||||
/* <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ô˴<C3B4><CBB4><EFBFBD>,<2C><><EFBFBD>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>STC<54><43><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __TIMER_H
|
||||
#define __TIMER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define Timer0 0
|
||||
#define Timer1 1
|
||||
#define Timer2 2
|
||||
#define Timer3 3
|
||||
#define Timer4 4
|
||||
|
||||
#define TIM_16BitAutoReload 0
|
||||
#define TIM_16Bit 1
|
||||
#define TIM_8BitAutoReload 2
|
||||
#define TIM_16BitAutoReloadNoMask 3
|
||||
|
||||
#define TIM_CLOCK_1T 0
|
||||
#define TIM_CLOCK_12T 1
|
||||
#define TIM_CLOCK_Ext 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 TIM_Mode; //<2F><><EFBFBD><EFBFBD>ģʽ, TIM_16BitAutoReload,TIM_16Bit,TIM_8BitAutoReload,TIM_16BitAutoReloadNoMask
|
||||
u8 TIM_Priority; //<2F><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD> Priority_0,Priority_1,Priority_2,Priority_3
|
||||
u8 TIM_Interrupt; //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD> ENABLE,DISABLE
|
||||
u8 TIM_ClkSource; //ʱ<><CAB1>Դ TIM_CLOCK_1T,TIM_CLOCK_12T,TIM_CLOCK_Ext
|
||||
u8 TIM_ClkOut; //<2F>ɱ<EFBFBD><C9B1><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ENABLE,DISABLE
|
||||
u16 TIM_Value; //װ<>س<EFBFBD>ֵ
|
||||
u8 TIM_Run; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> ENABLE,DISABLE
|
||||
} TIM_InitTypeDef;
|
||||
|
||||
extern u32 systick_1ms;
|
||||
u8 Timer_Inilize(u8 TIM, TIM_InitTypeDef *TIMx);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user