⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 STM8全部资料
💻 C
字号:

/********************************************************************************************************
*
* File                : tc.c
* Hardware Environment: 
* Build Environment   : ST Visual Develop 4.1.6
* Version             : V1.0
* By                  : Xiao xian hui
*
*                                  (c) Copyright 2005-2010, WaveShare
*                                       http://www.waveShare.net
*                                          All Rights Reserved
*
*********************************************************************************************************/

#include "STM8_TSL_RC_API.h"
#include <stm8s105c4.h>
#include <system2.h>
#include <ws_lcd_st7920.h>

/*
#define LED1_PIN_MASK  ((u8)0x08)
#define LED1_PORT_ODR  GPIOD->ODR
#define LED1_PORT_DDR  GPIOD->DDR
#define LED1_PORT_CR1  GPIOD->CR1

#define LED2_PIN_MASK  ((u8)0x04)
#define LED2_PORT_ODR  GPIOD->ODR
#define LED2_PORT_DDR  GPIOD->DDR
#define LED2_PORT_CR1  GPIOD->CR1

#define LED3_PIN_MASK  ((u8)0x01)
#define LED3_PORT_ODR  GPIOD->ODR
#define LED3_PORT_DDR  GPIOD->DDR
#define LED3_PORT_CR1  GPIOD->CR1*/

#define LED1_ON()  Led1State = ON;
#define LED1_OFF() Led1State = OFF;

#define LED2_ON()  Led2State = ON;
#define LED2_OFF() Led2State = OFF;

#define LED3_ON()  Led3State = ON;
#define LED3_OFF() Led3State = OFF;

typedef enum
{
  OFF = 0,
  ON = 1
} LedState_T;

LedState_T Led1State,Led2State,Led3State;


_Bool in_range;
_Bool p_valid;
char *ptr;

//--------    SECTION DEFINITION FOR THIS FILE   --------------
#if defined(__CSMC__) && defined(USE_PRAGMA_SECTION)
#pragma section [CONFIG_RAM]
#pragma section @tiny [CONFIG_RAM0]
#pragma section (CONFIG_CODE)
#pragma section const {CONFIG_CONST}
#endif

void ExtraCode_Init(void);
void ExtraCode_StateMachine(void);


void main(void)
{


  unsigned char value = 100;
	
  in_range = (value >= 10) && (value <= 20);
  p_valid = ptr;   /* p_valid is true if ptr not 0 */


	CLK->CKDIVR = 0x00; // Main freq divided by 1 = Full Freq
	
	TSL_Init();
	ExtraCode_Init();
	delay_ms(900);
	st7920LcdInit();
	showLine(0,0,lcd_buffer,"Capacitive Touch");
	showLine(0,1,lcd_buffer,"Key1: No~!!");
	showLine(0,2,lcd_buffer,"Key2: No~!!");
	showLine(0,3,lcd_buffer,"Key3: No~!!");
	refreshLCD(lcd_buffer);
  for (;;) {
    
		ExtraCode_StateMachine();
		
    TSL_Action();
   
	}
  
}

void ExtraCode_Init(void)
{

  u8 i;

  /* All keys are implemented and enabled */

  for (i = 0; i < NUMBER_OF_SINGLE_CHANNEL_KEYS; i++)
  {
    sSCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sSCKeyInfo[i].Setting.b.ENABLED = 1;
    sSCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }

#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
  for (i = 0; i < NUMBER_OF_MULTI_CHANNEL_KEYS; i++)
  {
    sMCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[i].Setting.b.ENABLED = 1;
    sMCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }
#endif

  /* Init I/O in Output Push-Pull to drive the LED */
	/*LED1_PORT_ODR |= LED1_PIN_MASK; /* LED1 is ON by default */
 /* LED1_PORT_DDR |= LED1_PIN_MASK;
  LED1_PORT_CR1 |= LED1_PIN_MASK;
  Led1State = ON;
  /*
  LED2_PORT_ODR |= LED2_PIN_MASK; /* LED1 is ON by default */
 /* LED2_PORT_DDR |= LED2_PIN_MASK;
  LED2_PORT_CR1 |= LED2_PIN_MASK;
  Led2State = ON;
  */
 /* *LED3_PORT_ODR |= LED3_PIN_MASK; /* LED1 is ON by default */
 /* LED3_PORT_DDR |= LED3_PIN_MASK;
  LED3_PORT_CR1 |= LED3_PIN_MASK;
  Led3State = ON;
  */
  enableInterrupts();

}


void ExtraCode_StateMachine(void)	{

	if ((TSL_GlobalSetting.b.CHANGED) && (TSLState == TSL_IDLE_STATE))
  {
   
		TSL_GlobalSetting.b.CHANGED = 0;
    
    if (sSCKeyInfo[0].Setting.b.DETECTED) /* KEY 1 touched */
    {
      if (Led1State == OFF)
      {
        LED1_ON();
				showLine(6,1,lcd_buffer,"Yes~!");
				refreshLCD(lcd_buffer);
      }
      else
      {
        LED1_OFF();
				showLine(6,1,lcd_buffer,"No~!");
				refreshLCD(lcd_buffer);
      }
    }
   
    if (sSCKeyInfo[1].Setting.b.DETECTED) /* KEY 2 touched */
    {
      if (Led2State == OFF)
      {
        LED2_ON();
				showLine(6,2,lcd_buffer,"Yes~!");
				refreshLCD(lcd_buffer);
      }
      else
      {
        LED2_OFF();
				showLine(6,2,lcd_buffer,"No~!");
				refreshLCD(lcd_buffer);
      }
    }
    
    if (sSCKeyInfo[2].Setting.b.DETECTED) /* KEY 3 touched */
    {
      if (Led3State == OFF)
      {
        LED3_ON();
				showLine(6,3,lcd_buffer,"Yes~!");
				refreshLCD(lcd_buffer);
      }
      else
      {
        LED3_OFF();
				showLine(6,3,lcd_buffer,"No~!");
				refreshLCD(lcd_buffer);
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -