, ! .


»  » STM32 & STM8 »  1


1

1 30 43

1

stm8s. . .
3. . 4 .
:

:
#include "iostm8s103f3.h"
/*..............................................................................*/
/*.......................  ...................................*/
/*..............................................................................*/
#define led_blue PC_ODR_bit.ODR5
#define led_green PC_ODR_bit.ODR6 
#define led_red PC_ODR_bit.ODR7 
#define button1_in PB_IDR_bit.IDR4
#define button2_in PB_IDR_bit.IDR5
/*..............................................................................*/
/*................... : 0 - ; 1 - ............................*/
/*..............................................................................*/
 struct
 {
   volatile unsigned char button1 :  1;
   volatile unsigned char button2 :  1; 
 } flag;
/*..............................................................................*/
/*...................  2.....................................*/
/*..............................................................................*/
union type_timer2_arr
{
  volatile unsigned int arr;  
  struct
  {
    volatile unsigned int l_arr : 8;
    volatile unsigned int h_arr : 8;
  };
} timer2_arr;
union type_timer2_pscr
{
  volatile unsigned int pscr;  
  struct
  {
    volatile unsigned int l_pscr : 8;
    volatile unsigned int h_pscr : 8;
  };
} timer2_pscr;
union type_timer1_ccr3
{
  volatile unsigned int ccr3;  
  struct
  {
    volatile unsigned int l_ccr3 : 8;
    volatile unsigned int h_ccr3 : 8;
  };
} timer1_ccr3;
union type_timer1_ccr4
{
  volatile unsigned int ccr4;  
  struct
  {
    volatile unsigned int l_ccr4 : 8;
    volatile unsigned int h_ccr4 : 8;
  };
} timer1_ccr4;
unsigned int zoom = 0;
unsigned int sum_tick = 0;
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC4IF_handler(void);
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
unsigned int pad_chg_time( unsigned char number )
{
  unsigned int tick = 0;
  if( number == 1 )
  {
    PB_ODR_bit.ODR4 = 1; //     +
    PB_DDR_bit.DDR4 = 1; //  
    PB_ODR_bit.ODR4 = 0; //     
    PB_DDR_bit.DDR4 = 0; //   
    while( button1_in == 0 ){tick++;}//   
  }
  if( number == 2 )
  {
    PB_ODR_bit.ODR5 = 1; //     +
    PB_DDR_bit.DDR5 = 1; //  
    PB_ODR_bit.ODR5 = 0; //     
    PB_DDR_bit.DDR5 = 0; //   
    while( button2_in == 0 ){tick++;}//   
  }    
  return tick;
}
unsigned char button_time( unsigned char number )
{
  unsigned int zero;
  if( number == 1 )
  {
    zero = pad_chg_time( number );
    while( pad_chg_time( number ) > 19 ){};
    if( zero > 19 )
      return 1;
    else
      return 0;
  }
  if( number == 2 )
  {
    zero = pad_chg_time( number );
    while( pad_chg_time( number ) > 9 ){};
    if( zero > 9 )
      return 1;
    else
      return 0;
  }
}
int main( void )
{
  CLK_SWCR_bit.SWEN = 0;//              
  CLK_CKDIVR_HSIDIV = 0;//     = 1.
  CLK_CKDIVR_CPUDIV = 0;//    = 1.
/*  .3   */ 
  PC_DDR_bit.DDR5 = 1; //  
  PC_CR1_bit.C15 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C25 = 1; // 10
/*  .4   */ 
  PC_DDR_bit.DDR6 = 1; //  
  PC_CR1_bit.C16 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C26 = 1; // 10
/*  .5   */ 
  PC_DDR_bit.DDR7 = 1; //  
  PC_CR1_bit.C17 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C27 = 1; // 10
/*  B.4  1 */
  PB_CR1_bit.C14 = 0; // 
  PB_CR2_bit.C24 = 0; // 
  PB_DDR_bit.DDR4 = 0; //  
  PB_ODR_bit.ODR4 = 0; // 
/*  B.5  2 */
  PB_CR1_bit.C15 = 0; // 
  PB_CR2_bit.C25 = 0; // 
  PB_DDR_bit.DDR5 = 0; //  
  PB_ODR_bit.ODR5 = 0; // 
/*   4    */
  TIM4_PSCR = 1;
  TIM4_CR1_bit.URS = 1; //    
  TIM4_EGR_bit.UG = 1;  // Update Event
  TIM4_IER_bit.UIE = 0; // 
  TIM4_CR1_bit.CEN = 0; // !!!!!!!!!!!!!!!!!!!!!!!!!
/*   2.  .  3.   10 */   
  PA_DDR_bit.DDR3 = 1; //  
  PA_CR1_bit.C13 = 1; //     +  - (PUSHPULL)
  PA_CR2_bit.C23 = 1; // 10
  TIM2_CR1 = 0;
  TIM2_PSCR = 4;
  timer2_arr.arr   = 10000;
  TIM2_ARRH = timer2_arr.h_arr;
  TIM2_ARRL = timer2_arr.l_arr;
  TIM2_CCMR3_OC3M = 6;
  TIM2_CCR3H = 0;
  TIM2_CCR3L = 10;
  TIM2_CCER2_CC3E = 1;
  TIM2_CR1_bit.CEN = 1;
/*   1.  . */ 
  TIM1_PSCRH = 0;
  TIM1_PSCRL = 0;
// 4  
  PC_CR1_bit.C14 = 0; // 
  PC_CR2_bit.C24 = 0; // 
  PC_DDR_bit.DDR4 = 0; //  
  PC_CR1_bit.C13 = 0; // 
  PC_CR2_bit.C23 = 0; // 
  PC_DDR_bit.DDR3 = 0; //  
  
  TIM1_CCMR4_CC4S = 1; //    ,    TI4
  TIM1_CCER2_CC4P = 1;//    
  TIM1_EGR_CC4G = 1;
// 3  
  TIM1_CCMR3_CC3S = 1;//     ,    TI3
  TIM1_CCER2_CC3P = 0;//   
  TIM1_EGR_CC3G = 1;
  TIM1_CCER2_CC4E = 1;
  TIM1_CCER2_CC3E = 1;
  TIM1_IER_CC3IE = 1;
  TIM1_CR1_bit.CEN = 1;
  
  asm("RIM"); // 
  for(;;)
  {
    if( button_time( 1 ) == 1 )led_red = ~led_red;
    if( button_time( 2 ) == 1 )led_green = ~led_green;
  }
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_CAPCOM_CC3IF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC3IF_handler(void)
{ 
  zoom = TIM1_CCR3H;
  zoom = TIM1_CCR3L;
  zoom = TIM1_CCR4H;
  zoom = TIM1_CCR4L;
 // TIM1_SR1_CC3IF = 0;
}


,

:
if( TIM1_SR1_CC3IF == 1 )

:
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_CAPCOM_CC3IF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC3IF_handler(void)
{
  if( TIM1_SR1_CC3IF == 1 )
  {
    zoom = TIM1_CCR3H;
    zoom = TIM1_CCR3L;
    zoom = TIM1_CCR4H;
    zoom = TIM1_CCR4L;
  }
   TIM1_SR1_CC3IF = 0; 
}

,

CC3IF

. . ? ?
CCR3-CCR4.

2

. , .

:
#define TIM1_CAPCOM_BIF_vector               13 /* IRQ No. in STM8 manual: 11 */
#define TIM1_CAPCOM_TIF_vector               13 /* IRQ No. in STM8 manual: 11 */
#define TIM1_OVR_UIF_vector                  13 /* IRQ No. in STM8 manual: 11 */
#define TIM1_CAPCOM_CC1IF_vector             14 /* IRQ No. in STM8 manual: 12 */
#define TIM1_CAPCOM_CC2IF_vector             14 /* IRQ No. in STM8 manual: 12 */
#define TIM1_CAPCOM_CC3IF_vector             14 /* IRQ No. in STM8 manual: 12 */
#define TIM1_CAPCOM_CC4IF_vector             14 /* IRQ No. in STM8 manual: 12 */
#define TIM1_CAPCOM_COMIF_vector             14 /* IRQ No. in STM8 manual: 12 */

SR1. . - if( TIM1_SR1_CC3IF == 1 ), , .???? ?
.

:
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_OVR_UIF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_OVR_UIF_handler(void)
{
  if( ( TIM1_SR1_bit.CC3IF == 1 ) && ( TIM1_SR1_bit.CC4IF == 1 ) && ( TIM1_SR1_UIF == 1 ) )
  {
    time = ( TIM1_CCR3H - TIM1_CCR4H ) << 8;
    time = time + ( TIM1_CCR3L - TIM1_CCR4L );
    TIM1_SR1_bit.UIF = 0;
  } 
}


:
/*   1.  . */ 
  TIM1_PSCRH = 0;
  TIM1_PSCRL = 32;
// 4  
  PC_CR1_bit.C14 = 0; // 
  PC_CR2_bit.C24 = 0; // 
  PC_DDR_bit.DDR4 = 0; //  
  TIM1_CCMR4_CC4S = 1; //    ,    TI4
  TIM1_CCER2_CC4P = 0;//    
//  TIM1_EGR_CC4G = 1;
  TIM1_CCER2_CC4E = 1;
// 3  
  PC_CR1_bit.C13 = 0; // 
  PC_CR2_bit.C23 = 0; // 
  PC_DDR_bit.DDR3 = 0; //  
  TIM1_CCMR3_CC3S = 1;//     ,    TI3
  TIM1_CCER2_CC3P = 1;//   
  TIM1_EGR_CC3G = 1;
  TIM1_CCER2_CC3E = 1;
  
  TIM1_CR1_bit.URS = 1; //    
  TIM1_EGR_bit.UG = 1;  // Update Event
  TIM1_IER_bit.UIE = 1; // 

. . - ( ), - ( , ).

RA (2018-01-26 12:40:34)

3

SR1. . - if( TIM1_SR1_CC3IF == 1 ), ,


- ... ...

read/clear (rc_w0)  Software can read and clear this bit by writing 0. Writing 1 has no effect on the bit value.

HHIMERA (2018-01-28 11:21:30)

4

RA IAR )), ? . , , stm8 .

