mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add examples
This commit is contained in:
parent
265d41b6a3
commit
4128624f93
112 changed files with 158017 additions and 0 deletions
13
RTL00_SDKV35a/example_sources/pwm/readme.txt
Normal file
13
RTL00_SDKV35a/example_sources/pwm/readme.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
Example Description
|
||||
|
||||
This example describes how to use pwm
|
||||
|
||||
Requirement Components:
|
||||
1~4 LED
|
||||
|
||||
Connect LED to below PWM pins and ground, then the LED would gradually become brighter and then darker with different speed.
|
||||
- connect a LED to PC_0 and ground
|
||||
- connect a LED to PC_1 and ground
|
||||
- connect a LED to PC_2 and ground
|
||||
- connect a LED to PC_3 and ground
|
||||
|
94
RTL00_SDKV35a/example_sources/pwm/src/main.c
Normal file
94
RTL00_SDKV35a/example_sources/pwm/src/main.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2013 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
#include "pwmout_api.h" // mbed
|
||||
#include "main.h"
|
||||
|
||||
#define PWM_1 PC_0
|
||||
#define PWM_2 PC_1
|
||||
#define PWM_3 PC_2
|
||||
#define PWM_4 PC_3
|
||||
#define PWM_PERIOD 20000
|
||||
#define USE_FLOAT 0
|
||||
|
||||
#if USE_FLOAT
|
||||
#define PWM_STEP (1.0/20.0)
|
||||
float pwms[4]={0.0, 0.25, 0.5, 0.75};
|
||||
float steps[4]={PWM_STEP, PWM_STEP, PWM_STEP, PWM_STEP};
|
||||
#else
|
||||
#define PWM_STEP (PWM_PERIOD/20)
|
||||
int pwms[4]={0, PWM_PERIOD/4, PWM_PERIOD/2, PWM_PERIOD/4*3};
|
||||
int steps[4]={PWM_STEP,PWM_STEP,PWM_STEP,PWM_STEP};
|
||||
#endif
|
||||
|
||||
pwmout_t pwm_led[4];
|
||||
PinName pwm_led_pin[4] = {PWM_1, PWM_2, PWM_3, PWM_4};
|
||||
|
||||
extern void RtlMsleepOS(u32 ms);
|
||||
|
||||
void pwm_delay(void)
|
||||
{
|
||||
for(int i=0;i<1000000;i++)
|
||||
asm(" nop");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Main program.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
//int main_app(IN u16 argc, IN u8 *argv[])
|
||||
void main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
pwmout_init(&pwm_led[i], pwm_led_pin[i]);
|
||||
pwmout_period_us(&pwm_led[i], PWM_PERIOD);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
#if USE_FLOAT
|
||||
for (i=0; i<4; i++) {
|
||||
pwmout_write(&pwm_led[i], pwms[i]);
|
||||
|
||||
pwms[i] += steps[i];
|
||||
if (pwms[i] >= 1.0) {
|
||||
steps[i] = -PWM_STEP;
|
||||
pwms[i] = 1.0;
|
||||
}
|
||||
|
||||
if (pwms[i] <= 0.0) {
|
||||
steps[i] = PWM_STEP;
|
||||
pwms[i] = 0.0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (i=0; i<4; i++) {
|
||||
pwmout_pulsewidth_us(&pwm_led[i], pwms[i]);
|
||||
|
||||
pwms[i] += steps[i];
|
||||
if (pwms[i] >= PWM_PERIOD) {
|
||||
steps[i] = -PWM_STEP;
|
||||
pwms[i] = PWM_PERIOD;
|
||||
}
|
||||
|
||||
if (pwms[i] <= 0) {
|
||||
steps[i] = PWM_STEP;
|
||||
pwms[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// wait_ms(20);
|
||||
// RtlMsleepOS(25);
|
||||
pwm_delay();
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue