亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? f500_pca0_16bit_pwm_output.c

?? C8051F500開發編程:MCU全部資源應用實例
?? C
字號:
//-----------------------------------------------------------------------------
// F500_PCA0_16Bit_PWM_Output.c
//-----------------------------------------------------------------------------
// Copyright 2008 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program sends a PWM waveform out of an I/O pin, using the PCA's
// 16-bit PWM Output Mode.  The duty cycle of the waveform is modified
// periodically within the main loop.
//
// In this example, PCA Module 0 is used to generate the waveform, and the
// crossbar is configured to send the CEX0 pin out on P0.0.
//
// How To Test:
//
// 1) Download code to a 'F500 device which has an oscilloscope monitoring P0.0
// 2) Run the program - the waveform should be visible on the oscilloscope.
// 3) Verify that the duty cycle of the waveform varies smoothly between
//    minimum and maximum values.
//
//
// Target:         C8051F500 (Side A of a C8051F500-TB)
// Tool chain:     Keil C51 8.0 / Keil EVAL C51
// Command Line:   None
//
// Release 1.1 / 10 JUN 2008 (ADT)
//    -Edited formatting
//
// Release 1.0 / 03 MAR 2008 (GP)
//    -Initial Revision
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <compiler_defs.h>
#include <C8051F500_defs.h>            // SFR declarations

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define SYSCLK       24000000          // Internal oscillator frequency in Hz

//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void);
void PORT_Init (void);
void PCA0_Init (void);

INTERRUPT_PROTO (PCA0_ISR, INTERRUPT_PCA0);

//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------

U16 CEX0_Compare_Value;                // Holds current PCA compare value

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

void main (void)
{
   U8 delay_count;                     // Used to implement a delay
   bit duty_direction = 0;             // 0 = Decrease; 1 = Increase

   SFRPAGE = ACTIVE_PAGE;              // Set SFR Page for PCA0 registers

   PCA0MD = 0x00;                      // Disable watchdog timer

   PORT_Init ();                       // Initialize crossbar and GPIO
   OSCILLATOR_Init ();                 // Initialize oscillator
   PCA0_Init ();                       // Initialize PCA0

   EA = 1;                             // Globally enable interrupts

   while (1)
   {
      // Wait a little while
      for (delay_count = 120; delay_count > 0; delay_count--);

      if (duty_direction == 1)         // Direction = Increase
      {
         // First, check the ECOM0 bit
         if ((PCA0CPM0 & 0x40) == 0x00)
         {
            PCA0CPM0 |= 0x40;          // Set ECOM0 if it is '0'
         }
         else                          // Increase duty cycle otherwise
         {
            CEX0_Compare_Value--;      // Increase duty cycle

            if (CEX0_Compare_Value == 0x0000)
            {
               duty_direction = 0;     // Change direction for next time
            }
         }
      }
      else                             // Direction = Decrease
      {
         if (CEX0_Compare_Value == 0xFFFF)
         {
            PCA0CPM0 &= ~0x40;         // Clear ECOM0
            duty_direction = 1;        // Change direction for next time
         }
         else
         {
            CEX0_Compare_Value++;      // Decrease duty cycle
         }
      }
   }
}


