We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I launch the program "F12x_Timer2_16bitToggle.c" from the folder with examples of Silabs ( C:\Silabs\MCU\Examples\C8051F12x_13x\Timers, but does not work as described: No bits in port0 is not changed.
// Program Description: // This program presents an example of use of the Timer2 of the C8051F12x's in // 16-bit output toggle mode. // It uses the 'F120DK as HW platform. This example code counts in timer2 until // it overflows. At this moment the T2 output is toggled. // Pinout: // P0.0 -> T2 toggle output // How To Test: // // 1) Load the F12x_Timer2_16bitToggle.c // 2) To change the toggling rate modify TOGGLE_RATE value (0 to 255 -> msec) // 3) Compile and download the code // 4) Run // 5) Check the P0.0 pin (T2) // // FID: 12X000001 // Target: C8051F12x // Tool chain: KEIL C51 7.20 / KEIL EVAL C51 // Command Line: None // // Release 1.0 // -Initial Revision (CG) // -09 NOV 2005 //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include <c8051f120.h> // SFR declarations //----------------------------------------------------------------------------- // Global Constants //----------------------------------------------------------------------------- #define TOGGLE_RATE 1L // TOGGLE Rate of P0.0 in msec (255 max) // The timer is operating from a 24.5MHz (SYSCLK) with a prescaler of 1:12, // therefore the frequency is of 255KHz #define AUX0 - (TOGGLE_RATE)*256 #define AUX1 AUX0&0x00FF #define AUX2 ((AUX0&0xFF00)>>8) #define TIMER2_RELOAD_HIGH AUX2 // Reload value for timer2 high byte #define TIMER2_RELOAD_LOW AUX1 // Reload value for timer2 low byte //----------------------------------------------------------------------------- // Function Prototypes //----------------------------------------------------------------------------- void PORT_Init (void); // Port initialization routine void TIMER2_Init (void); // Timer0 initialization routine //----------------------------------------------------------------------------- // main() Routine //----------------------------------------------------------------------------- void main (void) { WDTCN = 0xde; // Disable watchdog timer WDTCN = 0xad; TIMER2_Init (); // Initialize the timer2 PORT_Init (); // Init Ports EA = 1; // Enable global interrupts while (1); // Loop } //----------------------------------------------------------------------------- // Initialization Subroutines //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // PORT_Init //----------------------------------------------------------------------------- // This function configures the crossbar and GPIO ports. //----------------------------------------------------------------------------- void PORT_Init (void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = CONFIG_PAGE; // set SFR page XBR1 = 0x20; // T2 available in the pins XBR2 = 0x40; // Enable crossbar P0MDOUT = 0x01; // Enable P0.0 as output SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // TIMER2_Init //----------------------------------------------------------------------------- // This function configures the timer2 as 16-bit auto-reload. // It Uses the internal osc. at 24.5MHz/8 with a 1:12 prescaler. // At each overflow the P0.0 is toggled. //----------------------------------------------------------------------------- void TIMER2_Init(void) { char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page SFRPAGE = TMR2_PAGE; // Set SFR page TMR2CF = 0x02; // output enabled, SYSCLK/12 RCAP2L = TIMER2_RELOAD_LOW; // Reload value to be used in Timer2 RCAP2H = TIMER2_RELOAD_HIGH; TMR2CN = 0x04; // Enable timer2 in reload mode SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //----------------------------------------------------------------------------- // End Of File //-----------------------------------------------------------------------------
This literal text of the example (from STLAB). I want to change the state of pins instead of using the CPU (without generating an interrupt, and that has made all peripherals via the crossbar) (such as on the AVR, STM). I like you too do not understand why ET2. I want to realize the toggle mode. From datasheet: "Timer 2 and 4 have the capability to toggle the state of their respective output port pins (T2 or T4) to produce a 50% duty cycle waveform output. The port pin state will change upon the overflow or underflow of the respective timer .
the datasheet: TMR2CF: Bit1: TnOE: Timer output enable bit. This bit enables the timer to output a 50% duty cycle output to the timer’s assigned external port pin. NOTE: A timer is configured for Square Wave Output as follows: CP/RLn= 0 C/Tn = 0 TnOE = 1 Load RCAPnH:RCAPnL (See “Square Wave Frequency (Timer 2 and Timer 4 Only)” on page 320.) Configure Port Pin to output squarewave (See Section “18. Port Input/Output” on page 235) 0: Output of toggle mode not available at Timers’s assigned port pin. 1: Output of toggle mode available at Timers’s assigned port pin.
and the code: TMR2CF = 0x02; // output enabled, SYSCLK/12
as said before, probably one of the many I/O things the simulator will not do
do not understand why ET2. I want to realize the toggle mode. did you not read my reply? THERE IS NO ET2
Erik