STM8实验课例程

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言的主函数

*/

#include "stm8s207r.h"

void GPIO_Init(void)

{

/* LED IO Configuration */

/* LD3: PD3 */

/* LD2: PD1 */

/* LD1: PD0 */

PD_DDR |= 0x1D; /* Output. */

PD_CR1 |= 0x1D; /* PushPull. */

PD_CR2 = 0x00; /* Output speed up to 2MHz. */ }

-------- */

void TIM_Init(void)

{

TIM4_PSCR = 0x04;

TIM4_ARR = 0xFA;

TIM4_CR1 |= 0x01;

TIM4_IER |= 0x01;

}

main()

{

_asm("sim"); /* Disable interrupts. */

GPIO_Init();

TIM_Init();

_asm("rim"); /* Enable interrupts. */

while (1);

}

C语言下的中断

/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices

* Copyright (c) 2007 STMicroelectronics

*/

#include "stm8s207r.h"

unsigned int Count;

typedef void @far (*interrupt_handler_t)(void);

struct interrupt_vector {

unsigned char interrupt_instruction;

interrupt_handler_t interrupt_handler;

};

@far @interrupt void TIM4_UPD_OVF_IRQHandler (void)

{

Count++;

switch (Count)

{

case 4000: PD_ODR |=0x01;

break;

case 8000: PD_ODR |=0x04;

break;

case 12000: PD_ODR |=0x08;

break;

case 16000: PD_ODR &=~0x1D;

Count=0;

break;

}

/* Clear the update IT pending Bit */

TIM4_SR1 &=~(0x01);

return;

}

@far @interrupt void NonHandledInterrupt (void)

{

/* in order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction */

return;

}

extern void _stext(); /* startup routine */

struct interrupt_vector const _vectab[] = {

{0x82, (interrupt_handler_t)_stext}, /* reset */

{0x82, NonHandledInterrupt}, /* trap */

{0x82, TLI_Interrupt}, /* irq0 */

{0x82, NonHandledInterrupt}, /* irq1 */

{0x82, NonHandledInterrupt}, /* irq2 */

{0x82, NonHandledInterrupt}, /* irq3 */

{0x82, NonHandledInterrupt}, /* irq4 */

{0x82, NonHandledInterrupt}, /* irq5 */

{0x82, NonHandledInterrupt}, /* irq6 */

{0x82, NonHandledInterrupt}, /* irq7 */

{0x82, NonHandledInterrupt}, /* irq8 */

{0x82, NonHandledInterrupt}, /* irq9 */

{0x82, NonHandledInterrupt}, /* irq10 */

{0x82, NonHandledInterrupt}, /* irq11 */

{0x82, NonHandledInterrupt}, /* irq12 */

{0x82, TIM2_UPD_OVF_IRQHandler}, /* irq13 */ {0x82, NonHandledInterrupt}, /* irq14 */

{0x82, NonHandledInterrupt}, /* irq15 */

{0x82, NonHandledInterrupt}, /* irq16 */

{0x82, NonHandledInterrupt}, /* irq17 */

{0x82, NonHandledInterrupt}, /* irq18 */

{0x82, NonHandledInterrupt}, /* irq19 */

{0x82, NonHandledInterrupt}, /* irq20 */

{0x82, NonHandledInterrupt}, /* irq21 */

{0x82, NonHandledInterrupt}, /* irq22 */

{0x82, TIM4_UPD_OVF_IRQHandler}, /* irq23 */ {0x82, NonHandledInterrupt}, /* irq24 */

{0x82, NonHandledInterrupt}, /* irq25 */

{0x82, NonHandledInterrupt}, /* irq26 */

{0x82, NonHandledInterrupt}, /* irq27 */

{0x82, NonHandledInterrupt}, /* irq28 */

{0x82, NonHandledInterrupt}, /* irq29 */

};

相关文档
最新文档