STM8简单示波器程序IAR

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

/**
******************************************************************************

* 线接法:

* USB-TTL串口线的5V正负极接STM8的电源端口

* 如果STM8是开发板,而且带有电源,只需要接串口线的负极

* 串口线的TX接STM8S103的TIM1_CH1 即18脚

* 串口线的RX接STM8S103的UART1_TX 即30脚

* 因为芯片不同,脚位可能会有所不同,请具体查看芯片手册

* 主要计算程序在中断里,stm8s_it.c 第238行

******************************************************************************
*/


/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"

uint16_t i,AD_Value;

void Delay(uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


void Init_UART1(void)
{
UART1_DeInit();
UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
//UART1_Cmd(ENABLE);
}


void ADC_Init(void)
{
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_0, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_LEFT, ADC1_SCHMITTTRIG_CHANNEL0, DISABLE);
ADC1_ScanModeCmd(ENABLE);//启用扫描模式
ADC1_DataBufferCmd(ENABLE);//启用缓存寄存器存储数据
ADC1_ITConfig(ADC1_IT_EOCIE,DISABLE);//关闭中断功能
ADC1_Cmd(ENABLE);//启用ADC1
ADC1_StartConversion();//开始转换
}

void CLK_Init(void)
{

CLK->CMSR =0xB4; //使能外置高速晶体振荡器
CLK->CKDIVR =0x00; //设置外部时钟分频
CLK->ECKR = 0X01; //使能外部时钟寄存器
}

void main(void)
{
//uint16_t zq;
uint8_t n;

CLK_Init();
ADC_Init();
Init_UART1();
enableInterrupts();
while (1)
{
for(n=0;n<100;n++)
{
AD_Value=ADC1_GetBufferValue(0);
UART1_SendData8(0xA5 );
Delay(10000);
UART1_SendData8(AD_Value >> 8);
Delay(10000);
UART1_SendData8(0xAA);
Delay(10000);
}

}

}

INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/

}


INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{

}

INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/


}

#ifdef USE_FULL_ASSERT

/**
* @brief Reports the name of the source file and the source line number
* whe

re the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */
while (1)
{
}
}
#endif

相关文档
最新文档