//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function initializes the system clock to use the internal oscillator
// at 24 MHz.
//
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   OSCICN = 0x87;                      // Set internal oscillator to run
                                       // at its maximum frequency

   CLKSEL = 0x00;                      // Select the internal osc. as
                                       // the SYSCLK source

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the crossbar and GPIO ports.
//
// P0.0   digital   push-pull     PCA0 CEX0
//
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   P0MDOUT |= 0x01;                    // Set CEX0 (P0.0) to push-pull

   XBR1    = 0x04;                     // Enable CEX0 on crossbar
   XBR2    = 0x40;                     // Enable crossbar and weak pull-ups

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// PCA0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This function configures the PCA time base, and sets up 16-bit PWM output
// mode for Module 0 (CEX0 pin).
//
// The frequency of the PWM signal generated at the CEX0 pin is equal to the
// PCA main timebase frequency divided by 65536.
//
// The PCA time base in this example is configured to use SYSCLK, and SYSCLK
// is set up to use the internal oscillator running at 24 MHz.  Therefore,
// the frequency of the PWM signal will be 24 MHz / 65536 = 366.2 Hz.
// Using different PCA clock sources or a different processor clock will
// result in a different frequency for the PWM signal.
//
//    -------------------------------------------------------------------------
//    How "16-Bit PWM Mode" Works:
//
//       The PCA's 16-bit PWM Mode works by setting an output pin low every
//    time the main 16-bit PCA counter (PCA0H) overflows, and then setting
//    the pin high whenever a specific match condition is met.
//
//    Upon a PCA0 overflow (PCA0 incrementing from 0xFFFF to 0x0000), the
//    CEXn pin will be set low.
//
//    When the PCA0 register increments and matches the PCA0CPn register for
//    the selected module, the CEXn pin will be set high, except when the
//    ECOMn bit in PCA0CPMn is cleared to '0'.  By varying the value of the
//    PCA0CPn register, the duty cycle of the waveform can also be varied.
//
//    When ECOMn = '1', the duty cycle of the PWM waveform is:
//
//       16-bit PWM Duty Cycle = (65536 - PCA0CPn) / 65536
//
//    To set the duty cycle to 100%, a value of 0x0000 should be loaded into
//    the PCA0CPn register for the module being used (with ECOMn set to '1').
//    When the value of PCA0CPn is equal to 0x0000, the pin will never be
//    set low.
//
//    To set the duty cycle to 0%, the ECOMn bit in the PCA0CPMn register
//    should be cleared to 0.  This prevents the PCA0CPn match from occuring,
//    which results in the pin never being set high.
//
// When adjusting the PWM duty cycle, the low byte of the PCA0CPn register
// (PCA0CPLn) should be written first, followed by the high byte (PCA0CPHn).
// Writing the low byte clears the ECOMn bit, and writing the high byte will
// restore it.  This ensures that a match does not occur until the full
// 16-bit value has been written to the compare register.  Writing the high
// byte first will result in the ECOMn bit being set to '0' after the 16-bit
// write, and the duty cycle will also go to 0%.
//
// It is also advisable to wait until just after a match occurs before
// updating the PWM duty cycle.  This will help ensure that the ECOMn
// bit is not cleared (by writing PCA0CPLn) at the time when a match was
// supposed to happen.  This code implements the compare register update in
// the PCA ISR upon a match interrupt.
//    -------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void PCA0_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = ACTIVE_PAGE;

   // Configure PCA time base; overflow interrupt disabled
   PCA0CN = 0x00;                      // Stop counter; clear all flags
   PCA0MD = 0x08;                      // Use SYSCLK as time base

   PCA0CPM0 = 0xCB;                    // Module 0 = 16-bit PWM mode and
                                       // enable Module 0 Match and Interrupt
                                       // Flags

   // Configure initial PWM duty cycle = 50%
   CEX0_Compare_Value = 65536 - (65536 * 0.5);

   PCA0CPL0 = (CEX0_Compare_Value & 0x00FF);
   PCA0CPH0 = (CEX0_Compare_Value & 0xFF00) >> 8;

   EIE1 |= 0x08;                       // Enable PCA interrupts

   // Start PCA counter
   CR = 1;

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// PCA0_ISR
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This is the ISR for the PCA.  It handles the case when a match occurs on
// channel 0, and updates the PCA0CPn compare register with the value held in
// the global variable "CEX0_Compare_Value".
//
//-----------------------------------------------------------------------------
INTERRUPT(PCA0_ISR, INTERRUPT_PCA0)
{
   CCF0 = 0;                           // Clear module 0 interrupt flag.

   PCA0CPL0 = (CEX0_Compare_Value & 0x00FF);
   PCA0CPH0 = (CEX0_Compare_Value & 0xFF00) >> 8;
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品成人在线观看| 精品国产麻豆免费人成网站| 国产精品18久久久久久久久| 日本午夜一本久久久综合| 一区二区在线观看视频在线观看| 欧美经典三级视频一区二区三区| 国产亚洲午夜高清国产拍精品 | 国产高清成人在线| 麻豆高清免费国产一区| 激情久久五月天| 国产高清不卡二三区| 国产成人亚洲精品狼色在线| 国产成人啪免费观看软件| 成人午夜视频在线| 91小视频免费观看| 日本道在线观看一区二区| 欧美日韩国产天堂| 欧美一区二区播放| 久久精品在这里| 国产精品色噜噜| 亚洲亚洲精品在线观看| 日韩中文字幕1| 国产麻豆午夜三级精品| 不卡av电影在线播放| 欧美写真视频网站| 日韩一区二区精品葵司在线| 日本一区二区三级电影在线观看| 国产精品电影院| 天堂成人国产精品一区| 国产精品一区二区在线播放| 99精品国产热久久91蜜凸| 欧美伊人精品成人久久综合97| 5566中文字幕一区二区电影| 久久久久综合网| 一区二区欧美精品| 国内精品免费**视频| 99视频热这里只有精品免费| 9191国产精品| 中文字幕亚洲不卡| 国产美女精品在线| 97久久超碰国产精品| 8x8x8国产精品| 成人免费在线视频| 蜜桃精品视频在线观看| 99久久精品国产精品久久| 日韩一区二区视频| 一区二区三区免费看视频| 激情综合色播五月| 色婷婷综合久色| 国产午夜一区二区三区| 午夜av区久久| 色999日韩国产欧美一区二区| www激情久久| 日韩电影在线一区| 色老汉av一区二区三区| 国产精品少妇自拍| 狠狠色综合色综合网络| 欧美日韩一区三区| 亚洲视频中文字幕| 国产成人综合视频| 日韩精品在线网站| 亚洲午夜视频在线| 91视视频在线直接观看在线看网页在线看 | 欧美综合欧美视频| 国产精品高潮呻吟| 国产一区二区0| 精品国产三级电影在线观看| 亚洲h在线观看| 在线观看免费一区| 亚洲色图视频网| 99久久精品国产一区| 中文字幕的久久| 国产1区2区3区精品美女| 精品电影一区二区| 国精品**一区二区三区在线蜜桃| 91精品国产91综合久久蜜臀| 午夜一区二区三区视频| 欧美三区在线观看| 亚洲v中文字幕| 欧美精品在线一区二区| 丝袜a∨在线一区二区三区不卡| 欧美视频在线观看一区二区| 一区二区成人在线| 欧美日韩国产区一| 日韩高清电影一区| 日韩欧美综合在线| 久久电影国产免费久久电影| 精品国产污网站| 精品一二三四在线| 国产欧美日韩在线看| 国产91精品在线观看| 成人免费在线播放视频| 在线视频国内一区二区| 亚洲成人av电影| 日韩美女主播在线视频一区二区三区| 蜜桃av一区二区| 国产日韩欧美精品综合| www.日韩精品| 日韩在线a电影| 久久久91精品国产一区二区精品| 成人av在线资源| 亚洲第一精品在线| 精品国精品国产| 99re在线精品| 毛片基地黄久久久久久天堂| 欧美国产一区在线| 欧美午夜视频网站| 免费观看成人av| 一色屋精品亚洲香蕉网站| 在线国产亚洲欧美| 国内精品在线播放| 亚洲欧美日韩电影| 精品少妇一区二区三区在线视频| 成人动漫视频在线| 性感美女极品91精品| 久久久不卡网国产精品一区| 91久久精品一区二区三区| 久久99久久99| 一区二区三区av电影| 精品国产sm最大网站| 91精品福利在线| 国产精品99久久久久久久vr| 一区二区三区**美女毛片| 久久久亚洲国产美女国产盗摄 | 国产精品白丝jk白祙喷水网站| 国内精品国产成人国产三级粉色| 亚洲视频网在线直播| 欧美一区二区三区人| 91色婷婷久久久久合中文| 激情六月婷婷久久| 日韩中文字幕区一区有砖一区| 自拍偷拍欧美精品| 精品久久久久久最新网址| 91久久精品一区二区| 国产精品1区2区| 久久99精品国产麻豆婷婷洗澡| 亚洲另类中文字| 国产精品美女久久久久av爽李琼| 精品乱人伦一区二区三区| 欧美在线|欧美| www.欧美亚洲| 成人免费高清在线| 国精产品一区一区三区mba视频 | 精品免费一区二区三区| 欧美性一区二区| 在线观看国产一区二区| 色综合天天综合网天天看片| 国产成人精品午夜视频免费| 精品中文av资源站在线观看| 蜜臀久久99精品久久久久宅男| 亚洲电影在线播放| 亚洲国产另类av| 亚洲图片欧美综合| 一区二区三区欧美| 一区二区三区国产精品| 亚洲欧美日韩国产手机在线| 亚洲精品视频免费看| 亚洲视频免费在线观看| 亚洲免费观看在线视频| 亚洲女厕所小便bbb| 亚洲精品免费视频| 一区2区3区在线看| 亚洲成人动漫精品| 日韩激情一二三区| 奇米影视一区二区三区小说| 成人国产精品视频| 福利电影一区二区三区| av资源站一区| 日本福利一区二区| 777a∨成人精品桃花网| 欧美一二三四在线| 国产日韩欧美亚洲| 亚洲丝袜自拍清纯另类| 尤物av一区二区| 日韩中文字幕一区二区三区| 国产精品亚洲一区二区三区妖精| 成人网在线播放| 91色乱码一区二区三区| 欧美在线观看一区| 日韩欧美在线观看一区二区三区| 国产日韩欧美高清在线| 亚洲欧美日韩在线播放| 日韩av一区二区三区| 国产精品综合一区二区| av一区二区久久| 在线不卡a资源高清| 久久一留热品黄| 亚洲精品高清在线观看| 偷窥少妇高潮呻吟av久久免费| 国产毛片精品视频| 色综合婷婷久久| 精品国产青草久久久久福利| 1000精品久久久久久久久| 日韩av中文在线观看| 成人高清免费观看| 51午夜精品国产| 亚洲欧美一区二区三区久本道91 | 久久精品亚洲精品国产欧美kt∨| 亚洲另类色综合网站| 国产老肥熟一区二区三区|