MasterElectric (2018-01-29 16:36:12)

5

RA ? .

6

RA , . , , , , . 4 , .. .

MasterElectric (2018-01-29 16:55:57)

7

RA :

:
if (( TIM1_SR1_bit.CC4IF == 1 ) && (TIM1_IER_bit.CC4IE == 1))
{

}

MasterElectric (2018-01-29 17:02:40)

8

... ...
""... ...
... ... ... ...
... ... ... ...

9

HHIMERA ():

... ...
""... ...
... ... ... ...
... ... ... ...

!!! ? . . .

:
#include "iostm8s103f3.h"
volatile unsigned int time = 0;
/*..............................................................................*/
int main( void )
{
  CLK_SWCR_bit.SWEN = 0;//              
  CLK_CKDIVR_HSIDIV = 0;//     = 1.
  CLK_CKDIVR_CPUDIV = 0;//    = 1.
/*   2.  .  3.   10 */ 
  PA_ODR_bit.ODR3 = 0;  
  PA_DDR_bit.DDR3 = 1; //  
  PA_CR1_bit.C13 = 1; //     +  - (PUSHPULL)
  PA_CR2_bit.C23 = 1; // 10
  TIM2_PSCR = 4;
  TIM2_CCMR3_OC3M = 6;
  TIM2_CCR3H = 0;
  TIM2_CCR3L = 10;
  TIM2_CCER2_CC3E = 1;
  TIM2_CR1_bit.CEN = 1;
/*   1.  . */ 
  TIM1_PSCRH = 0;
  TIM1_PSCRL = 32;
// 3  
  TIM1_CCMR3_CC3S = 1;//     ,    TI3
  TIM1_CCER2_CC3P = 0;// 0 to 1
  TIM1_CCER2_CC3E = 1;
// 4  
  TIM1_CCMR4_CC4S = 1;//     ,    TI4
  TIM1_CCER2_CC4P = 1;// 1 to 0
  TIM1_CCER2_CC4E = 1;
  TIM1_IER_CC4IE = 1;
   
  TIM1_CR1_bit.CEN = 1; 
  asm("RIM"); // 
  for(;;)
  {
  }
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_CAPCOM_CC3IF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC3IF_handler(void)
{
  if (( TIM1_SR1_bit.CC4IF == 1 ) && (TIM1_IER_bit.CC4IE == 1))
  {
    time = ( TIM1_CCR4H - TIM1_CCR3H ) << 8;
    time = time + ( TIM1_CCR4L - TIM1_CCR3L );
  }
}

. .
1. Select the active input: For example, to link the TIM1_CCR1 register to the TI1 input,
write the CC1S bits to 01 in the TIM1_CCMR1 register. This configures the channel in
input mode and the TIM1_CCR1 register becomes read-only.
2. Program the required input filter duration for the signal to be connected to the timer.
This is done for each TIi input using the ICiF bits in the TIM1_CCMRi registers. For
example, if the input signal is unstable for up to five tMASTER cycles when it toggles, the
filter duration must be performed for longer than five clock cycles. The filter bits allow a
duration of eight cycles to be selected by writing them to 0011 in the TIMx_CCMR1
register. With this filter setting, a transition on TI1 is valid only when eight consecutive
samples with the new level have been detected (sampled at fMASTER frequency).
3. Select the edge of the active transition on the TI1 channel by writing the CC1P bit to 0
in the TIM1_CCER1 register (rising edge in this case).
4. Program the input prescaler. In this example, the capture needs to be performed at
each valid transition, so the prescaler is disabled (write the IC1PS( ) bits to 00 in the
TIM1_CCMR1 register).
5. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIM1_CCER1 register.
6. If needed, enable the related interrupt request by setting the CC1IE bit in the TIM1_IER
register.

RA (2018-01-29 20:49:00)

10

, 32 ...

11

??? ... ??? ???

HHIMERA (2018-01-31 11:52:01)

12

... UG ... ... ...

13

HHIMERA ():

??? ... ??? ???

HHIMERA ( 08:52:01)

. 2 . . "".

RA (2018-01-31 12:18:05)

14

HHIMERA ():

... UG ... ... ...

? - -.

15

HHIMERA ():

???

- . :)

