ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
pca_pwm_10bit_2ch.c
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "fw_hal.h"
16
17__BIT dir = SET;
19
20void main(void)
21{
23 // UART1, baud 115200, baud source Timer1, 1T mode, no interrupt
25
26 // Set GPIO pin mode
28
29 // Stop PCA/PWM
31 // Stop counter in idle mode
33 // Use SYSCLK as clock source
35 // Turn off overflow interrupt
37
38 // Set PCA0 and PCA1 to PWM mode
41 // Set both to 8-bit PWM
44 // Set initial duty cycle
47 // Set output port for STC8G1K08A, PWM0:P32, PWM1:P33
49 // Start PWM
51
52 while(1)
53 {
56 UART1_TxHex(dc >> 8);
57 UART1_TxHex(dc & 0xFF);
58 if (dir)
59 {
60 dc++;
61 if (dc == 0x03FF) dir = !dir;
62 }
63 else
64 {
65 dc--;
66 if (dc == 0) dir = !dir;
67 }
68 UART1_TxString("\r\n");
69 SYS_Delay(10);
70 }
71}
#define GPIO_P3_SetMode(__PINS__, __MODE__)
Definition: fw_gpio.h:89
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ PCA_AlterPort_G1K08A_P55_P32_P33_P54
Definition: fw_pca.h:66
#define PCA_PCA0_ChangeCompareValue10bit(__VALUE__)
Definition: fw_pca.h:131
#define PCA_PCA0_SetWorkMode(__MODE__)
Definition: fw_pca.h:90
@ PCA_PWM_BitWidth_10
Definition: fw_pca.h:52
@ PCA_WorkMode_PWM_NonInterrupt
Definition: fw_pca.h:36
#define PCA_SetCounterState(__STATE__)
Definition: fw_pca.h:80
@ PCA_ClockSource_SysClkDiv12
Definition: fw_pca.h:23
#define PCA_SetPort(__ALTER_PORT__)
Definition: fw_pca.h:147
#define PCA_PCA1_SetCompareValue10bit(__VALUE__)
Definition: fw_pca.h:117
#define PCA_PWM1_SetBitWidth(__BIT_WIDTH__)
Definition: fw_pca.h:95
#define PCA_PWM0_SetBitWidth(__BIT_WIDTH__)
Definition: fw_pca.h:94
#define PCA_SetClockSource(__SOURCE___)
Definition: fw_pca.h:87
#define PCA_PCA1_ChangeCompareValue10bit(__VALUE__)
Definition: fw_pca.h:135
#define PCA_SetStopCounterInIdle(__STATE__)
Definition: fw_pca.h:86
#define PCA_PCA0_SetCompareValue10bit(__VALUE__)
Definition: fw_pca.h:113
#define PCA_PCA1_SetWorkMode(__MODE__)
Definition: fw_pca.h:91
#define PCA_EnableCounterOverflowInterrupt(__STATE__)
Definition: fw_pca.h:88
void SYS_SetClock(void)
Definition: fw_sys.c:40
void SYS_Delay(uint16_t t)
Definition: fw_sys.c:65
unsigned short uint16_t
Definition: fw_types.h:19
@ HAL_State_OFF
Definition: fw_types.h:70
@ HAL_State_ON
Definition: fw_types.h:71
@ SET
Definition: fw_types.h:85
void UART1_TxString(uint8_t *str)
Definition: fw_uart.c:85
@ UART1_BaudSource_Timer1
Definition: fw_uart.h:33
void UART1_TxHex(uint8_t hex)
Definition: fw_uart.c:79
void UART1_Config8bitUart(UART1_BaudSource_t baudSource, HAL_State_t _1TMode, uint32_t baudrate)
Definition: fw_uart.c:56
void main(void)
uint16_t dc
__BIT dir