资源简介
基于stm8s103 的电阻式触摸按键源代码,很好
代码片段和文件信息
#include
#include “TM1628.h“
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
#define loadbitmask 0x04
#define GPIOA_baseAddress 0x5000
#define GPIOB_baseAddress 0x5005
#define GPIOF_baseAddress 0x5019
#define PA3_stouchbit 0
#define PF4_stouchbit 1
#define PB7_stouchbit 2
#define PB6_stouchbit 3
typedef struct GPIO_struct
{
volatile uint8_t ODR; /*!< Output Data Register */
volatile uint8_t IDR; /*!< Input Data Register */
volatile uint8_t DDR; /*!< Data Direction Register */
volatile uint8_t CR1; /*!< Configuration Register 1 */
volatile uint8_t CR2; /*!< Configuration Register 2 */ /*!< defines ‘read / write‘ permissions */
}
GPIO_TypeDef;
GPIO_TypeDef *PORT_ADDR; /**< base adress of the GPIO (DR address) */
void Clk_Config(void)
{
CLK_CKDIVR_CPUDIV = 0; //系统时钟1分频
while(!(CLK_ICKR & 0x02)); //等待HSI准备好
}
void delay(u16 n)
{
u16 ij;
while(n --)
{
for(i = 0;i < 32;i ++)
for(j = 0;j < 10;j ++);
}
}
void Io_Config(void)
{
PA_DDR |= 0x0C;
PA_CR1 |= 0x0C;
PA_ODR |= 0x0C;
PB_DDR |= 0xC0;
PB_CR1 |= 0xC0;
PB_ODR |= 0xC0;
PF_DDR |= 0x10;
PF_CR1 |= 0x10;
PF_ODR |= 0x10;
PD_DDR |= 0x10;
PD_CR1 |= 0x10;
}
void Tim2_Config(void)
{
TIM2_PSCR = 0; //16分频得到8MHZ的定时器时钟定时器加1就是0.125us
TIM2_ARRH = 0xff; //20ms更新一次
TIM2_ARRL = 0xff;
// TIM2_IER_UIE = 1; //更新中断使能
TIM2_CR1_ARPE = 1; //预装载使能
TIM2_CR1_CEN=1;
}
int touch_acqusition(int touch_io)
{
u16 measure_time=0measure_count=0;
u8 stouchbitmask;
switch(touch_io)
{
case PA3_stouchbit:
PORT_ADDR = (GPIO_TypeDef *)(GPIOA_baseAddress);
stouchbitmask=0x08;
break;
case PF4_stouchbit:
PORT_ADDR = (GPIO_TypeDef *)(GPIOF_baseAddress);
stouchbitmask=0x10;
break;
case PB7_stouchbit:
PORT_ADDR = (GPIO_TypeDef *)(GPIOB_baseAddress);
stouchbitmask=0x80;
break;
case PB6_stouchbit:
PORT_ADDR = (GPIO_TypeDef *)(GPIOB_baseAddress);
stouchbitmask=0x40;
break;
}
do
{
PORT_ADDR->ODR &= ~stouchbitmask; //CAP_CHx pin is set in output mode at Vss
PORT_ADDR->DDR |= stouchbitmask;
PORT_ADDR->CR1 &= ~stouchbitmask;
PA_ODR |= loadbitmask; //Load pin is set in output mode at Vdd
TIM2_CNTRH=0X00;
TIM2_CNTRL=0X00; //保存定时器计数器的初始值(vih_start)
- 上一篇:数据结构 停车场问题
- 下一篇:opengl实现的光线跟踪
相关资源
- STM8S003 cc115l cc113l
- stm32f429电容触摸按键程序
- STM8S 0.96寸OLED4线SPI驱动程序
- cypress 的触摸按键程序
- 基于msp430g2553的触摸按键程序
- STM8S模拟串口,双串口,虚拟串口
- STM8S003单片机ADC多通道采样
- STM8S003模拟IIC总线读取PCF8563
- STM8S003模拟串口程序
- STM8S003F使用I/O口模拟串口一发送数据
- 触摸式感应按键的设计原理及指南
- 触摸按键PCB板layout注意事项
- 触摸按键PCB设计要点
- 触摸按键IC
- 基于AD采集的电容触摸按键
- 合泰触摸按键芯片BS83BX系列例程 汇
- STM8S单片机输出互补PWM可通过刹车输入
- PIC 触摸按键资料
- 使用 STM8S103F3 设计的数字电压表头
- STM8S 模拟I2C程序 源码
- stm8s003与ds1307时钟芯片程序
- 触摸按键设计指导
- stvd 4.1.2 汉化版ST Visual Develop Version
- stm8s解码pt2262
- 触摸按键-控制
- stm8s105 一个简单的高低电平控制3位
- 一个74hc595驱动3个数码管
- 合泰bs83b08c触摸按键源程序 C
- STM8S003使用手册
- STM32的电容触摸按键程序,亲测可用
评论
共有 条评论