您好,欢迎光临本网站![请登录][注册会员]  
文件名称: C8051F410定时器程序
  所属分类: C
  开发工具:
  文件大小: 7kb
  下载次数: 0
  上传时间: 2013-09-11
  提 供 者: sxx****
 详细说明: C8051F410定时器程序 //----------------------------------------------------------------------------- // F41x_Timer0_16bitTimer.c //----------------------------------------------------------------------------- // Copyright 2006 Silicon Laboratories, Inc. // http://www.silabs.com // // Program Description: // // This program presents an example of use of the Timer0 of the C8051F41x's in // 16-bit counter/timer mode. It uses the 'F410DK as HW platform. // In this example the LED is toggled at a rate defined by the // LED_TOGGLE_RATE cons tant.(in milliseconds) // // The timer is set with this values and counts until an overflow when it // generates an interrupt. This interrupt reloads the timer values and toggles // the LED. // // Pinout: // // P2.1 -> LED // // all other port pins unused // // How To Test: // // 1) Open the F41x_Timer0_16bitTimer.c file in the Silicon Labs IDE. // 2) If another rate is required change LED_TOGGLE_RATE (in msec) // 3) Compile the project and download to the device. // 4) Verify the LED pins of J5 are populated on the 'F41x TB. // 5) Run the code. // 6) Check that the LED is blinking at a constant rate . // // // FID: 41X000046 // Target: C8051F41x // Tool chain: KEIL C51 7.20 / KEIL EVAL C51 // Command Line: None // // Release 1.0 // -Initial Revision (CG) // -08 Mar 2006 // //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include // SFR declarations //----------------------------------------------------------------------------- // Global Constants //----------------------------------------------------------------------------- #define SYSCLK 24500000/8 // SYSCLK in Hz (24.5 MHz internal // oscillator / 8) // the internal oscillator has a // tolerance of +/- 2% #define TIMER_PRESCALER 48 // Based on Timer CKCON settings #define LED_TOGGLE_RATE 50 // LED toggle rate in milliseconds // if LED_TOGGLE_RATE = 1, the LED will // be on for 1 millisecond and off for // 1 millisecond // There are SYSCLK/TIMER_PRESCALER timer ticks per second, so // SYSCLK/TIMER_PRESCALER/1000 timer ticks per millisecond. #define TIMER_TICKS_PER_MS SYSCLK/TIMER_PRESCALER/1000 // Note: LED_TOGGLE_RATE*TIMER_TICKS_PER_MS should not exceed 65535 (0xFFFF) // for the 16-bit timer #define AUX1 TIMER_TICKS_PER_MS*LED_TOGGLE_RATE #define AUX2 -AUX1 #define AUX3 AUX2&0x00FF #define AUX4 ((AUX2&0xFF00)>>8) #define TIMER0_RELOAD_HIGH AUX4 // Reload value for Timer0 high byte #define TIMER0_RELOAD_LOW AUX3 // Reload value for Timer0 low byte sbit LED = P2^1; // LED='1' means ON //----------------------------------------------------------------------------- // Function Prototypes //----------------------------------------------------------------------------- void Port_Init (void); // Port initialization routine void Timer0_Init (void); // Timer0 initialization routine //----------------------------------------------------------------------------- // main() Routine //----------------------------------------------------------------------------- void main (void) { PCA0MD &= ~0x40; // Clear watchdog timer enable OSCICN |= 0x04; // Force Internal Osc. 1:8 prescaler while ((OSCICN & 0x40 ) == 0); // Wait until stable Timer0_Init (); // Initialize the Timer0 Port_Init (); // Init Ports EA = 1; // Enable global interrupts while (1); // Loop forever } //----------------------------------------------------------------------------- // Initialization Subroutines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Port_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function configures the crossbar and GPIO ports. // // Pinout: // // P2.1 -> LED // // all other port pins unused // //----------------------------------------------------------------------------- void Port_Init (void) { XBR1 = 0x40; // Enable crossbar P2MDOUT = 0x02; // Set LED to push-pull } //----------------------------------------------------------------------------- // Timer0_Init //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // This function configures the Timer0 as a 16-bit timer, interrupt enabled. // Using the internal osc. at 12MHz with a prescaler of 1:8 and reloading the // T0 registers with TIMER0_RELOAD_HIGH/LOW it will interrupt and then toggle // the LED aproximately one time every second. // // Note: The Timer0 uses a 1:48 prescaler. If this setting changes, the // TIMER_PRESCALER constant must also be changed. //----------------------------------------------------------------------------- void Timer0_Init(void) { TH0 = TIMER0_RELOAD_HIGH; // Init Timer0 High register TL0 = TIMER0_RELOAD_LOW ; // Init Timer0 Low register TMOD = 0x01; // Timer0 in 16-bit mode CKCON = 0x02; // Timer0 uses a 1:48 prescaler ET0 = 1; // Timer0 interrupt enabled TCON = 0x10; // Timer0 ON } //----------------------------------------------------------------------------- // Interrupt Service Routines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Timer0_ISR //----------------------------------------------------------------------------- // // Here we process the Timer0 interrupt and toggle the LED // //----------------------------------------------------------------------------- void Timer0_ISR (void) interrupt 1 { LED = ~LED; // Toggle the LED TH0 = TIMER0_RELOAD_HIGH; // Reinit Timer0 High register TL0 = TIMER0_RELOAD_LOW; // Reinit Timer0 Low register } //----------------------------------------------------------------------------- // End Of File //----------------------------------------------------------------------------- ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: C8051F410
 输入关键字,在本站1000多万海量源码库中尽情搜索: