Mạch hẹn giờ tắt mở thiết bị điện dùng vi điều khiển STM8S103 , sử dụng biến trở để chỉnh thời gian hẹn từ 0 đến 60 phút , hiển thị lên màn hình LED
Mạch sử dụng điện áp 220V , và đóng cắt được tải 220V - 10A bằng relay
Video test mạch với máy bơm nước :
Sơ đồ mạch :
Sơ đồ |
Mach IN |
Code :
Code được viết bằng STVD với trình biên dịch Cosmic 16
Hàm main.h :
/**
******************************************************************************
* @file main.h
* @author 220von
* @version V1.0.0
* @date
* @brief This file is header for module main.c
******************************************************************************
* @attention
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H__
#define __MAIN_H__
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define NUT_PORT (GPIOD)
#define NUT_PIN (GPIO_PIN_4)
#define ADC_PORT (GPIOD)
#define ADC_PIN (GPIO_PIN_5)
#define A_PORT (GPIOC)
#define A_PIN (GPIO_PIN_4)
#define B_PORT (GPIOC)
#define B_PIN (GPIO_PIN_3)
#define C_PORT (GPIOD)
#define C_PIN (GPIO_PIN_1)
#define D_PORT (GPIOC)
#define D_PIN (GPIO_PIN_7)
#define E_PORT (GPIOD)
#define E_PIN (GPIO_PIN_3)
#define F_PORT (GPIOC)
#define F_PIN (GPIO_PIN_5)
#define G_PORT (GPIOC)
#define G_PIN (GPIO_PIN_6)
#define DOT_PORT (GPIOD)
#define DOT_PIN (GPIO_PIN_2)
#define LED1_PORT (GPIOB)
#define LED1_PIN (GPIO_PIN_4)
#define LED2_PORT (GPIOB)
#define LED2_PIN (GPIO_PIN_5)
#define R_PORT (GPIOA)
#define R_PIN (GPIO_PIN_3)
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
#endif /* __MAIN_H__ */
/******************* (C) COPYRIGHT 220von *****END OF FILE****/
Hàm main.c:
/**
******************************************************************************
* @file main.c
* @author 220von
* @version V1.0.0
* @date
* @brief This file contains the main function for GPIO Toggle example.
******************************************************************************
* @attention
*/
/* Includes ------------------------------------------------------------------*/
/*#include "stm8s_conf.h"*/
#include "main.h"
#include "stm8s_gpio.h"
#include "stm8s_adc1.h"
#include "stm8s_clk.h"
#include "stm8s_tim4.h"
#include "stm8s_tim1.h"
#include "stm8s.h"
#include "stm8s_it.h"
#include "stm8s_flash.h"
BitStatus dot_set=0,menu=0;
u8 min=0,sec=0;
u16 i=0;
u16 adc_val=1000;
const u8 so[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
///////////////////////////////////////////////////////////////////////////
void send_led7seg(u8 giatri, BitStatus dot)
{
if(giatri&0x01)GPIO_WriteLow(A_PORT, (GPIO_Pin_TypeDef)A_PIN);
else GPIO_WriteHigh(A_PORT, (GPIO_Pin_TypeDef)A_PIN);
if(giatri&0x02)GPIO_WriteLow(B_PORT, (GPIO_Pin_TypeDef)B_PIN);
else GPIO_WriteHigh(B_PORT, (GPIO_Pin_TypeDef)B_PIN);
if(giatri&0x04)GPIO_WriteLow(C_PORT, (GPIO_Pin_TypeDef)C_PIN);
else GPIO_WriteHigh(C_PORT, (GPIO_Pin_TypeDef)C_PIN);
if(giatri&0x08)GPIO_WriteLow(D_PORT, (GPIO_Pin_TypeDef)D_PIN);
else GPIO_WriteHigh(D_PORT, (GPIO_Pin_TypeDef)D_PIN);
if(giatri&0x10)GPIO_WriteLow(E_PORT, (GPIO_Pin_TypeDef)E_PIN);
else GPIO_WriteHigh(E_PORT, (GPIO_Pin_TypeDef)E_PIN);
if(giatri&0x20)GPIO_WriteLow(F_PORT, (GPIO_Pin_TypeDef)F_PIN);
else GPIO_WriteHigh(F_PORT, (GPIO_Pin_TypeDef)F_PIN);
if(giatri&0x40)GPIO_WriteLow(G_PORT, (GPIO_Pin_TypeDef)G_PIN);
else GPIO_WriteHigh(G_PORT, (GPIO_Pin_TypeDef)G_PIN);
if(dot==1)GPIO_WriteLow(DOT_PORT, (GPIO_Pin_TypeDef)DOT_PIN);
else GPIO_WriteHigh(DOT_PORT, (GPIO_Pin_TypeDef)DOT_PIN);
}
///////////////////////////////////////////////////////////////////////////
u8 quetled=0;
void putc_to_3_led7seg(u8 value1,u8 value2,BitStatus dot)
{
switch(quetled)
{
case 1:
{
GPIO_WriteHigh(LED2_PORT, (GPIO_Pin_TypeDef)LED2_PIN);
send_led7seg(value1,0);
GPIO_WriteLow(LED1_PORT, (GPIO_Pin_TypeDef)LED1_PIN);
break;
}
case 2:
{
GPIO_WriteHigh(LED1_PORT, (GPIO_Pin_TypeDef)LED1_PIN);
send_led7seg(value2,dot);
GPIO_WriteLow(LED2_PORT, (GPIO_Pin_TypeDef)LED2_PIN);
break;
}
}
}
///////////////////////////////////////////////////////////////////////////
void hienthi_led7seg(u8 value1,BitStatus dot)
{
u8 chuc;
u8 le;
chuc = value1/10;
le = value1%10;
if(value1<10)putc_to_3_led7seg(0x00,so[value1],dot);
else putc_to_3_led7seg(so[chuc],so[le],dot);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void main(void)
{
CLK_DeInit();
CLK_HSICmd( ENABLE);
/* Configure the Fcpu to DIV1*/
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
/* Configure the HSI prescaler to the optimal value */
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
/* Output Fcpu on CLK_CCO pin */
/*CLK_CCOConfig(CLK_OUTPUT_CPU);*/
/* Configure the system clock to use HSI clock source and to run at 16Mhz */
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
/* Define flash programming Time*/
FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);
/* Unlock Data memory */
FLASH_Unlock(FLASH_MEMTYPE_DATA);
TIM1_DeInit();
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 65535,0);
TIM1_Cmd(ENABLE);
ADC1_DeInit();
ADC1_Cmd(ENABLE);
ADC1_ConversionConfig(ADC1_CONVERSIONMODE_CONTINUOUS,ADC1_CHANNEL_5 ,ADC1_ALIGN_RIGHT);
ADC1_PrescalerConfig(ADC1_PRESSEL_FCPU_D2);
ADC1_StartConversion();
/* Time base configuration */
TIM4_TimeBaseInit(TIM4_PRESCALER_128, 124); // ngắt timer4 mỗi 1ms
/* Clear TIM4 update flag */
TIM4_ClearFlag(TIM4_FLAG_UPDATE);
/* Enable update interrupt */
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
/* Enable TIM4 */
TIM4_Cmd(ENABLE);
/* Initialize I/Os in Output Mode */
GPIO_Init(ADC_PORT, (GPIO_Pin_TypeDef)ADC_PIN, GPIO_MODE_IN_FL_NO_IT );
GPIO_Init(LED1_PORT, (GPIO_Pin_TypeDef)LED1_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LED2_PORT, (GPIO_Pin_TypeDef)LED2_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_WriteHigh (LED1_PORT, (GPIO_Pin_TypeDef)LED1_PIN);
GPIO_WriteHigh (LED2_PORT, (GPIO_Pin_TypeDef)LED2_PIN);
GPIO_Init(A_PORT, (GPIO_Pin_TypeDef)A_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(B_PORT, (GPIO_Pin_TypeDef)B_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(C_PORT, (GPIO_Pin_TypeDef)C_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(D_PORT, (GPIO_Pin_TypeDef)D_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(E_PORT, (GPIO_Pin_TypeDef)E_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(F_PORT, (GPIO_Pin_TypeDef)F_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(G_PORT, (GPIO_Pin_TypeDef)G_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(DOT_PORT, (GPIO_Pin_TypeDef)DOT_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(R_PORT, (GPIO_Pin_TypeDef)R_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_WriteLow(R_PORT, (GPIO_Pin_TypeDef)R_PIN);
GPIO_Init(NUT_PORT, (GPIO_Pin_TypeDef)NUT_PIN, GPIO_MODE_IN_FL_NO_IT );
enableInterrupts();
while (1)
{
////////////////////////////////////////////////////////////////////////
switch(menu)
{
case 0:
{
for(i=0;i<50;i++)
{
adc_val += ADC1_GetConversionValue ();
delay(10);
}
adc_val=adc_val/50;
min=adc_val/33;
if(min>=30)min=30; // chỉnh max thời gian hẹn là 30 phút
sec=0;
GPIO_WriteLow(R_PORT, (GPIO_Pin_TypeDef)R_PIN);
hienthi_led7seg(min,0);
break;
}
case 1:
{
if(min==0)GPIO_WriteLow(R_PORT, (GPIO_Pin_TypeDef)R_PIN);
else GPIO_WriteHigh(R_PORT, (GPIO_Pin_TypeDef)R_PIN);
hienthi_led7seg(min,dot_set);
break;
}
}
////////////////////////////////////////////////////////////////////////////
}
}
/**
* @brief Delay
* @param nCount
* @retval None
*/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where 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(uint8_t* file, uint32_t 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
/**
* @}
*/
/******************* (C) COPYRIGHT 220von *****END OF FILE****/
Và cuối cùng là hàm ngắt phục vụ cho phần đếm thời gian :
/**
******************************************************************************
* @file stm8s_it.c
* @author MCD Application Team
* @version V2.0.1
* @date 18-November-2011
* @brief Main Interrupt Service Routines.
******************************************************************************
* @attention
*
* 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 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8s_it.h"
#include "stm8s_tim1.h"
#include "main.h"
#include "stm8s_tim4.h"
#include "stm8s_gpio.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
/** @addtogroup GPIO_Toggle
* @{
*/
#ifdef _COSMIC_
/**
* @brief Dummy interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(NonHandledInterrupt, 25)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*_COSMIC_*/
/**
* @brief TRAP interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Top Level Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TLI_IRQHandler, 0)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Auto Wake Up Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(AWU_IRQHandler, 1)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Clock Controller Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(CLK_IRQHandler, 2)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief External Interrupt PORTA Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief External Interrupt PORTB Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief External Interrupt PORTC Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief External Interrupt PORTD Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief External Interrupt PORTE Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#ifdef STM8S903
/**
* @brief External Interrupt PORTF Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S903*/
#if defined (STM8S208) || defined (STM8AF52Ax)
/**
* @brief CAN RX Interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief CAN TX Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S208 || STM8AF52Ax */
/**
* @brief SPI Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(SPI_IRQHandler, 10)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Timer1 Update/Overflow/Trigger/Break Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Timer1 Capture/Compare Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#ifdef STM8S903
/**
* @brief Timer5 Update/Overflow/Break/Trigger Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Timer5 Capture/Compare Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
/**
* @brief Timer2 Update/Overflow/Break Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Timer2 Capture/Compare Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S903*/
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
/**
* @brief Timer3 Update/Overflow/Break Interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief Timer3 Capture/Compare Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
/**
* @brief UART1 TX Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief UART1 RX Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S105*/
/**
* @brief I2C Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(I2C_IRQHandler, 19)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
/**
* @brief UART2 TX interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief UART2 RX interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /* STM8S105*/
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
/**
* @brief UART3 TX interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @brief UART3 RX interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
/**
* @brief ADC2 interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(ADC2_IRQHandler, 22)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
return;
}
#else /*STM8S105, STM8S103 or STM8S903 or STM8AF626x */
/**
* @brief ADC1 interrupt routine.
* @param None
* @retval None
*/
INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
return;
}
#endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */
#ifdef STM8S903
/**
* @brief Timer6 Update/Overflow/Trigger Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
/**
* @brief Timer4 Update/Overflow Interrupt routine
* @param None
* @retval None
*/
extern u8 quetled;
extern BitStatus dot_set,menu;
BitStatus nut_set =0;
u16 msec=0;
u8 count=0;
extern u8 sec;
extern u8 min;
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23) // ngắt timer
{
/* Cleat Interrupt Pending bit */
msec++;
if(msec>=1000){sec++;msec=0;dot_set ^= 1;}
if(sec>=60){min--;sec=0;}
if(min==0){menu=0;sec=0;}
quetled++;
if(quetled>2)quetled=0;
if((!(GPIO_ReadInputPin(NUT_PORT,(GPIO_Pin_TypeDef)NUT_PIN)))&&(nut_set==1))count++;
if(GPIO_ReadInputPin(NUT_PORT,(GPIO_Pin_TypeDef)NUT_PIN)) {count=0;nut_set=1;}
if(count>=100){menu ^=1;nut_set=0;count=0;}
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
#endif /*STM8S903*/
/**
* @brief Eeprom EEC Interrupt routine
* @param None
* @retval None
*/
INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
}
/**
* @}
*/
/******************* (C) COPYRIGHT 220von *****END OF FILE****/
Toàn bộ chi phí linh kiện chế tạo mạch này rơi vào khoản 60k
Nếu
các bạn muốn hợp tác với mình để mở rộng chức năng cho ứng dụng này
hoặc chia sẻ ý tưởng ứng dụng vào cuộc sống thì gửi mail cho mình theo
địa chỉ : 220von.com@gmail.com
Hoặc theo dõi trang fan page facebook : https://www.facebook.com/220von/