RA (2018-01-31 12:21:13)

16

... ...
... 1 2 2 ... ... ...
__BCPL... ... ...

17

  UG ... ... ...
... UG... ... ... ...

HHIMERA (2018-01-31 12:38:20)

18

RA stm- . , .

19

??? 8... 32... ...
... ... ... ... ??? ??? ???

20

HHIMERA ():

... ...

. ... ... , TRIGER , , . . .
PWM .

RA (2018-01-31 15:39:41)

21

stm32, stm8 (). , DHT22. ( , ))), ).

22

MasterElectric ():

? HHIMERA - 1wire 16 -.

RA, uart DMA. .

23

dosikus ():

? HHIMERA - 1wire 16 -.

, .

24

25

:

:
#include "iostm8s103f3.h"
volatile unsigned int time;
/*..............................................................................*/
int main( void )
{
  CLK_SWCR_bit.SWEN = 0;//              
  CLK_CKDIVR_HSIDIV = 0;//     = 1.
  CLK_CKDIVR_CPUDIV = 0;//    = 1.  
  PA_ODR_bit.ODR3 = 1;
  PA_DDR_bit.DDR3 = 1; //  
  PA_CR1_bit.C13 = 1; //     +  - (PUSHPULL)
  PA_CR2_bit.C23 = 1; // 10
/*   1.    3,4 /   2. */ 
/*      50 .     50.04 . */ 
  TIM1_ARRH = 3;
  TIM1_ARRL = 106;
/*  .        . */ 
  TIM1_PSCRH = 3;
  TIM1_PSCRL = 140; 
// 2  /   
  TIM1_CCMR2_OC2M = 3; //  011: Toggle - OC1REF toggles when TIM1_CNT = TIM1_CCR1
  TIM1_CCR2H = 0;//
  TIM1_CCR2L = 1;//   :) 61,75 
  TIM1_IER_CC2IE = 1;//     
// 3  /   .  .
  TIM1_CCMR3_CC3S = 1;//     ,    TI3
  TIM1_CCER2_CC3P = 0;//   
  TIM1_CCER2_CC3E = 1;//     
// 4 
  TIM1_CCMR4_CC4S = 1;//     ,    TI4
  TIM1_CCER2_CC4P = 1;//   
  TIM1_CCER2_CC4E = 1;//  .
  TIM1_IER_CC4IE = 1;//    
//  
  TIM1_EGR_bit.UG = 1;  // Update Event
  asm("nop");
  asm("nop");
  TIM1_SR1 = 0;
  TIM1_IER_bit.UIE = 1; // 
//   
  TIM1_CR1_bit.CEN = 1; 
  asm("RIM"); // 
  for(;;)
  {
  }
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_OVR_UIF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_OVR_UIF_handler(void)
{
  if( ( TIM1_IER_bit.UIE == 1 ) && ( TIM1_SR1_UIF == 1 ) )
  {
    asm(" bcpl PA_ODR, #3 ");//PA_ODR_bit.ODR3 = ~PA_ODR_bit.ODR3;
    TIM1_SR1_bit.UIF = 0;
  } 
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_CAPCOM_CC4IF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC4IF_handler(void)
{
  if (( TIM1_SR1_bit.CC4IF == 1 ) && (TIM1_IER_bit.CC4IE == 1))
  {
//        
    time = ( TIM1_CCR4H - TIM1_CCR3H ) << 8;
    time = time + ( TIM1_CCR4L - TIM1_CCR3L ); 
  }
  if (( TIM1_SR1_bit.CC2IF == 1 ) && (TIM1_IER_bit.CC2IE == 1))
  {
    //   
    asm(" bcpl PA_ODR, #3 ");//PA_ODR_bit.ODR3 = ~PA_ODR_bit.ODR3;
    TIM1_SR1_bit.CC2IF = 0;
  }
}


http://s5.uploads.ru/t/lmZsq.png         http://sg.uploads.ru/t/gnp3B.png
.

RA (2018-01-31 18:37:47)

26

HHIMERA . )

RA . . . , ? . .

27

:crazy: :offtop:    , 1, . . , . .:crazy:
- . . 2, 1, ( ????). . .
100% . 90% . ? , , .  :tomato:

:
#include "iostm8s103f3.h"
/*..............................................................................*/
/*.......................  ...................................*/
/*..............................................................................*/
#define led_blue PC_ODR_bit.ODR5
#define led_green PC_ODR_bit.ODR6 
#define led_red PC_ODR_bit.ODR7 
#define button1_in PB_IDR_bit.IDR4
#define button2_in PB_IDR_bit.IDR5
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
volatile unsigned int time;
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
unsigned int pad_chg_time( unsigned char number )
{
  unsigned int tick = 0;
  if( number == 1 )
  {
    PB_ODR_bit.ODR4 = 1; //     +
    PB_DDR_bit.DDR4 = 1; //  
    PB_ODR_bit.ODR4 = 0; //     
    PB_DDR_bit.DDR4 = 0; //   
    while( button1_in == 0 ){tick++;}//   
  }
  if( number == 2 )
  {
    PB_ODR_bit.ODR5 = 1; //     +
    PB_DDR_bit.DDR5 = 1; //  
    PB_ODR_bit.ODR5 = 0; //     
    PB_DDR_bit.DDR5 = 0; //   
    while( button2_in == 0 ){tick++;}//   
  }    
  return tick;
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
unsigned char button_time( unsigned char number )
{
  unsigned int zero;
  if( number == 1 )
  {
    zero = pad_chg_time( number );
    while( pad_chg_time( number ) > 19 ){};
    if( zero > 19 )
      return 1;
    else
      return 0;
  }
  else if( number == 2 )
  {
    zero = pad_chg_time( number );
    while( pad_chg_time( number ) > 9 ){};
    if( zero > 9 )
      return 1;
    else
      return 0;
  }
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
int main( void )
{
  CLK_SWCR_bit.SWEN = 0;//              
  CLK_CKDIVR_HSIDIV = 0;//     = 1.
  CLK_CKDIVR_CPUDIV = 0;//    = 1.
/*  .3   */ 
  PC_DDR_bit.DDR5 = 1; //  
  PC_CR1_bit.C15 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C25 = 1; // 10
/*  .4   */ 
  PC_DDR_bit.DDR6 = 1; //  
  PC_CR1_bit.C16 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C26 = 1; // 10
/*  .5   */ 
  PC_DDR_bit.DDR7 = 1; //  
  PC_CR1_bit.C17 = 1; //     +  - (PUSHPULL)
  PC_CR2_bit.C27 = 1; // 10
/*  B.4  1 */
  PB_CR1_bit.C14 = 0; // 
  PB_CR2_bit.C24 = 0; // 
  PB_DDR_bit.DDR4 = 0; //  
  PB_ODR_bit.ODR4 = 0; // 
/*  B.5  2 */
  PB_CR1_bit.C15 = 0; // 
  PB_CR2_bit.C25 = 0; // 
  PB_DDR_bit.DDR5 = 0; //  
  PB_ODR_bit.ODR5 = 0; // 
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/  
  PA_ODR_bit.ODR3 = 1;
  PA_DDR_bit.DDR3 = 1; //  
  PA_CR1_bit.C13 = 1; //     +  - (PUSHPULL)
  PA_CR2_bit.C23 = 1; // 10
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
/*   1.    3,4 /   2. */ 
/*      50 .     50.04 . */ 
  TIM1_ARRH = 3;
  TIM1_ARRL = 106;
/*  .        . */ 
  TIM1_PSCRH = 3;
  TIM1_PSCRL = 140; 
// 2  /   
  TIM1_CCMR2_OC2M = 3; //  011: Toggle - OC1REF toggles when TIM1_CNT = TIM1_CCR1
  TIM1_CCR2H = 0;//
  TIM1_CCR2L = 1;//   :) 61,75 
  TIM1_IER_CC2IE = 1;//     
// 3  /   .  .
  TIM1_CCMR3_CC3S = 1;//     ,    TI3
  TIM1_CCER2_CC3P = 0;//   
  TIM1_CCER2_CC3E = 1;//     
// 4 
  TIM1_CCMR4_CC4S = 1;//     ,    TI4
  TIM1_CCER2_CC4P = 1;//   
  TIM1_CCER2_CC4E = 1;//  .
  TIM1_IER_CC4IE = 1;//    
//  
  TIM1_EGR_bit.UG = 1;  // Update Event
  asm("nop");
  asm("nop");
  TIM1_SR1 = 0;
  TIM1_IER_bit.UIE = 1; // 
//   
  TIM1_CR1_bit.CEN = 1; 
  asm("RIM"); // 
  for(;;)
  {
    if( button_time( 1 ) == 1 )led_red = ~led_red;
    if( button_time( 2 ) == 1 )led_green = ~led_green;
  }
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_OVR_UIF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_OVR_UIF_handler(void)
{
  if( ( TIM1_IER_bit.UIE == 1 ) && ( TIM1_SR1_UIF == 1 ) )
  {
    asm(" bcpl PA_ODR, #3 ");//PA_ODR_bit.ODR3 = ~PA_ODR_bit.ODR3;
    TIM1_SR1_bit.UIF = 0;
  } 
}
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
#pragma vector = TIM1_CAPCOM_CC4IF_vector
/*..............................................................................*/
/*..............................................................................*/
/*..............................................................................*/
__interrupt void TIM1_CAPCOM_CC4IF_handler(void)
{
  if (( TIM1_SR1_bit.CC4IF == 1 ) && (TIM1_IER_bit.CC4IE == 1))
  {
//        
    time = ( TIM1_CCR4H - TIM1_CCR3H ) << 8;
    time = time + ( TIM1_CCR4L - TIM1_CCR3L ); 
  }
  if (( TIM1_SR1_bit.CC2IF == 1 ) && (TIM1_IER_bit.CC2IE == 1))
  {
    //   
    asm(" bcpl PA_ODR, #3 ");//PA_ODR_bit.ODR3 = ~PA_ODR_bit.ODR3;
    TIM1_SR1_bit.CC2IF = 0;
  }
}

RA (2018-01-31 21:57:50)

28

RA ():

:offtop:
:tomato:

:O
, , )

29

RA ():

, 1, .

. . .

30

... ... ... ...
...

while( button2_in == 0 ){tick++;}//

... ...


»  » STM32 & STM8 »  1