📄 main.c
字号:
/**
******************************************************************************
* @file project\main.c
* @brief This file contains the firmware main function.
* @author STMicroelectronics - MCD Application Team
* @version V1.1.0
* @date 02/27/2009
******************************************************************************
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2>
* @image html logo.bmp
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "stm8s207r.h"
#include "lcd_19264.h"
#include "key.h"
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* -------------------------------------------------------------------------- */
/* ROUTINE NAME: CLK_Init */
/* INPUT/OUTPUT: None. */
/* DESCRIPTION: Initialize the clock source */
/* 1) Configure fmaster prescaler. */
/* 2) Switch HSI to HSE. */
/* 3) Enable CSS. */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* ROUTINE NAME: CLK_Init */
/* INPUT/OUTPUT: None. */
/* DESCRIPTION: Initialize the clock source */
/* -------------------------------------------------------------------------- */
void CLK_Init(void)
{
/* Configure HSI prescaler*/
CLK_CKDIVR &= ~0x10; /* 01: fHSI= fHSI RC output/2. */
/* Configure CPU clock prescaler */
// CLK_CKDIVR |= 0x01; /* 001: fCPU=fMASTER/2. */
CLK_CKDIVR = 0;
}
void LCD_Clear(void);
volatile u8 flag_2ms_ok, flag_10ms_ok;
void main(void)
{
u8 j = 0, i;
u8 keycode;
int timer5s_counter = 0;
CLK_Init();
TIM4_DeInit();
/* Time base configuration */
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 250);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
GPIO_Init( GPIOD, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);
LCD_Init();
enableInterrupts();
TIM4_Cmd(ENABLE);
LCD_Clear();
for(i = 0; i < 64; i+=16)
LCD_BufferDrawXDotLine(0, i, 128, LCD_SET);
for(i = 0; i <129; i+=16)
LCD_BufferDrawYDotLine(i, 0, 63, LCD_SET);
//LCD_BufferDrawLine(0, 0, 128, 63, LCD_SET); // 0 < k < 1
//LCD_BufferDrawLine(128, 0, 0, 50, LCD_SET); // -1 < k < 0
//LCD_BufferDrawLine(0, 0, 27, 63, LCD_SET); // k > 1
//LCD_BufferDrawLine(31, 0, 0, 63, LCD_SET); // k < -1
//LCD_BufferDrawLine(120, 40, 20, 0, LCD_SET);
LCD_BufferDrawLine(0, 0, 31, 63, LCD_SET);
LCD_BufferDrawLine(31, 63, 63, 0, LCD_SET);
LCD_BufferDrawLine(63, 0, 94, 63, LCD_SET);
LCD_BufferDrawLine(94, 63, 125, 0, LCD_SET);
LCD_PutString5x8(22, 0, "STM8 DSO");
LCD_PutString5x8(22, 1, "By ifree");
LCD_PutString5x8(22, 2, "1000Hz");
LCD_PutString5x8(22, 3, "5Vpp");
LCD_BufferToLCD();
/* Infinite loop */
while (1)
{
if(flag_10ms_ok)
{
flag_10ms_ok = 0;
keycode = KEY_Scan();
if(GET_KCODE(keycode))
{
switch(GET_KTYPE(keycode))
{
case KTYPE_NORMAL:
LCD_PutString5x8(22, 4, "NORMAL");
break;
case KTYPE_LONG:
LCD_PutString5x8(22, 4, "LONG ");
break;
case KTYPE_LIANFA:
LCD_PutString5x8(22, 4, "LIANFA");
break;
}
}
if(++timer5s_counter >= 500)
{
timer5s_counter = 0;
LCD_PutString5x8(22, 4, " ");
}
}
LCD_BufferToLCD();
}
}
/**
* @brief Reports the name of the source file and the source line number where
* the assert error has occurred.
* 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)
* @retval void None
* @par Required preconditions:
* None
* @par Called functions:
* None
*/
#ifdef FULL_ASSERT
void assert_failed(u8 *file, u16 line)
#else
void assert_failed(void)
#endif
{
/* Add your own code to manage an assert error */
/* Infinite loop */
while (1)
{
}
}
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -